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

ensure to remove 'isForce' option from the methods to setup strategy

Yuki Takei 8 лет назад
Родитель
Сommit
c5d2c9c365
2 измененных файлов с 14 добавлено и 12 удалено
  1. 3 2
      lib/crowi/index.js
  2. 11 10
      lib/service/passport.js

+ 3 - 2
lib/crowi/index.js

@@ -263,14 +263,15 @@ Crowi.prototype.setupPassport = function() {
 
   debug('Passport is enabled');
 
+  // initialize service
   const PassportService = require('../service/passport');
-
   if (this.passportService == null) {
     this.passportService = new PassportService(this);
   }
+  this.passportService.setupSerializer();
+  // setup strategies
   this.passportService.setupLocalStrategy();
   this.passportService.setupLdapStrategy();
-  this.passportService.setupSerializer();
 
   return Promise.resolve();
 }

+ 11 - 10
lib/service/passport.js

@@ -47,10 +47,7 @@ class PassportService {
    *
    * @memberof PassportService
    */
-  setupLocalStrategy(isForce) {
-    if (isForce === true) {
-      this.resetLocalStrategy();
-    }
+  setupLocalStrategy() {
     // check whether the strategy has already been set up
     if (this.isLocalStrategySetup) {
       throw new Error('LocalStrategy has already been set up');
@@ -98,18 +95,22 @@ class PassportService {
    *
    * @memberof PassportService
    */
-  setupLdapStrategy(isForce) {
-    if (isForce === true) {
-      this.resetLdapStrategy();
-    }
+  setupLdapStrategy() {
     // check whether the strategy has already been set up
     if (this.isLdapStrategySetup) {
       throw new Error('LdapStrategy has already been set up');
     }
 
-    debug('LdapStrategy: setting up..');
-
     const config = this.crowi.config;
+    const Config = this.crowi.model('Config');
+    const isLdapEnabled = Config.isEnabledPassportLdap(config);
+
+    // when disabled
+    if (!isLdapEnabled) {
+      return;
+    }
+
+    debug('LdapStrategy: setting up..');
 
     // get configurations
     const isUserBind      = config.crowi['security:passport-ldap:isUserBind'];