use of org.codice.ddf.security.policy.context.ContextPolicy in project ddf by codice.
the class PolicyManager method setPolicyStore.
private void setPolicyStore(Map<String, List<String>> allContextsToAuths, Map<String, List<ContextAttributeMapping>> allContextsToAttrs) {
// add default context values if they do not exist
if (allContextsToAttrs.get(ROOT_CONTEXT) == null) {
allContextsToAttrs.put(ROOT_CONTEXT, new ArrayList<>());
}
if (allContextsToAuths.get(ROOT_CONTEXT) == null) {
allContextsToAuths.put(ROOT_CONTEXT, new ArrayList<>());
}
// gather all given context paths
Set<String> allContextPaths = new HashSet<>();
allContextPaths.addAll(allContextsToAuths.keySet());
allContextPaths.addAll(allContextsToAttrs.keySet());
Map<String, ContextPolicy> newPolicyStore = new HashMap<>();
newPolicyStore.put(ROOT_CONTEXT, defaultPolicy);
// resolve all authorization types & required attributes
for (String path : allContextPaths) {
List<String> contextAuthTypes = getContextAuthTypes(path, allContextsToAuths);
List<ContextAttributeMapping> contextReqAttrs = getContextReqAttrs(path, allContextsToAttrs);
newPolicyStore.put(path, new Policy(path, contextAuthTypes, contextReqAttrs));
}
policyStore = newPolicyStore;
}
use of org.codice.ddf.security.policy.context.ContextPolicy in project ddf by codice.
the class PolicyManager method copyContextPolicy.
/**
* Duplicates the given context policy
*
* @param contextPolicy
* @return copy of contextPolicy
*/
public ContextPolicy copyContextPolicy(ContextPolicy contextPolicy) {
Collection<ContextAttributeMapping> copiedContextAttributes = new ArrayList<>();
Collection<String> copiedAuthenticationMethods = new ArrayList<>();
copiedAuthenticationMethods.addAll(contextPolicy.getAuthenticationMethods());
copiedContextAttributes.addAll(contextPolicy.getAllowedAttributes().stream().map(contextAttribute -> new DefaultContextAttributeMapping(contextAttribute.getContext(), contextAttribute.getAttributeName(), contextAttribute.getAttributeValue())).collect(Collectors.toList()));
return new Policy(contextPolicy.getContextPath(), copiedAuthenticationMethods, copiedContextAttributes);
}
use of org.codice.ddf.security.policy.context.ContextPolicy 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;
}
use of org.codice.ddf.security.policy.context.ContextPolicy in project ddf by codice.
the class TestStsRealm method testCreateClaimsElement.
@Test
public void testCreateClaimsElement() {
StsRealm stsRealm = new StsRealm();
stsRealm.setClaims(Arrays.asList("claim1", "claim2", "claim3"));
ContextPolicyManager contextPolicyManager = mock(ContextPolicyManager.class);
ContextPolicy policy1 = mock(ContextPolicy.class);
ContextPolicy policy2 = mock(ContextPolicy.class);
when(policy1.getAllowedAttributeNames()).thenReturn(Arrays.asList("claim4", "claim5"));
when(policy2.getAllowedAttributeNames()).thenReturn(Arrays.asList("claim6", "claim7"));
when(contextPolicyManager.getAllContextPolicies()).thenReturn(Arrays.asList(policy1, policy2));
stsRealm.setContextPolicyManager(contextPolicyManager);
Element claimsElement = stsRealm.createClaimsElement();
assertNotNull(claimsElement);
NodeList childNodes = claimsElement.getChildNodes();
assertEquals("claim1", childNodes.item(0).getAttributes().item(1).getTextContent());
assertEquals("claim2", childNodes.item(1).getAttributes().item(1).getTextContent());
assertEquals("claim3", childNodes.item(2).getAttributes().item(1).getTextContent());
assertEquals("claim4", childNodes.item(3).getAttributes().item(1).getTextContent());
assertEquals("claim5", childNodes.item(4).getAttributes().item(1).getTextContent());
assertEquals("claim6", childNodes.item(5).getAttributes().item(1).getTextContent());
assertEquals("claim7", childNodes.item(6).getAttributes().item(1).getTextContent());
}
use of org.codice.ddf.security.policy.context.ContextPolicy in project ddf by codice.
the class AuthenticationEndpointTest method testUnauthorized.
@Test(expected = SecurityServiceException.class)
public void testUnauthorized() throws SecurityServiceException {
HttpServletRequest request = mock(HttpServletRequest.class);
when(request.isSecure()).thenReturn(true);
ContextPolicy policy = mock(ContextPolicy.class);
when(policy.getRealm()).thenReturn(REALM);
when(policyManager.getContextPolicy(PATH)).thenReturn(policy);
authEndpoint.login(request, "bad", "bad", PATH);
}
Aggregations