Просмотр исходного кода

BugFix getLdapConfigurationFunc

Yuki Takei 8 лет назад
Родитель
Сommit
f4d0efaec3
1 измененных файлов с 7 добавлено и 10 удалено
  1. 7 10
      lib/service/passport.js

+ 7 - 10
lib/service/passport.js

@@ -158,8 +158,8 @@ class PassportService {
     // get configurations
     const isUserBind      = config.crowi['security:passport-ldap:isUserBind'];
     const serverUrl       = config.crowi['security:passport-ldap:serverUrl'];
-    let   bindDN          = config.crowi['security:passport-ldap:bindDN'];
-    let   bindCredentials = config.crowi['security:passport-ldap:bindDNPassword'];
+    const bindDN          = config.crowi['security:passport-ldap:bindDN'];
+    const bindCredentials = config.crowi['security:passport-ldap:bindDNPassword'];
     const searchFilter    = config.crowi['security:passport-ldap:searchFilter'] || '(uid={{username}})';
 
     // parse serverUrl
@@ -182,9 +182,6 @@ class PassportService {
     debug(`LdapStrategy: searchFilter=${searchFilter}`);
 
     return (req, callback) => {
-      // TODO impl test mode
-
-
       // get credentials from form data
       const loginForm = req.body.loginForm;
       if (!req.form.isValid) {
@@ -192,16 +189,16 @@ class PassportService {
       }
 
       // user bind
-      if (isUserBind) {
-        bindDN = bindDN.replace(/{{username}}/, loginForm.username);
-        bindCredentials = loginForm.password;
-      }
+      const fixedBindDN = (isUserBind) ?
+          bindDN.replace(/{{username}}/, loginForm.username):
+          bindDN;
+      const fixedBindCredentials = (isUserBind) ? loginForm.password : bindCredentials;
 
       process.nextTick(() => {
         const mergedOpts = Object.assign({
           usernameField: PassportService.USERNAME_FIELD,
           passwordField: PassportService.PASSWORD_FIELD,
-          server: { url, bindDN, bindCredentials, searchBase, searchFilter },
+          server: { url, bindDN: fixedBindDN, bindCredentials: fixedBindCredentials, searchBase, searchFilter },
         }, opts);
         debug('ldap configuration: ', mergedOpts);
         callback(null, mergedOpts);