Przeglądaj źródła

store ldap logs to req

Yuki Takei 7 lat temu
rodzic
commit
1958365fbe
2 zmienionych plików z 15 dodań i 0 usunięć
  1. 7 0
      lib/routes/login-passport.js
  2. 8 0
      lib/service/passport.js

+ 7 - 0
lib/routes/login-passport.js

@@ -174,12 +174,15 @@ module.exports = function(crowi, app) {
         return res.json({
         return res.json({
           status: 'warning',
           status: 'warning',
           message: 'LDAP Server Error occured.',
           message: 'LDAP Server Error occured.',
+          err
         });
         });
       }
       }
       if (info && info.message) {
       if (info && info.message) {
         return res.json({
         return res.json({
           status: 'warning',
           status: 'warning',
           message: info.message,
           message: info.message,
+          ldapConfiguration: req.ldapConfiguration,
+          ldapAccountInfo: req.ldapAccountInfo,
         });
         });
       }
       }
       if (user) {
       if (user) {
@@ -188,11 +191,15 @@ module.exports = function(crowi, app) {
           return res.json({
           return res.json({
             status: 'warning',
             status: 'warning',
             message: 'The user is found, but that has no groups.',
             message: 'The user is found, but that has no groups.',
+            ldapConfiguration: req.ldapConfiguration,
+            ldapAccountInfo: req.ldapAccountInfo,
           });
           });
         }
         }
         return res.json({
         return res.json({
           status: 'success',
           status: 'success',
           message: 'Successfully authenticated.',
           message: 'Successfully authenticated.',
+          ldapConfiguration: req.ldapConfiguration,
+          ldapAccountInfo: req.ldapAccountInfo,
         });
         });
       }
       }
     })(req, res, () => {});
     })(req, res, () => {});

+ 8 - 0
lib/service/passport.js

@@ -115,6 +115,10 @@ class PassportService {
     passport.use(new LdapStrategy(this.getLdapConfigurationFunc(config, {passReqToCallback: true}),
     passport.use(new LdapStrategy(this.getLdapConfigurationFunc(config, {passReqToCallback: true}),
       (req, ldapAccountInfo, done) => {
       (req, ldapAccountInfo, done) => {
         debug('LDAP authentication has succeeded', ldapAccountInfo);
         debug('LDAP authentication has succeeded', ldapAccountInfo);
+
+        // store ldapAccountInfo to req
+        req.ldapAccountInfo = ldapAccountInfo;
+
         done(null, ldapAccountInfo);
         done(null, ldapAccountInfo);
       }
       }
     ));
     ));
@@ -212,6 +216,10 @@ class PassportService {
           server: serverOpt,
           server: serverOpt,
         }, opts);
         }, opts);
         debug('ldap configuration: ', mergedOpts);
         debug('ldap configuration: ', mergedOpts);
+
+        // store configuration to req
+        req.ldapConfiguration = mergedOpts;
+
         callback(null, mergedOpts);
         callback(null, mergedOpts);
       });
       });
     };
     };