|
|
@@ -20,6 +20,12 @@ const validator = {
|
|
|
body('hideRestrictedByOwner').isBoolean(),
|
|
|
body('hideRestrictedByGroup').isBoolean(),
|
|
|
],
|
|
|
+ authenticationSetting: [
|
|
|
+ body('isEnabled').isBoolean(),
|
|
|
+ body('authId').isString().isIn([
|
|
|
+ 'local', 'ldap', 'saml', 'oidc', 'basic', 'google', 'github', 'twitter',
|
|
|
+ ]),
|
|
|
+ ],
|
|
|
localSetting: [
|
|
|
body('isLocalEnabled').isBoolean(),
|
|
|
body('registrationMode').isString(),
|
|
|
@@ -393,6 +399,65 @@ module.exports = (crowi) => {
|
|
|
return res.apiv3({ securityParams });
|
|
|
});
|
|
|
|
|
|
+ /**
|
|
|
+ * @swagger
|
|
|
+ *
|
|
|
+ * /_api/v3/security-setting/authentication/enabled:
|
|
|
+ * put:
|
|
|
+ * tags: [SecuritySetting]
|
|
|
+ * description: Update authentication isEnabled
|
|
|
+ * requestBody:
|
|
|
+ * required: true
|
|
|
+ * content:
|
|
|
+ * application/json:
|
|
|
+ * schema:
|
|
|
+ * type: object
|
|
|
+ * properties:
|
|
|
+ * isEnabled:
|
|
|
+ * type: boolean
|
|
|
+ * target:
|
|
|
+ * type: string
|
|
|
+ * responses:
|
|
|
+ * 200:
|
|
|
+ * description: Succeeded to enable authentication
|
|
|
+ * content:
|
|
|
+ * application/json:
|
|
|
+ * schema:
|
|
|
+ * type: object
|
|
|
+ * description: updated param
|
|
|
+ */
|
|
|
+ router.put('/authentication/enabled', loginRequiredStrictly, adminRequired, csrf, validator.authenticationSetting, ApiV3FormValidator, async(req, res) => {
|
|
|
+ const { isEnabled, authId } = req.body;
|
|
|
+
|
|
|
+ let setupStrategies = await crowi.passportService.getSetupStrategies();
|
|
|
+
|
|
|
+ // Reflect request param
|
|
|
+ setupStrategies = setupStrategies.filter(strategy => strategy !== authId);
|
|
|
+
|
|
|
+ if (setupStrategies.length === 0) {
|
|
|
+ return res.apiv3Err(new ErrorV3('Can not turn everything off'));
|
|
|
+ }
|
|
|
+
|
|
|
+ const enableParams = { [`security:passport-${authId}:isEnabled`]: isEnabled };
|
|
|
+
|
|
|
+ try {
|
|
|
+ await crowi.configManager.updateConfigsInTheSameNamespace('crowi', enableParams);
|
|
|
+
|
|
|
+ await crowi.passportService.setupStrategyById(authId);
|
|
|
+
|
|
|
+ const responseParams = { [`security:passport-${authId}:isEnabled`]: await crowi.configManager.getConfig('crowi', `security:passport-${authId}:isEnabled`) };
|
|
|
+
|
|
|
+ return res.apiv3({ responseParams });
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ const msg = 'Error occurred in updating enable setting';
|
|
|
+ logger.error('Error', err);
|
|
|
+ return res.apiv3Err(new ErrorV3(msg, 'update-enable-setting failed'));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
/**
|
|
|
* @swagger
|
|
|
*
|
|
|
@@ -472,6 +537,7 @@ module.exports = (crowi) => {
|
|
|
};
|
|
|
try {
|
|
|
await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
|
|
|
+ await crowi.passportService.setupStrategyById('local');
|
|
|
const localSettingParams = {
|
|
|
isLocalEnabled: await crowi.configManager.getConfig('crowi', 'security:passport-local:isEnabled'),
|
|
|
registrationMode: await crowi.configManager.getConfig('crowi', 'security:registrationMode'),
|
|
|
@@ -525,6 +591,7 @@ module.exports = (crowi) => {
|
|
|
|
|
|
try {
|
|
|
await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
|
|
|
+ await crowi.passportService.setupStrategyById('ldap');
|
|
|
const securitySettingParams = {
|
|
|
serverUrl: await crowi.configManager.getConfig('crowi', 'security:passport-ldap:serverUrl'),
|
|
|
isUserBind: await crowi.configManager.getConfig('crowi', 'security:passport-ldap:isUserBind'),
|
|
|
@@ -585,6 +652,7 @@ module.exports = (crowi) => {
|
|
|
|
|
|
try {
|
|
|
await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
|
|
|
+ await crowi.passportService.setupStrategyById('saml');
|
|
|
const securitySettingParams = {
|
|
|
missingMandatoryConfigKeys: await crowi.passportService.getSamlMissingMandatoryConfigKeys(),
|
|
|
samlEntryPoint: await crowi.configManager.getConfigFromDB('crowi', 'security:passport-saml:entryPoint'),
|
|
|
@@ -644,6 +712,7 @@ module.exports = (crowi) => {
|
|
|
|
|
|
try {
|
|
|
await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
|
|
|
+ await crowi.passportService.setupStrategyById('oidc');
|
|
|
const securitySettingParams = {
|
|
|
oidcProviderName: await crowi.configManager.getConfig('crowi', 'security:passport-oidc:providerName'),
|
|
|
oidcIssuerHost: await crowi.configManager.getConfig('crowi', 'security:passport-oidc:issuerHost'),
|
|
|
@@ -693,6 +762,7 @@ module.exports = (crowi) => {
|
|
|
|
|
|
try {
|
|
|
await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
|
|
|
+ await crowi.passportService.setupStrategyById('basic');
|
|
|
const securitySettingParams = {
|
|
|
isSameUsernameTreatedAsIdenticalUser: await crowi.configManager.getConfig('crowi', 'security:passport-basic:isSameUsernameTreatedAsIdenticalUser'),
|
|
|
};
|
|
|
@@ -735,23 +805,16 @@ module.exports = (crowi) => {
|
|
|
|
|
|
try {
|
|
|
await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
|
|
|
+ await crowi.passportService.setupStrategyById('google');
|
|
|
const securitySettingParams = {
|
|
|
isGoogleOAuthEnabled: await crowi.configManager.getConfig('crowi', 'security:passport-google:isEnabled'),
|
|
|
googleClientId: await crowi.configManager.getConfig('crowi', 'security:passport-google:clientId'),
|
|
|
googleClientSecret: await crowi.configManager.getConfig('crowi', 'security:passport-google:clientSecret'),
|
|
|
isSameUsernameTreatedAsIdenticalUser: await crowi.configManager.getConfig('crowi', 'security:passport-google:isSameUsernameTreatedAsIdenticalUser'),
|
|
|
};
|
|
|
- // reset strategy
|
|
|
- await crowi.passportService.resetGoogleStrategy();
|
|
|
- // setup strategy
|
|
|
- if (crowi.configManager.getConfig('crowi', 'security:passport-google:isEnabled')) {
|
|
|
- await crowi.passportService.setupGoogleStrategy(true);
|
|
|
- }
|
|
|
return res.apiv3({ securitySettingParams });
|
|
|
}
|
|
|
catch (err) {
|
|
|
- // reset strategy
|
|
|
- await crowi.passportService.resetGoogleStrategy();
|
|
|
const msg = 'Error occurred in updating googleOAuth';
|
|
|
logger.error('Error', err);
|
|
|
return res.apiv3Err(new ErrorV3(msg, 'update-googleOAuth-failed'));
|
|
|
@@ -788,18 +851,13 @@ module.exports = (crowi) => {
|
|
|
|
|
|
try {
|
|
|
await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
|
|
|
+ await crowi.passportService.setupStrategyById('github');
|
|
|
const securitySettingParams = {
|
|
|
isGitHubStrategySetup: await crowi.passportService.isGitHubStrategySetup,
|
|
|
githubClientId: await crowi.configManager.getConfig('crowi', 'security:passport-github:clientId'),
|
|
|
githubClientSecret: await crowi.configManager.getConfig('crowi', 'security:passport-github:clientSecret'),
|
|
|
isSameUsernameTreatedAsIdenticalUser: await crowi.configManager.getConfig('crowi', 'security:passport-github:isSameUsernameTreatedAsIdenticalUser'),
|
|
|
};
|
|
|
- // reset strategy
|
|
|
- await crowi.passportService.resetGitHubStrategy();
|
|
|
- // setup strategy
|
|
|
- if (crowi.configManager.getConfig('crowi', 'security:passport-github:isEnabled')) {
|
|
|
- await crowi.passportService.setupGitHubStrategy(true);
|
|
|
- }
|
|
|
return res.apiv3({ securitySettingParams });
|
|
|
}
|
|
|
catch (err) {
|
|
|
@@ -841,23 +899,16 @@ module.exports = (crowi) => {
|
|
|
|
|
|
try {
|
|
|
await crowi.configManager.updateConfigsInTheSameNamespace('crowi', requestParams);
|
|
|
+ await crowi.passportService.setupStrategyById('twitter');
|
|
|
const securitySettingParams = {
|
|
|
isTwitterStrategySetup: await crowi.passportService.isTwitterStrategySetup,
|
|
|
twitterConsumerId: await crowi.configManager.getConfig('crowi', 'security:passport-twitter:consumerKey'),
|
|
|
twitterConsumerSecret: await crowi.configManager.getConfig('crowi', 'security:passport-twitter:consumerSecret'),
|
|
|
isSameUsernameTreatedAsIdenticalUser: await crowi.configManager.getConfig('crowi', 'security:passport-twitter:isSameUsernameTreatedAsIdenticalUser'),
|
|
|
};
|
|
|
- // reset strategy
|
|
|
- await crowi.passportService.resetTwitterStrategy();
|
|
|
- // setup strategy
|
|
|
- if (crowi.configManager.getConfig('crowi', 'security:passport-twitter:isEnabled')) {
|
|
|
- await crowi.passportService.setupTwitterStrategy(true);
|
|
|
- }
|
|
|
return res.apiv3({ securitySettingParams });
|
|
|
}
|
|
|
catch (err) {
|
|
|
- // reset strategy
|
|
|
- await crowi.passportService.resetTwitterStrategy();
|
|
|
const msg = 'Error occurred in updating twitterOAuth';
|
|
|
logger.error('Error', err);
|
|
|
return res.apiv3Err(new ErrorV3(msg, 'update-twitterOAuth-failed'));
|