// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import AdminSettings from './admin_settings.jsx';
import BooleanSetting from './boolean_setting.jsx';
import ConnectionSecurityDropdownSetting from './connection_security_dropdown_setting.jsx';
import SettingsGroup from './settings_group.jsx';
import TextSetting from './text_setting.jsx';
import SyncNowButton from './sync_now_button.jsx';
import LdapTestButton from './ldap_test_button.jsx';
import * as Utils from 'utils/utils.jsx';
import React from 'react';
import {FormattedMessage} from 'react-intl';
export default class LdapSettings extends AdminSettings {
constructor(props) {
super(props);
this.getConfigFromState = this.getConfigFromState.bind(this);
this.renderSettings = this.renderSettings.bind(this);
}
getConfigFromState(config) {
config.LdapSettings.Enable = this.state.enable;
config.LdapSettings.LdapServer = this.state.ldapServer;
config.LdapSettings.LdapPort = this.parseIntNonZero(this.state.ldapPort);
config.LdapSettings.ConnectionSecurity = this.state.connectionSecurity;
config.LdapSettings.BaseDN = this.state.baseDN;
config.LdapSettings.BindUsername = this.state.bindUsername;
config.LdapSettings.BindPassword = this.state.bindPassword;
config.LdapSettings.UserFilter = this.state.userFilter;
config.LdapSettings.FirstNameAttribute = this.state.firstNameAttribute;
config.LdapSettings.LastNameAttribute = this.state.lastNameAttribute;
config.LdapSettings.NicknameAttribute = this.state.nicknameAttribute;
config.LdapSettings.EmailAttribute = this.state.emailAttribute;
config.LdapSettings.UsernameAttribute = this.state.usernameAttribute;
config.LdapSettings.IdAttribute = this.state.idAttribute;
config.LdapSettings.SyncIntervalMinutes = this.parseIntNonZero(this.state.syncIntervalMinutes);
config.LdapSettings.SkipCertificateVerification = this.state.skipCertificateVerification;
config.LdapSettings.QueryTimeout = this.parseIntNonZero(this.state.queryTimeout);
config.LdapSettings.MaxPageSize = this.parseInt(this.state.maxPageSize);
config.LdapSettings.LoginFieldName = this.state.loginFieldName;
return config;
}
getStateFromConfig(config) {
return {
enable: config.LdapSettings.Enable,
ldapServer: config.LdapSettings.LdapServer,
ldapPort: config.LdapSettings.LdapPort,
connectionSecurity: config.LdapSettings.ConnectionSecurity,
baseDN: config.LdapSettings.BaseDN,
bindUsername: config.LdapSettings.BindUsername,
bindPassword: config.LdapSettings.BindPassword,
userFilter: config.LdapSettings.UserFilter,
firstNameAttribute: config.LdapSettings.FirstNameAttribute,
lastNameAttribute: config.LdapSettings.LastNameAttribute,
nicknameAttribute: config.LdapSettings.NicknameAttribute,
emailAttribute: config.LdapSettings.EmailAttribute,
usernameAttribute: config.LdapSettings.UsernameAttribute,
idAttribute: config.LdapSettings.IdAttribute,
syncIntervalMinutes: config.LdapSettings.SyncIntervalMinutes,
skipCertificateVerification: config.LdapSettings.SkipCertificateVerification,
queryTimeout: config.LdapSettings.QueryTimeout,
maxPageSize: config.LdapSettings.MaxPageSize,
loginFieldName: config.LdapSettings.LoginFieldName
};
}
renderTitle() {
return (
);
}
renderSettings() {
const licenseEnabled = global.window.mm_license.IsLicensed === 'true' && global.window.mm_license.LDAP === 'true';
if (!licenseEnabled) {
return null;
}
return (
}
helpText={
}
value={this.state.enable}
onChange={this.handleChange}
/>
}
placeholder={Utils.localizeMessage('admin.ldap.serverEx', 'Ex "10.0.0.23"')}
helpText={
}
value={this.state.ldapServer}
onChange={this.handleChange}
disabled={!this.state.enable}
/>
}
placeholder={Utils.localizeMessage('admin.ldap.portEx', 'Ex "389"')}
helpText={
}
value={this.state.ldapPort}
onChange={this.handleChange}
disabled={!this.state.enable}
/>
}
helpText={
}
value={this.state.skipCertificateVerification}
onChange={this.handleChange}
/>
}
placeholder={Utils.localizeMessage('admin.ldap.baseEx', 'Ex "ou=Unit Name,dc=corp,dc=example,dc=com"')}
helpText={
}
value={this.state.baseDN}
onChange={this.handleChange}
disabled={!this.state.enable}
/>
}
helpText={
}
value={this.state.bindUsername}
onChange={this.handleChange}
disabled={!this.state.enable}
/>
}
helpText={
}
value={this.state.bindPassword}
onChange={this.handleChange}
disabled={!this.state.enable}
/>
}
placeholder={Utils.localizeMessage('admin.ldap.userFilterEx', 'Ex. "(objectClass=user)"')}
helpText={
}
value={this.state.userFilter}
onChange={this.handleChange}
disabled={!this.state.enable}
/>
}
placeholder={Utils.localizeMessage('admin.ldap.firstnameAttrEx', 'Ex "givenName"')}
helpText={
}
value={this.state.firstNameAttribute}
onChange={this.handleChange}
disabled={!this.state.enable}
/>
}
placeholder={Utils.localizeMessage('admin.ldap.lastnameAttrEx', 'Ex "sn"')}
helpText={
}
value={this.state.lastNameAttribute}
onChange={this.handleChange}
disabled={!this.state.enable}
/>
}
placeholder={Utils.localizeMessage('admin.ldap.nicknameAttrEx', 'Ex "nickname"')}
helpText={
}
value={this.state.nicknameAttribute}
onChange={this.handleChange}
disabled={!this.state.enable}
/>
}
placeholder={Utils.localizeMessage('admin.ldap.emailAttrEx', 'Ex "mail" or "userPrincipalName"')}
helpText={
}
value={this.state.emailAttribute}
onChange={this.handleChange}
disabled={!this.state.enable}
/>
}
placeholder={Utils.localizeMessage('admin.ldap.usernameAttrEx', 'Ex "sAMAccountName"')}
helpText={
}
value={this.state.usernameAttribute}
onChange={this.handleChange}
disabled={!this.state.enable}
/>
}
placeholder={Utils.localizeMessage('admin.ldap.idAttrEx', 'Ex "sAMAccountName"')}
helpText={
}
value={this.state.idAttribute}
onChange={this.handleChange}
disabled={!this.state.enable}
/>
}
placeholder={Utils.localizeMessage('admin.ldap.loginNameEx', 'Ex "LDAP Username"')}
helpText={
}
value={this.state.loginFieldName}
onChange={this.handleChange}
disabled={!this.state.enable}
/>
}
helpText={
}
value={this.state.syncIntervalMinutes}
onChange={this.handleChange}
disabled={!this.state.enable}
/>
}
placeholder={Utils.localizeMessage('admin.ldap.maxPageSizeEx', 'Ex "2000"')}
helpText={
}
value={this.state.maxPageSize}
onChange={this.handleChange}
disabled={!this.state.enable}
/>
}
placeholder={Utils.localizeMessage('admin.ldap.queryEx', 'Ex "60"')}
helpText={
}
value={this.state.queryTimeout}
onChange={this.handleChange}
disabled={!this.state.enable}
/>
);
}
}