// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import * as Client from '../../utils/client.jsx'; import * as AsyncClient from '../../utils/async_client.jsx'; const DEFAULT_LDAP_PORT = 389; const DEFAULT_QUERY_TIMEOUT = 60; export default class LdapSettings extends React.Component { constructor(props) { super(props); this.handleSubmit = this.handleSubmit.bind(this); this.handleChange = this.handleChange.bind(this); this.handleEnable = this.handleEnable.bind(this); this.handleDisable = this.handleDisable.bind(this); this.state = { saveNeeded: false, serverError: null, enable: this.props.config.LdapSettings.Enable }; } handleChange() { this.setState({saveNeeded: true}); } handleEnable() { this.setState({saveNeeded: true, enable: true}); } handleDisable() { this.setState({saveNeeded: true, enable: false}); } handleSubmit(e) { e.preventDefault(); $('#save-button').button('loading'); const config = this.props.config; config.LdapSettings.Enable = this.refs.Enable.checked; config.LdapSettings.LdapServer = this.refs.LdapServer.value.trim(); let LdapPort = DEFAULT_LDAP_PORT; if (!isNaN(parseInt(ReactDOM.findDOMNode(this.refs.LdapPort).value, 10))) { LdapPort = parseInt(ReactDOM.findDOMNode(this.refs.LdapPort).value, 10); } config.LdapSettings.LdapPort = LdapPort; config.LdapSettings.BaseDN = this.refs.BaseDN.value.trim(); config.LdapSettings.BindUsername = this.refs.BindUsername.value.trim(); config.LdapSettings.BindPassword = this.refs.BindPassword.value.trim(); config.LdapSettings.FirstNameAttribute = this.refs.FirstNameAttribute.value.trim(); config.LdapSettings.LastNameAttribute = this.refs.LastNameAttribute.value.trim(); config.LdapSettings.EmailAttribute = this.refs.EmailAttribute.value.trim(); config.LdapSettings.UsernameAttribute = this.refs.UsernameAttribute.value.trim(); config.LdapSettings.IdAttribute = this.refs.IdAttribute.value.trim(); let QueryTimeout = DEFAULT_QUERY_TIMEOUT; if (!isNaN(parseInt(ReactDOM.findDOMNode(this.refs.QueryTimeout).value, 10))) { QueryTimeout = parseInt(ReactDOM.findDOMNode(this.refs.QueryTimeout).value, 10); } config.LdapSettings.QueryTimeout = QueryTimeout; Client.saveConfig( config, () => { AsyncClient.getConfig(); this.setState({ serverError: null, saveNeeded: false }); $('#save-button').button('reset'); }, (err) => { this.setState({ serverError: err.message, saveNeeded: true }); $('#save-button').button('reset'); } ); } render() { let serverError = ''; if (this.state.serverError) { serverError =
; } let saveClass = 'btn'; if (this.state.saveNeeded) { saveClass = 'btn btn-primary'; } return (

{'Note:'}

{'If a user attribute changes on the LDAP server it will be updated the next time the user enters their credentials to log in to Mattermost. This includes if a user is made inactive or removed from an LDAP server. Synchronization with LDAP servers is planned in a future release.'}

{'LDAP Settings'}

{'When true, Mattermost allows login using LDAP'}

{'The domain or IP address of LDAP server.'}

{'The port Mattermost will use to connect to the LDAP server. Default is 389.'}

{'The Base DN is the Distinguished Name of the location where Mattermost should start its search for users in the LDAP tree.'}

{'The username used to perform the LDAP search. This should typically be an account created specifically for use with Mattermost. It should have access limited to read the portion of the LDAP tree specified in the BaseDN field.'}

{'Password of the user given in "Bind Username".'}

{'The attribute in the LDAP server that will be used to populate the first name of users in Mattermost.'}

{'The attribute in the LDAP server that will be used to populate the last name of users in Mattermost.'}

{'The attribute in the LDAP server that will be used to populate the email addresses of users in Mattermost.'}

{'The attribute in the LDAP server that will be used to populate the username field in Mattermost. This may be the same as the ID Attribute.'}

{'The attribute in the LDAP server that will be used as a unique identifier in Mattermost. It should be an LDAP attribute with a value that does not change, such as username or uid. If a user’s Id Attribute changes, it will create a new Mattermost account unassociated with their old one. This is the value used to log in to Mattermost in the "LDAP Username" field on the sign in page. Normally this attribute is the same as the “Username Attribute” field above. If your team typically uses domain\\username to sign in to other services with LDAP, you may choose to put domain\\username in this field to maintain consistency between sites.'}

{'The timeout value for queries to the LDAP server. Increase if you are getting timeout errors caused by a slow LDAP server.'}

{serverError}
); } } LdapSettings.defaultProps = { }; LdapSettings.propTypes = { config: React.PropTypes.object };