Search in sources :

Example 56 with PolicyResponse

use of ddf.catalog.plugin.PolicyResponse in project ddf by codice.

the class QueryOperations method populateQueryRequestPolicyMap.

private QueryRequest populateQueryRequestPolicyMap(QueryRequest queryReq) throws FederationException {
    HashMap<String, Set<String>> requestPolicyMap = new HashMap<>();
    Map<String, Serializable> unmodifiableProperties = Collections.unmodifiableMap(queryReq.getProperties());
    for (PolicyPlugin plugin : frameworkProperties.getPolicyPlugins()) {
        try {
            PolicyResponse policyResponse = plugin.processPreQuery(queryReq.getQuery(), unmodifiableProperties);
            opsSecuritySupport.buildPolicyMap(requestPolicyMap, policyResponse.operationPolicy().entrySet());
        } catch (StopProcessingException e) {
            throw new FederationException("Query could not be executed.", e);
        }
    }
    queryReq.getProperties().put(PolicyPlugin.OPERATION_SECURITY, requestPolicyMap);
    return queryReq;
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) PolicyPlugin(ddf.catalog.plugin.PolicyPlugin) StopProcessingException(ddf.catalog.plugin.StopProcessingException) FederationException(ddf.catalog.federation.FederationException) PolicyResponse(ddf.catalog.plugin.PolicyResponse)

Example 57 with PolicyResponse

use of ddf.catalog.plugin.PolicyResponse in project ddf by codice.

the class UpdateOperations method populateUpdateRequestPolicyMap.

private UpdateRequest populateUpdateRequestPolicyMap(UpdateRequest updateRequest) throws StopProcessingException {
    Map<String, Metacard> metacardMap = getUpdateMap(updateRequest);
    HashMap<String, Set<String>> requestPolicyMap = new HashMap<>();
    for (Map.Entry<Serializable, Metacard> update : updateRequest.getUpdates()) {
        HashMap<String, Set<String>> itemPolicyMap = new HashMap<>();
        HashMap<String, Set<String>> oldItemPolicyMap = new HashMap<>();
        Metacard oldMetacard = metacardMap.get(update.getKey().toString());
        for (PolicyPlugin plugin : frameworkProperties.getPolicyPlugins()) {
            PolicyResponse updatePolicyResponse = plugin.processPreUpdate(update.getValue(), Collections.unmodifiableMap(updateRequest.getProperties()));
            PolicyResponse oldPolicyResponse = plugin.processPreUpdate(oldMetacard, Collections.unmodifiableMap(updateRequest.getProperties()));
            opsSecuritySupport.buildPolicyMap(itemPolicyMap, updatePolicyResponse.itemPolicy().entrySet());
            opsSecuritySupport.buildPolicyMap(oldItemPolicyMap, oldPolicyResponse.itemPolicy().entrySet());
            opsSecuritySupport.buildPolicyMap(requestPolicyMap, updatePolicyResponse.operationPolicy().entrySet());
        }
        update.getValue().setAttribute(new AttributeImpl(Metacard.SECURITY, itemPolicyMap));
        if (oldMetacard != null) {
            oldMetacard.setAttribute(new AttributeImpl(Metacard.SECURITY, oldItemPolicyMap));
        }
    }
    updateRequest.getProperties().put(PolicyPlugin.OPERATION_SECURITY, requestPolicyMap);
    return updateRequest;
}
Also used : Metacard(ddf.catalog.data.Metacard) Serializable(java.io.Serializable) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) PolicyPlugin(ddf.catalog.plugin.PolicyPlugin) Map(java.util.Map) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap) PolicyResponse(ddf.catalog.plugin.PolicyResponse)

Example 58 with PolicyResponse

use of ddf.catalog.plugin.PolicyResponse in project ddf by codice.

the class ResourceOperations method processPreResourcePolicyPlugins.

private ResourceRequest processPreResourcePolicyPlugins(ResourceRequest resourceReq) throws StopProcessingException {
    HashMap<String, Set<String>> requestPolicyMap = new HashMap<>();
    for (PolicyPlugin plugin : frameworkProperties.getPolicyPlugins()) {
        PolicyResponse policyResponse = plugin.processPreResource(resourceReq);
        opsSecuritySupport.buildPolicyMap(requestPolicyMap, policyResponse.operationPolicy().entrySet());
    }
    resourceReq.getProperties().put(PolicyPlugin.OPERATION_SECURITY, requestPolicyMap);
    return resourceReq;
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) PolicyPlugin(ddf.catalog.plugin.PolicyPlugin) PolicyResponse(ddf.catalog.plugin.PolicyResponse)

Example 59 with PolicyResponse

use of ddf.catalog.plugin.PolicyResponse in project ddf by codice.

the class PointOfContactPolicyPluginTest method processPreUpdateReturnsPolicyWhenNewPointOfContactIsNull.

@Test
public void processPreUpdateReturnsPolicyWhenNewPointOfContactIsNull() throws java.lang.Exception {
    MetacardImpl oldMetacard = getMetacardWithPointOfContact(TEST_POINT_OF_CONTACT);
    PolicyResponse response = pointOfContactPolicyPlugin.processPreUpdate(getMetacardWithPointOfContact(null), setupAndGetInputProperties(oldMetacard));
    responseHasPolicy(response);
}
Also used : PolicyResponse(ddf.catalog.plugin.PolicyResponse) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 60 with PolicyResponse

use of ddf.catalog.plugin.PolicyResponse in project ddf by codice.

the class PointOfContactPolicyPluginTest method processPostResourceDoesNothing.

@Test
public void processPostResourceDoesNothing() throws java.lang.Exception {
    PolicyResponse response = pointOfContactPolicyPlugin.processPostResource(mock(ResourceResponse.class), new MetacardImpl());
    responseIsEmpty(response);
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) PolicyResponse(ddf.catalog.plugin.PolicyResponse) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Aggregations

PolicyResponse (ddf.catalog.plugin.PolicyResponse)75 Test (org.junit.Test)64 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)20 Metacard (ddf.catalog.data.Metacard)19 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)14 Serializable (java.io.Serializable)14 Set (java.util.Set)14 Result (ddf.catalog.data.Result)13 HashMap (java.util.HashMap)12 PolicyPlugin (ddf.catalog.plugin.PolicyPlugin)10 HashSet (java.util.HashSet)7 ResultImpl (ddf.catalog.data.impl.ResultImpl)6 ResourceResponse (ddf.catalog.operation.ResourceResponse)6 Query (ddf.catalog.operation.Query)5 StopProcessingException (ddf.catalog.plugin.StopProcessingException)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 ResourceRequest (ddf.catalog.operation.ResourceRequest)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 OPERATION_TRANSACTION_KEY (ddf.catalog.Constants.OPERATION_TRANSACTION_KEY)2