Search in sources :

Example 1 with ContextPolicyBin

use of org.codice.ddf.admin.security.common.fields.wcpm.ContextPolicyBin in project admin-console-beta by connexta.

the class PolicyManagerServiceProperties method contextPoliciesToPolicyManagerProps.

public Map<String, Object> contextPoliciesToPolicyManagerProps(List<ContextPolicyBin> contextPolicies) {
    List<String> realmsProps = new ArrayList<>();
    List<String> authTypesProps = new ArrayList<>();
    List<String> reqAttrisProps = new ArrayList<>();
    for (ContextPolicyBin bin : contextPolicies) {
        bin.contexts().forEach(context -> {
            realmsProps.add(context + "=" + bin.realm());
            authTypesProps.add(context + "=" + String.join("|", bin.authTypes()));
            if (bin.claimsMapping().isEmpty()) {
                reqAttrisProps.add(context + "=");
            } else {
                reqAttrisProps.add(context + "={" + String.join(";", bin.claimsMapping().entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).collect(Collectors.toList())) + "}");
            }
        });
    }
    return ImmutableMap.of(AUTH_TYPES, authTypesProps.toArray(new String[0]), REALMS, realmsProps.toArray(new String[0]), REQUIRED_ATTRIBUTES, reqAttrisProps.toArray(new String[0]));
}
Also used : ContextPolicy(org.codice.ddf.security.policy.context.ContextPolicy) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ListUtils(org.apache.commons.collections.ListUtils) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ListFieldImpl(org.codice.ddf.admin.common.fields.base.ListFieldImpl) ServiceCommons(org.codice.ddf.admin.common.services.ServiceCommons) ConfigReader(org.codice.ddf.admin.configurator.ConfigReader) List(java.util.List) Map(java.util.Map) ListField(org.codice.ddf.admin.api.fields.ListField) ContextPolicyBin(org.codice.ddf.admin.security.common.fields.wcpm.ContextPolicyBin) ContextPolicyManager(org.codice.ddf.security.policy.context.ContextPolicyManager) ConfiguratorFactory(org.codice.ddf.admin.configurator.ConfiguratorFactory) ContextPath(org.codice.ddf.admin.common.fields.common.ContextPath) ArrayList(java.util.ArrayList) ContextPolicyBin(org.codice.ddf.admin.security.common.fields.wcpm.ContextPolicyBin)

Example 2 with ContextPolicyBin

use of org.codice.ddf.admin.security.common.fields.wcpm.ContextPolicyBin in project admin-console-beta by connexta.

the class SaveContextPolices method checkClaimsValidity.

private void checkClaimsValidity() {
    List<String> supportedClaims = stsServiceProps.getConfiguredStsClaims(configuratorFactory);
    List<StringField> claimArgs = new ArrayList<>();
    for (ContextPolicyBin bin : contextPolicies.getList()) {
        claimArgs.addAll(bin.claimsMappingField().getList().stream().map(entry -> entry.claimField()).collect(Collectors.toList()));
    }
    claimArgs.stream().filter(claimArg -> !supportedClaims.contains(claimArg.getValue())).forEach(claimArg -> addArgumentMessage(invalidClaimType(claimArg.path())));
}
Also used : POLICY_MANAGER_PID(org.codice.ddf.admin.security.common.services.PolicyManagerServiceProperties.POLICY_MANAGER_PID) BaseFunctionField(org.codice.ddf.admin.common.fields.base.BaseFunctionField) SecurityMessages.invalidClaimType(org.codice.ddf.admin.security.common.SecurityMessages.invalidClaimType) Collection(java.util.Collection) StringField(org.codice.ddf.admin.common.fields.base.scalar.StringField) StsServiceProperties(org.codice.ddf.admin.security.common.services.StsServiceProperties) PolicyManagerServiceProperties(org.codice.ddf.admin.security.common.services.PolicyManagerServiceProperties) Configurator(org.codice.ddf.admin.configurator.Configurator) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ListFieldImpl(org.codice.ddf.admin.common.fields.base.ListFieldImpl) List(java.util.List) DefaultMessages.failedPersistError(org.codice.ddf.admin.common.report.message.DefaultMessages.failedPersistError) OperationReport(org.codice.ddf.admin.configurator.OperationReport) ImmutableList(com.google.common.collect.ImmutableList) ROOT_CONTEXT_PATH(org.codice.ddf.admin.security.common.services.PolicyManagerServiceProperties.ROOT_CONTEXT_PATH) ListField(org.codice.ddf.admin.api.fields.ListField) ContextPolicyBin(org.codice.ddf.admin.security.common.fields.wcpm.ContextPolicyBin) FunctionField(org.codice.ddf.admin.api.fields.FunctionField) ConfiguratorFactory(org.codice.ddf.admin.configurator.ConfiguratorFactory) SecurityMessages.noRootContextError(org.codice.ddf.admin.security.common.SecurityMessages.noRootContextError) DataType(org.codice.ddf.admin.api.DataType) StringField(org.codice.ddf.admin.common.fields.base.scalar.StringField) ArrayList(java.util.ArrayList) ContextPolicyBin(org.codice.ddf.admin.security.common.fields.wcpm.ContextPolicyBin)

Example 3 with ContextPolicyBin

use of org.codice.ddf.admin.security.common.fields.wcpm.ContextPolicyBin in project admin-console-beta by connexta.

the class PolicyManagerServiceProperties method contextPolicyServiceToContextPolicyFields.

public ListField<ContextPolicyBin> contextPolicyServiceToContextPolicyFields(ConfiguratorFactory configurator) {
    ContextPolicyManager policyManager = configurator.getConfigReader().getServiceReference(ContextPolicyManager.class);
    List<ContextPolicyBin> policies = new ArrayList<>();
    Collection<ContextPolicy> allPolicies = policyManager.getAllContextPolicies();
    for (ContextPolicy policy : allPolicies) {
        boolean foundBin = false;
        Map<String, String> policyRequiredAttributes = policy.getAllowedAttributes().stream().collect(Collectors.toMap(map -> map.getAttributeName(), map -> map.getAttributeValue()));
        //Check if bin containing an identical context policy exists already, if so add the context path to it
        for (ContextPolicyBin bin : policies) {
            if (bin.realm().equals(policy.getRealm()) && ListUtils.isEqualList(bin.authTypes(), policy.getAuthenticationMethods()) && hasSameRequiredAttributes(bin, policyRequiredAttributes)) {
                bin.addContextPath(policy.getContextPath());
                foundBin = true;
            }
        }
        if (!foundBin) {
            policies.add(new ContextPolicyBin().realm(policy.getRealm()).addClaimsMap(policyRequiredAttributes).authTypes(policy.getAuthenticationMethods()).addContextPath(policy.getContextPath()));
        }
    }
    ListField<ContextPolicyBin> policiesField = new ListFieldImpl<>(ContextPolicyBin.class);
    policiesField.addAll(policies);
    return policiesField;
}
Also used : ContextPolicy(org.codice.ddf.security.policy.context.ContextPolicy) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ListUtils(org.apache.commons.collections.ListUtils) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ListFieldImpl(org.codice.ddf.admin.common.fields.base.ListFieldImpl) ServiceCommons(org.codice.ddf.admin.common.services.ServiceCommons) ConfigReader(org.codice.ddf.admin.configurator.ConfigReader) List(java.util.List) Map(java.util.Map) ListField(org.codice.ddf.admin.api.fields.ListField) ContextPolicyBin(org.codice.ddf.admin.security.common.fields.wcpm.ContextPolicyBin) ContextPolicyManager(org.codice.ddf.security.policy.context.ContextPolicyManager) ConfiguratorFactory(org.codice.ddf.admin.configurator.ConfiguratorFactory) ContextPath(org.codice.ddf.admin.common.fields.common.ContextPath) ListFieldImpl(org.codice.ddf.admin.common.fields.base.ListFieldImpl) ArrayList(java.util.ArrayList) ContextPolicyBin(org.codice.ddf.admin.security.common.fields.wcpm.ContextPolicyBin) ContextPolicy(org.codice.ddf.security.policy.context.ContextPolicy) ContextPolicyManager(org.codice.ddf.security.policy.context.ContextPolicyManager)

Aggregations

ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 ListField (org.codice.ddf.admin.api.fields.ListField)3 ListFieldImpl (org.codice.ddf.admin.common.fields.base.ListFieldImpl)3 ConfiguratorFactory (org.codice.ddf.admin.configurator.ConfiguratorFactory)3 ContextPolicyBin (org.codice.ddf.admin.security.common.fields.wcpm.ContextPolicyBin)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Map (java.util.Map)2 ListUtils (org.apache.commons.collections.ListUtils)2 ContextPath (org.codice.ddf.admin.common.fields.common.ContextPath)2 ServiceCommons (org.codice.ddf.admin.common.services.ServiceCommons)2 ConfigReader (org.codice.ddf.admin.configurator.ConfigReader)2 ContextPolicy (org.codice.ddf.security.policy.context.ContextPolicy)2 ContextPolicyManager (org.codice.ddf.security.policy.context.ContextPolicyManager)2 ImmutableList (com.google.common.collect.ImmutableList)1 DataType (org.codice.ddf.admin.api.DataType)1 FunctionField (org.codice.ddf.admin.api.fields.FunctionField)1 BaseFunctionField (org.codice.ddf.admin.common.fields.base.BaseFunctionField)1