Search in sources :

Example 11 with ContextPolicyManager

use of org.codice.ddf.security.policy.context.ContextPolicyManager in project admin-console-beta by connexta.

the class PolicyManagerServiceProperties method contextPolicyServiceToContextPolicyFields.

public ContextPolicyBin.ListImpl contextPolicyServiceToContextPolicyFields(ServiceReader serviceReader) {
    ContextPolicyManager policyManager = serviceReader.getServiceReference(ContextPolicyManager.class);
    List<ContextPolicyBin> policies = new ArrayList<>();
    Collection<ContextPolicy> allPolicies = policyManager.getAllContextPolicies();
    for (ContextPolicy policy : allPolicies) {
        Map<String, String> policyRequiredAttributes = policy.getAllowedAttributes().stream().collect(Collectors.toMap(ContextAttributeMapping::getAttributeName, ContextAttributeMapping::getAttributeValue));
        policies.add(new ContextPolicyBin(serviceReader).addClaimsMap(policyRequiredAttributes).authTypes(policy.getAuthenticationMethods()).addContextPath(policy.getContextPath()));
    }
    // Check if bin containing an identical context policy exists already, if so add the context
    // path to it
    // Do this after pulling the configuration so that values are matched to their appropriate enums
    List<ContextPolicyBin> collapsedBins = new ArrayList<>();
    for (ContextPolicyBin bin : policies) {
        boolean foundBin = false;
        for (ContextPolicyBin collapsedBin : collapsedBins) {
            if (ListUtils.isEqualList(bin.authTypes(), collapsedBin.authTypes()) && bin.claimsMapping().equals(collapsedBin.claimsMapping())) {
                for (ContextPath contextPath : bin.contextFields().getList()) {
                    collapsedBin.addContextPath(contextPath);
                }
                foundBin = true;
                break;
            }
        }
        if (!foundBin) {
            collapsedBins.add(bin);
        }
    }
    return new ContextPolicyBin.ListImpl(serviceReader).addAll(collapsedBins);
}
Also used : ContextPath(org.codice.ddf.admin.common.fields.common.ContextPath) 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

ContextPolicy (org.codice.ddf.security.policy.context.ContextPolicy)11 ContextPolicyManager (org.codice.ddf.security.policy.context.ContextPolicyManager)11 Test (org.junit.Test)8 FilterChain (javax.servlet.FilterChain)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 Collection (java.util.Collection)5 Map (java.util.Map)5 SecurityConstants (ddf.security.SecurityConstants)4 Subject (ddf.security.Subject)4 CollectionPermission (ddf.security.permission.CollectionPermission)4 KeyValuePermission (ddf.security.permission.KeyValuePermission)4 IOException (java.io.IOException)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 FilterConfig (javax.servlet.FilterConfig)4 ServletException (javax.servlet.ServletException)4 ThreadContext (org.apache.shiro.util.ThreadContext)4 Assert.fail (org.junit.Assert.fail)4 Before (org.junit.Before)4