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);
}
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;
}
};
}
Aggregations