use of org.codice.ddf.security.policy.context.attributes.ContextAttributeMapping in project ddf by codice.
the class PolicyManager method setContextPolicy.
@Override
public void setContextPolicy(String path, ContextPolicy newContextPolicy) {
if (path == null) {
throw new IllegalArgumentException("Context path cannot be null.");
}
if (!path.startsWith("/")) {
throw new IllegalArgumentException("Context path must start with /");
}
if (newContextPolicy == null) {
throw new IllegalArgumentException("Context policy cannot be null.");
}
LOGGER.debug("setContextPolicy called with path = {}", path);
//gather all context realms, authorization types, & required attributes
Map<String, String> contextsToRealms = new HashMap<String, String>();
Map<String, List<ContextAttributeMapping>> contextsToAttrs = new HashMap<>();
Map<String, List<String>> contextsToAuths = new HashMap<>();
for (ContextPolicy contextPolicy : getPolicyStore().values()) {
contextsToRealms.put(contextPolicy.getContextPath(), contextPolicy.getRealm());
contextsToAttrs.put(contextPolicy.getContextPath(), new ArrayList<>(contextPolicy.getAllowedAttributes()));
contextsToAuths.put(contextPolicy.getContextPath(), new ArrayList<>(contextPolicy.getAuthenticationMethods()));
}
//duplicate and add the new context policy
String newContextRealm = newContextPolicy.getRealm();
List<ContextAttributeMapping> newContextAttrs = newContextPolicy.getAllowedAttributes().stream().map(contextAttribute -> new DefaultContextAttributeMapping(contextAttribute.getContext(), contextAttribute.getAttributeName(), contextAttribute.getAttributeValue())).collect(Collectors.toList());
Collection<String> newContextAuths = new ArrayList<>();
newContextAuths.addAll(newContextPolicy.getAuthenticationMethods());
if (StringUtils.isNotEmpty(newContextRealm)) {
contextsToRealms.put(path, newContextRealm);
}
if (newContextAttrs != null) {
contextsToAttrs.put(path, new ArrayList<>(newContextAttrs));
}
contextsToAuths.put(path, new ArrayList<>(newContextAuths));
setPolicyStore(contextsToRealms, contextsToAuths, contextsToAttrs);
}
Aggregations