Search in sources :

Example 6 with ContextAttributeMapping

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);
}
Also used : Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) Logger(org.slf4j.Logger) ContextPolicy(org.codice.ddf.security.policy.context.ContextPolicy) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) SecurityLogger(ddf.security.common.audit.SecurityLogger) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) PropertyResolver(org.codice.ddf.configuration.PropertyResolver) HashSet(java.util.HashSet) List(java.util.List) DefaultContextAttributeMapping(org.codice.ddf.security.policy.context.attributes.DefaultContextAttributeMapping) Map(java.util.Map) ContextAttributeMapping(org.codice.ddf.security.policy.context.attributes.ContextAttributeMapping) Collections(java.util.Collections) ContextPolicyManager(org.codice.ddf.security.policy.context.ContextPolicyManager) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DefaultContextAttributeMapping(org.codice.ddf.security.policy.context.attributes.DefaultContextAttributeMapping) ContextPolicy(org.codice.ddf.security.policy.context.ContextPolicy) ArrayList(java.util.ArrayList) List(java.util.List) DefaultContextAttributeMapping(org.codice.ddf.security.policy.context.attributes.DefaultContextAttributeMapping) ContextAttributeMapping(org.codice.ddf.security.policy.context.attributes.ContextAttributeMapping)

Aggregations

ContextAttributeMapping (org.codice.ddf.security.policy.context.attributes.ContextAttributeMapping)6 ArrayList (java.util.ArrayList)4 ContextPolicy (org.codice.ddf.security.policy.context.ContextPolicy)4 DefaultContextAttributeMapping (org.codice.ddf.security.policy.context.attributes.DefaultContextAttributeMapping)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)2 List (java.util.List)2 SecurityLogger (ddf.security.common.audit.SecurityLogger)1 KeyValueCollectionPermission (ddf.security.permission.KeyValueCollectionPermission)1 KeyValuePermission (ddf.security.permission.KeyValuePermission)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang.StringUtils)1 PropertyResolver (org.codice.ddf.configuration.PropertyResolver)1 ContextPolicyManager (org.codice.ddf.security.policy.context.ContextPolicyManager)1 Logger (org.slf4j.Logger)1