All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.internet2.middleware.grouper.app.scim2Provisioning.Scim2SyncConfigurationValidation Maven / Gradle / Ivy

There is a newer version: 5.13.5
Show newest version
package edu.internet2.middleware.grouper.app.scim2Provisioning;

import java.util.Collection;

import org.apache.commons.lang.StringUtils;

import edu.internet2.middleware.grouper.app.provisioning.GrouperProvisioner;
import edu.internet2.middleware.grouper.app.provisioning.GrouperProvisioningBehavior;
import edu.internet2.middleware.grouper.app.provisioning.GrouperProvisioningConfigurationAttribute;
import edu.internet2.middleware.grouper.app.provisioning.GrouperProvisioningConfigurationValidation;
import edu.internet2.middleware.grouper.app.provisioning.ProvisioningValidationIssue;
import edu.internet2.middleware.grouper.cfg.text.GrouperTextContainer;
import edu.internet2.middleware.grouper.util.GrouperUtil;


public class Scim2SyncConfigurationValidation extends GrouperProvisioningConfigurationValidation {

  @Override
  public void validateFromObjectModel() {
    super.validateFromObjectModel();
    
    String scimType = this.getSuffixToConfigValue().get("scimType");
    if (StringUtils.equals("Github", scimType)) {
      
      GrouperProvisioner grouperProvisioner = this.getGrouperProvisioner();
      GrouperScim2ProvisionerConfiguration grouperProvisioningConfiguration = (GrouperScim2ProvisionerConfiguration)grouperProvisioner.retrieveGrouperProvisioningConfiguration();
      GrouperProvisioningBehavior grouperProvisioningBehavior = grouperProvisioner.retrieveGrouperProvisioningBehavior();

      if (grouperProvisioningBehavior.isSelectGroups() && grouperProvisioningConfiguration.isSelectAllGroups()) {
        this.addErrorMessage(new ProvisioningValidationIssue()
            .assignMessage(GrouperTextContainer.textOrNull("scim2githubCannotSelectAllGroupsAtOnce"))
            .assignJqueryHandle("selectAllGroups"));
        
      }
      
      if (grouperProvisioningConfiguration.isOperateOnGrouperGroups()) {
        if (!grouperProvisioningConfiguration.isCustomizeGroupCrud() || grouperProvisioningConfiguration.isInsertGroups() || grouperProvisioningConfiguration.isUpdateGroups() 
            || grouperProvisioningConfiguration.isDeleteGroups()
            || !grouperProvisioningConfiguration.isSelectGroups()) {
          this.addErrorMessage(new ProvisioningValidationIssue()
              .assignMessage(GrouperTextContainer.textOrNull("scim2githubMustSelectOnly"))
              .assignJqueryHandle("customizeGroupCrud"));
          
        }
      }
      
      if (grouperProvisioningBehavior.isSelectGroups()) {

        boolean foundId = false;
        for (String attributeName : GrouperUtil.nonNull(grouperProvisioningConfiguration.getTargetGroupAttributeNameToConfig().keySet())) {
        
          GrouperProvisioningConfigurationAttribute grouperProvisioningConfigurationAttribute = grouperProvisioningConfiguration.getTargetGroupAttributeNameToConfig().get(attributeName);       
        
          if (!StringUtils.equals("id", grouperProvisioningConfigurationAttribute.getName())) {
            this.addErrorMessage(new ProvisioningValidationIssue().assignMessage(GrouperTextContainer.textOrNull("scim2githubOnlyGroupAttributeIsOrgInUrl"))
                .assignJqueryHandle(grouperProvisioningConfigurationAttribute.configKey(attributeName)));
            
          } else {
            foundId = true;
          }
        }
        
        if (!foundId) {
          this.addErrorMessage(new ProvisioningValidationIssue().assignMessage(GrouperTextContainer.textOrNull("scim2githubMustHaveGroupAttributeOrgInUrl")));
        }
      }
    }
    
    /**
     * # Select memberships
      # {valueType: "string", readOnly: true, order: 1500, subSection: "membership", showEl: "${operateOnGrouperMemberships}"}
      # provisioner.myScimProvisioner.selectMemberships = false
      
      # Replace memberships
      # {valueType: "boolean", order: 2491, defaultValue: "false", subSection: "membership", showEl: "${operateOnGrouperMemberships}"}
      # provisioner.myScimProvisioner.replaceMemberships = 
      
      # Update groups
      # {valueType: "string", readOnly: true, order: 11500, subSection: "group", showEl: "${operateOnGrouperGroups}"}
      # provisioner.myScimProvisioner.updateGroups = false
     */
    
    //update cannot be true 
    // if they don't edit it to make it true, then provisioner 
    
  }
  
  @Override
  public Collection validateGroupAttributeNamesAllowed() {
    return null;
  }

  @Override
  public Collection validateGroupAttributeNamesRequired() {
    int numberOfAttributes = GrouperUtil.intValue(this.getSuffixToConfigValue().get("numberOfGroupAttributes"), 0);
    if (numberOfAttributes > 0) {

      String scimType = this.getSuffixToConfigValue().get("scimType");
      if (StringUtils.equals("Github", scimType)) {
        return null;
      } else if (StringUtils.equals("AWS", scimType)) {
        return GrouperUtil.toSet("displayName", "id");
      } 
    }
    return null;
  }

  @Override
  public boolean validateGroupAttributesRequireString() {
    return true;
  }

  @Override
  public Collection validateEntityAttributeNamesAllowed() {
    String scimType = this.getSuffixToConfigValue().get("scimType");
    if (StringUtils.equals("Github", scimType)) {
      return null;
    } else if (StringUtils.equals("AWS", scimType)) {
      return GrouperUtil.toSet("active", "externalId", "formattedName", "middleName", "emailValue", "emailType", "userType", "employeeNumber", "costCenter");
    } 
    return null;
  }

  @Override
  public Collection validateEntityAttributeNamesRequired() {
    int numberOfAttributes = GrouperUtil.intValue(this.getSuffixToConfigValue().get("numberOfEntityAttributes"), 0);
    if (numberOfAttributes > 0) {

      String scimType = this.getSuffixToConfigValue().get("scimType");
      if (StringUtils.equals("Github", scimType)) {
        return GrouperUtil.toSet("id", "userName", "familyName", "givenName");
      } else if (StringUtils.equals("AWS", scimType)) {
        return GrouperUtil.toSet("id", "userName", "displayName", "familyName", "givenName");
      } 
    }
    return null;
  }

  @Override
  public boolean validateEntityAttributesRequireString() {
    return true;
  }

  
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy