|
|
@@ -14,6 +14,32 @@ class PassportService {
|
|
|
|
|
|
constructor(crowi) {
|
|
|
this.crowi = crowi;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * the flag whether LocalStrategy is set up successfully
|
|
|
+ */
|
|
|
+ this.isLocalStrategySetup = false;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * the flag whether LdapStrategy is set up successfully
|
|
|
+ */
|
|
|
+ this.isLdapStrategySetup = false;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * the flag whether serializer/deserializer are set up successfully
|
|
|
+ */
|
|
|
+ this.isSerializerSetup = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * reset LocalStrategy
|
|
|
+ *
|
|
|
+ * @memberof PassportService
|
|
|
+ */
|
|
|
+ resetLocalStrategy() {
|
|
|
+ debug('LocalStrategy: reset');
|
|
|
+ passport.unuse('local');
|
|
|
+ this.isLocalStrategySetup = false;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -21,7 +47,15 @@ class PassportService {
|
|
|
*
|
|
|
* @memberof PassportService
|
|
|
*/
|
|
|
- setupLocalStrategy() {
|
|
|
+ setupLocalStrategy(isForce) {
|
|
|
+ if (isForce === true) {
|
|
|
+ this.resetLocalStrategy();
|
|
|
+ }
|
|
|
+ // check whether the strategy has already been set up
|
|
|
+ if (this.isLocalStrategySetup) {
|
|
|
+ throw new Error('LocalStrategy has already been set up');
|
|
|
+ }
|
|
|
+
|
|
|
debug('LocalStrategy: setting up..');
|
|
|
|
|
|
const User = this.crowi.model('User');
|
|
|
@@ -43,13 +77,36 @@ class PassportService {
|
|
|
});
|
|
|
}
|
|
|
));
|
|
|
+
|
|
|
+ this.isLocalStrategySetup = true;
|
|
|
debug('LocalStrategy: setup is done');
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
+ /**
|
|
|
+ * reset LdapStrategy
|
|
|
+ *
|
|
|
+ * @memberof PassportService
|
|
|
+ */
|
|
|
+ resetLdapStrategy() {
|
|
|
+ debug('LdapStrategy: reset');
|
|
|
+ passport.unuse('ldapauth');
|
|
|
+ this.isLdapStrategySetup = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Asynchronous configuration retrieval
|
|
|
+ *
|
|
|
+ * @memberof PassportService
|
|
|
*/
|
|
|
- setupLdapStrategy() {
|
|
|
+ setupLdapStrategy(isForce) {
|
|
|
+ if (isForce === true) {
|
|
|
+ this.resetLdapStrategy();
|
|
|
+ }
|
|
|
+ // 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;
|
|
|
@@ -78,7 +135,7 @@ class PassportService {
|
|
|
debug(`LdapStrategy: bindDN=${bindDN}`);
|
|
|
debug(`LdapStrategy: bindCredentials=${bindCredentials}`);
|
|
|
}
|
|
|
- debug(`LdapStrategy searchFilter: ${searchFilter}`);
|
|
|
+ debug(`LdapStrategy: searchFilter=${searchFilter}`);
|
|
|
|
|
|
// Asynchronous configuration retrieval
|
|
|
const getLDAPConfiguration = (req, callback) => {
|
|
|
@@ -120,6 +177,7 @@ class PassportService {
|
|
|
}
|
|
|
));
|
|
|
|
|
|
+ this.isLdapStrategySetup = true;
|
|
|
debug('LdapStrategy: setup is done');
|
|
|
}
|
|
|
|
|
|
@@ -129,6 +187,11 @@ class PassportService {
|
|
|
* @memberof PassportService
|
|
|
*/
|
|
|
setupSerializer() {
|
|
|
+ // check whether the serializer/deserializer have already been set up
|
|
|
+ if (this.isSerializerSetup) {
|
|
|
+ throw new Error('serializer/deserializer have already been set up');
|
|
|
+ }
|
|
|
+
|
|
|
debug('setting up serializer and deserializer');
|
|
|
|
|
|
const User = this.crowi.model('User');
|
|
|
@@ -141,6 +204,8 @@ class PassportService {
|
|
|
done(err, user);
|
|
|
});
|
|
|
});
|
|
|
+
|
|
|
+ this.isSerializerSetup = true;
|
|
|
}
|
|
|
|
|
|
}
|