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