Search in sources :

Example 1 with ListField

use of org.codice.ddf.admin.api.fields.ListField 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

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