From 8c2c8921446c0e098fdbc1e4287fc5e9b475d88a Mon Sep 17 00:00:00 2001
From: Joram Wilander
Date: Wed, 13 Apr 2016 19:31:01 -0400
Subject: [PATCH] Allow customization of LDAP login fields (#2692)
---
config/config.json | 4 +-
model/config.go | 14 +++++
utils/config.go | 2 +
.../admin_console/ldap_settings.jsx | 63 +++++++++++++++++++
.../login/components/login_ldap.jsx | 18 +++++-
webapp/i18n/en.json | 6 ++
6 files changed, 104 insertions(+), 3 deletions(-)
diff --git a/config/config.json b/config/config.json
index 5b05158b59..7f30859503 100644
--- a/config/config.json
+++ b/config/config.json
@@ -145,7 +145,9 @@
"UsernameAttribute": "",
"IdAttribute": "",
"SkipCertificateVerification": false,
- "QueryTimeout": 60
+ "QueryTimeout": 60,
+ "LoginFieldName": "",
+ "PasswordFieldName": ""
},
"ComplianceSettings": {
"Enable": false,
diff --git a/model/config.go b/model/config.go
index 26c71d07f1..6803fe069d 100644
--- a/model/config.go
+++ b/model/config.go
@@ -185,6 +185,10 @@ type LdapSettings struct {
// Advanced
SkipCertificateVerification *bool
QueryTimeout *int
+
+ // Customization
+ LoginFieldName *string
+ PasswordFieldName *string
}
type ComplianceSettings struct {
@@ -388,6 +392,16 @@ func (o *Config) SetDefaults() {
*o.LdapSettings.UserFilter = ""
}
+ if o.LdapSettings.LoginFieldName == nil {
+ o.LdapSettings.LoginFieldName = new(string)
+ *o.LdapSettings.LoginFieldName = ""
+ }
+
+ if o.LdapSettings.PasswordFieldName == nil {
+ o.LdapSettings.PasswordFieldName = new(string)
+ *o.LdapSettings.PasswordFieldName = ""
+ }
+
if o.ServiceSettings.SessionLengthWebInDays == nil {
o.ServiceSettings.SessionLengthWebInDays = new(int)
*o.ServiceSettings.SessionLengthWebInDays = 30
diff --git a/utils/config.go b/utils/config.go
index 244ff7180d..3cafb9d2f4 100644
--- a/utils/config.go
+++ b/utils/config.go
@@ -241,6 +241,8 @@ func getClientConfig(c *model.Config) map[string]string {
props["ProfileWidth"] = fmt.Sprintf("%v", c.FileSettings.ProfileWidth)
props["EnableLdap"] = strconv.FormatBool(*c.LdapSettings.Enable)
+ props["LdapLoginFieldName"] = *c.LdapSettings.LoginFieldName
+ props["LdapPasswordFieldName"] = *c.LdapSettings.PasswordFieldName
props["WebsocketPort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketPort)
props["WebsocketSecurePort"] = fmt.Sprintf("%v", *c.ServiceSettings.WebsocketSecurePort)
diff --git a/webapp/components/admin_console/ldap_settings.jsx b/webapp/components/admin_console/ldap_settings.jsx
index e5abec95fe..dd6e4338fc 100644
--- a/webapp/components/admin_console/ldap_settings.jsx
+++ b/webapp/components/admin_console/ldap_settings.jsx
@@ -67,6 +67,8 @@ class LdapSettings extends React.Component {
config.LdapSettings.UserFilter = this.refs.UserFilter.value.trim();
config.LdapSettings.ConnectionSecurity = this.state.connectionSecurity.trim();
config.LdapSettings.SkipCertificateVerification = this.state.skipCertificateVerification;
+ config.LdapSettings.LoginFieldName = this.refs.LoginFieldName.value.trim();
+ config.LdapSettings.PasswordFieldName = this.refs.PasswordFieldName.value.trim();
let QueryTimeout = DEFAULT_QUERY_TIMEOUT;
if (!isNaN(parseInt(ReactDOM.findDOMNode(this.refs.QueryTimeout).value, 10))) {
@@ -571,6 +573,67 @@ class LdapSettings extends React.Component {
+
+
+
+
+
{serverError}
diff --git a/webapp/components/login/components/login_ldap.jsx b/webapp/components/login/components/login_ldap.jsx
index a2013710fb..36b8a406cc 100644
--- a/webapp/components/login/components/login_ldap.jsx
+++ b/webapp/components/login/components/login_ldap.jsx
@@ -52,6 +52,20 @@ export default class LoginLdap extends React.Component {
errorClass = ' has-error';
}
+ let loginPlaceholder;
+ if (global.window.mm_config.LdapLoginFieldName) {
+ loginPlaceholder = global.window.mm_config.LdapLoginFieldName;
+ } else {
+ loginPlaceholder = Utils.localizeMessage('login_ldap.username', 'LDAP Username');
+ }
+
+ let passwordPlaceholder;
+ if (global.window.mm_config.LdapPasswordFieldName) {
+ passwordPlaceholder = global.window.mm_config.LdapPasswordFieldName;
+ } else {
+ passwordPlaceholder = Utils.localizeMessage('login_ldap.pwd', 'LDAP Password');
+ }
+
return (
diff --git a/webapp/i18n/en.json b/webapp/i18n/en.json
index 75d516f901..ee2d472e74 100644
--- a/webapp/i18n/en.json
+++ b/webapp/i18n/en.json
@@ -241,6 +241,12 @@
"admin.image.thumbWidthExample": "Ex \"120\"",
"admin.image.thumbWidthTitle": "Thumbnail Width:",
"admin.image.true": "true",
+ "admin.ldap.loginNameTitle": "Login Field Name:",
+ "admin.ldap.loginNameEx": "Ex \"LDAP Username\"",
+ "admin.ldap.loginNameDesc": "The placeholder text that appears in the login field on the login page. Defaults to \"LDAP Username\".",
+ "admin.ldap.passwordFieldTitle": "Password Field Name:",
+ "admin.ldap.passwordFieldEx": "Ex \"LDAP Password\"",
+ "admin.ldap.passwordFieldDesc": "The placeholder text that appears in the password field on the login page. Defaults to \"LDAP Password\".",
"admin.ldap.bannerDesc": "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.",
"admin.ldap.bannerHeading": "Note:",
"admin.ldap.baseDesc": "The Base DN is the Distinguished Name of the location where Mattermost should start its search for users in the LDAP tree.",