Search in sources :

Example 1 with PolicyManager

use of org.codice.ddf.security.policy.context.impl.PolicyManager in project ddf by codice.

the class PolicyManagerTest method setup.

@Before
public void setup() {
    manager = new PolicyManager();
    manager.setTraversalDepth(10);
    manager.setContextPolicy("/", new Policy("/", null, new ArrayList<>(), null));
    manager.setContextPolicy("/search", new Policy("/search", null, new ArrayList<>(), null));
    manager.setContextPolicy("/admin", new Policy("/admin", null, new ArrayList<>(), null));
    manager.setContextPolicy("/search/standard", new Policy("/search/standard", null, new ArrayList<>(), null));
    manager.setContextPolicy("/search/cometd", new Policy("/search/cometd", null, new ArrayList<>(), null));
    manager.setContextPolicy("/search/simple", new Policy("/search/simple", null, new ArrayList<>(), null));
    manager.setContextPolicy("/aaaaaa", new Policy("/aaaaaa", null, new ArrayList<>(), null));
    manager.setContextPolicy("/aaa", new Policy("/aaa", null, new ArrayList<>(), null));
    manager.setContextPolicy("/aaa/aaa", new Policy("/aaa/aaa", null, new ArrayList<>(), null));
    manager.setContextPolicy("/foo/bar", new Policy("/foo/bar", null, new ArrayList<>(), null));
    manager.setContextPolicy("/1/2", new Policy("/1/2", null, new ArrayList<>(), null));
    manager.setContextPolicy("/1/2/3/4/5/6/7/8/9/10/11/12/13/14", new Policy("/1/2/3/4/5/6/7/8/9/10/11/12/13/14", null, new ArrayList<>(), null));
    for (Map.Entry<String, List<ContextAttributeMapping>> entry : simpleAttributeMap.entrySet()) {
        manager.setContextPolicy(entry.getKey(), new Policy(entry.getKey(), null, new ArrayList<>(), entry.getValue()));
    }
    for (Map.Entry<String, List<ContextAttributeMapping>> entry : complexAttributeMap.entrySet()) {
        manager.setContextPolicy(entry.getKey(), new Policy(entry.getKey(), null, new ArrayList<>(), entry.getValue()));
    }
    // Can't use Collections.singletonList because the context policy manager must be able to change the passed in list
    manager.setWhiteListContexts(Arrays.asList("/foo"));
    Map<String, Object> contextPolicies = new HashMap<>();
    contextPolicies.put(REALMS, rollBackRealmValues);
    contextPolicies.put(AUTH_TYPES, rollBackAuthTypesValues);
    contextPolicies.put(REQ_ATTRS, rollBackReqAttrValues);
    rollBackTestManager = new PolicyManager();
    rollBackTestManager.setPolicies(contextPolicies);
}
Also used : ContextPolicy(org.codice.ddf.security.policy.context.ContextPolicy) Policy(org.codice.ddf.security.policy.context.impl.Policy) PolicyManager(org.codice.ddf.security.policy.context.impl.PolicyManager) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) Before(org.junit.Before)

Example 2 with PolicyManager

use of org.codice.ddf.security.policy.context.impl.PolicyManager in project ddf by codice.

the class SecurityPolicyConfigurator method createChecker.

private Callable<Boolean> createChecker(final Map<String, Object> policyProperties) {
    final ContextPolicyManager ctxPolicyMgr = services.getService(ContextPolicyManager.class);
    final PolicyManager targetPolicies = new PolicyManager();
    targetPolicies.setPolicies(policyProperties);
    return new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            for (ContextPolicy policy : ctxPolicyMgr.getAllContextPolicies()) {
                ContextPolicy targetPolicy = targetPolicies.getContextPolicy(policy.getContextPath());
                if (targetPolicy == null || !targetPolicy.getContextPath().equals(policy.getContextPath()) || (targetPolicy.getRealm() != null && !targetPolicy.getRealm().equals(policy.getRealm())) || !targetPolicy.getAuthenticationMethods().containsAll(policy.getAuthenticationMethods()) || !targetPolicy.getAllowedAttributeNames().containsAll(policy.getAllowedAttributeNames())) {
                    return false;
                }
            }
            return true;
        }
    };
}
Also used : PolicyManager(org.codice.ddf.security.policy.context.impl.PolicyManager) ContextPolicyManager(org.codice.ddf.security.policy.context.ContextPolicyManager) Callable(java.util.concurrent.Callable) 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)2 PolicyManager (org.codice.ddf.security.policy.context.impl.PolicyManager)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 ContextPolicyManager (org.codice.ddf.security.policy.context.ContextPolicyManager)1 Policy (org.codice.ddf.security.policy.context.impl.Policy)1 Before (org.junit.Before)1