itizawa 6 лет назад
Родитель
Сommit
ce4167f000

+ 11 - 15
src/client/js/services/AdminSamlSecurityContainer.js

@@ -157,23 +157,19 @@ export default class AdminSamlSecurityContainer extends Container {
    * Update saml option
    */
   async updateSamlSetting() {
-    const {
-      samlEntryPoint, samlIssuer, samlCert, samlAttrMapId, samlAttrMapUserName, samlAttrMapMail,
-      samlAttrMapFirstName, samlAttrMapLastName, isSameUsernameTreatedAsIdenticalUser, isSameEmailTreatedAsIdenticalUser, samlABLCRule,
-    } = this.state;
 
     let requestParams = {
-      samlEntryPoint,
-      samlIssuer,
-      samlCert,
-      samlAttrMapId,
-      samlAttrMapUserName,
-      samlAttrMapMail,
-      samlAttrMapFirstName,
-      samlAttrMapLastName,
-      isSameUsernameTreatedAsIdenticalUser,
-      isSameEmailTreatedAsIdenticalUser,
-      samlABLCRule,
+      entryPoint: this.state.samlEntryPoint,
+      issuer: this.state.samlIssuer,
+      cert: this.state.cert,
+      attrMapId: this.state.samlAttrMapId,
+      attrMapUserName: this.state.samlAttrMapUserName,
+      attrMapMail: this.state.samlAttrMapMail,
+      attrMapFirstName: this.state.samlAttrMapFirstName,
+      attrMapLastName: this.state.samlAttrMapLastName,
+      isSameUsernameTreatedAsIdenticalUser: this.state.isSameUsernameTreatedAsIdenticalUser,
+      isSameEmailTreatedAsIdenticalUser: this.state.isSameEmailTreatedAsIdenticalUser,
+      ABLCRule: this.state.ABLCRule,
     };
 
     requestParams = await removeNullPropertyFromObject(requestParams);

+ 0 - 24
src/server/routes/admin.js

@@ -559,29 +559,5 @@ module.exports = function(crowi, app) {
     return res.json(ApiResponse.success());
   };
 
-  // /**
-  //  * validate setting form values for SAML
-  //  *
-  //  * - For the value of each mandatory items,
-  //  *     check whether it from the environment variables is empty and form value to update it is empty
-  //  * - validate the syntax of a attribute-based login control rule
-  //  */
-  // function validateSamlSettingForm(form, t) {
-  //   for (const key of crowi.passportService.mandatoryConfigKeysForSaml) {
-  //     const formValue = form.settingForm[key];
-  //     if (configManager.getConfigFromEnvVars('crowi', key) === null && formValue === '') {
-  //       const formItemName = t(`security_setting.form_item_name.${key}`);
-  //       form.errors.push(t('form_validation.required', formItemName));
-  //     }
-  //   }
-
-  //   const rule = form.settingForm['security:passport-saml:ABLCRule'];
-  //   // Empty string disables attribute-based login control.
-  //   // So, when rule is empty string, validation is passed.
-  //   if (rule !== '' && (rule == null || crowi.passportService.parseABLCRule(rule) == null)) {
-  //     form.errors.push(t('form_validation.invalid_syntax', t('security_setting.form_item_name.security:passport-saml:ABLCRule')));
-  //   }
-  // }
-
   return actions;
 };

+ 26 - 10
src/server/routes/apiv3/security-setting.js

@@ -51,17 +51,17 @@ const validator = {
     body('ldapGroupDnProperty').if((value, { req }) => req.body.ldapGroupDnProperty).isString(),
   ],
   samlAuth: [
-    body('samlEntryPoint').if((value, { req }) => req.body.samlEntryPoint).isString(),
-    body('samlIssuer').if((value, { req }) => req.body.samlIssuer).isString(),
-    body('samlCert').if((value, { req }) => req.body.samlCert).isString(),
-    body('samlAttrMapId').if((value, { req }) => req.body.samlAttrMapId).isString(),
-    body('samlAttrMapUserName').if((value, { req }) => req.body.samlAttrMapUserName).isString(),
-    body('samlAttrMapMail').if((value, { req }) => req.body.samlAttrMapMail).isString(),
-    body('samlAttrMapFirstName').if((value, { req }) => req.body.samlAttrMapFirstName).isString(),
-    body('samlAttrMapLastName').if((value, { req }) => req.body.samlAttrMapLastName).isString(),
+    body('entryPoint').if((value, { req }) => req.body.samlEntryPoint).isString(),
+    body('issuer').if((value, { req }) => req.body.samlIssuer).isString(),
+    body('cert').if((value, { req }) => req.body.samlCert).isString(),
+    body('attrMapId').if((value, { req }) => req.body.samlAttrMapId).isString(),
+    body('attrMapUserName').if((value, { req }) => req.body.samlAttrMapUserName).isString(),
+    body('attrMapMail').if((value, { req }) => req.body.samlAttrMapMail).isString(),
+    body('attrMapFirstName').if((value, { req }) => req.body.samlAttrMapFirstName).isString(),
+    body('attrMapLastName').if((value, { req }) => req.body.samlAttrMapLastName).isString(),
     body('isSameUsernameTreatedAsIdenticalUser').if((value, { req }) => req.body.isSameUsernameTreatedAsIdenticalUser).isBoolean(),
     body('isSameEmailTreatedAsIdenticalUser').if((value, { req }) => req.body.isSameEmailTreatedAsIdenticalUser).isBoolean(),
-    body('samlABLCRule').if((value, { req }) => req.body.samlABLCRule).isString(),
+    body('ABLCRule').if((value, { req }) => req.body.samlABLCRule).isString(),
   ],
   oidcAuth: [
     body('oidcProviderName').if((value, { req }) => req.body.oidcProviderName).isString(),
@@ -643,11 +643,27 @@ module.exports = (crowi) => {
    */
   router.put('/saml', loginRequiredStrictly, adminRequired, csrf, validator.samlAuth, ApiV3FormValidator, async(req, res) => {
 
+    //  For the value of each mandatory items,
+    //  check whether it from the environment variables is empty and form value to update it is empty
+    //  validate the syntax of a attribute - based login control rule
+    res.errors = [];
+    for (const configKey of crowi.passportService.mandatoryConfigKeysForSaml) {
+      const key = configKey.replace('security:passport-saml:', '');
+      const formValue = req.body[key];
+      if (crowi.configManager.getConfigFromEnvVars('crowi', configKey) === null && formValue == null) {
+        const formItemName = req.t(`security_setting.form_item_name.${key}`);
+        res.errors.push(req.t('form_validation.required', formItemName));
+      }
+    }
+    if (res.errors.length !== 0) {
+      return res.apiv3Err(req.t('form_validation.error_message'), 400);
+    }
+
     const rule = req.body.samlABLCRule;
     // Empty string disables attribute-based login control.
     // So, when rule is empty string, validation is passed.
     if (rule !== '' && (rule == null || crowi.passportService.parseABLCRule(rule) == null)) {
-      return res.apiv3Err(req.t('form_validation.invalid_syntax', { target: req.t('security_setting.form_item_name.ABLCRule') }), 400);
+      return res.apiv3Err(req.t('form_validation.invalid_syntax', req.t('security_setting.form_item_name.ABLCRule')), 400);
     }
 
     const requestParams = {

+ 0 - 1
src/server/service/passport.js

@@ -73,7 +73,6 @@ class PassportService {
      * the keys of mandatory configs for SAML
      */
     this.mandatoryConfigKeysForSaml = [
-      'security:passport-saml:isEnabled',
       'security:passport-saml:entryPoint',
       'security:passport-saml:issuer',
       'security:passport-saml:cert',