Search in sources :

Example 6 with PolicyResponse

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

the class MetacardValidityFilterPluginTest method testValidMetacards.

@Test
public void testValidMetacards() throws Exception {
    Result result = mock(Result.class);
    PolicyResponse response = filterPluginResponseHelper(result, getValidMetacard(), true, false);
    assertThat(response.itemPolicy().size(), is(0));
}
Also used : PolicyResponse(ddf.catalog.plugin.PolicyResponse) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 7 with PolicyResponse

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

the class ResourceOperations method processPostResourcePolicyPlugins.

private ResourceResponse processPostResourcePolicyPlugins(ResourceResponse resourceResponse, Metacard metacard) throws StopProcessingException {
    HashMap<String, Set<String>> responsePolicyMap = new HashMap<>();
    for (PolicyPlugin plugin : frameworkProperties.getPolicyPlugins()) {
        PolicyResponse policyResponse = plugin.processPostResource(resourceResponse, metacard);
        opsSecuritySupport.buildPolicyMap(responsePolicyMap, policyResponse.operationPolicy().entrySet());
    }
    resourceResponse.getProperties().put(PolicyPlugin.OPERATION_SECURITY, responsePolicyMap);
    return resourceResponse;
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) PolicyPlugin(ddf.catalog.plugin.PolicyPlugin) PolicyResponse(ddf.catalog.plugin.PolicyResponse)

Example 8 with PolicyResponse

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

the class DeleteOperations method populateDeleteRequestPolicyMap.

private DeleteRequest populateDeleteRequestPolicyMap(DeleteRequest deleteRequest, DeleteResponse deleteResponse) throws StopProcessingException {
    HashMap<String, Set<String>> responsePolicyMap = new HashMap<>();
    Map<String, Serializable> unmodifiableProperties = Collections.unmodifiableMap(deleteRequest.getProperties());
    if (deleteResponse != null && deleteResponse.getDeletedMetacards() != null) {
        for (Metacard metacard : deleteResponse.getDeletedMetacards()) {
            HashMap<String, Set<String>> itemPolicyMap = new HashMap<>();
            for (PolicyPlugin plugin : frameworkProperties.getPolicyPlugins()) {
                PolicyResponse policyResponse = plugin.processPostDelete(metacard, unmodifiableProperties);
                opsSecuritySupport.buildPolicyMap(itemPolicyMap, policyResponse.itemPolicy().entrySet());
                opsSecuritySupport.buildPolicyMap(responsePolicyMap, policyResponse.operationPolicy().entrySet());
            }
            metacard.setAttribute(new AttributeImpl(Metacard.SECURITY, itemPolicyMap));
        }
    }
    deleteRequest.getProperties().put(PolicyPlugin.OPERATION_SECURITY, responsePolicyMap);
    return deleteRequest;
}
Also used : Serializable(java.io.Serializable) Metacard(ddf.catalog.data.Metacard) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) PolicyPlugin(ddf.catalog.plugin.PolicyPlugin) PolicyResponse(ddf.catalog.plugin.PolicyResponse)

Example 9 with PolicyResponse

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

the class PointOfContactPolicyPlugin method processPreUpdate.

@Override
public PolicyResponse processPreUpdate(Metacard newMetacard, Map<String, Serializable> properties) throws StopProcessingException {
    //If it's not a resource metacard, don't apply the policy.
    if (!newMetacard.getTags().isEmpty() && !newMetacard.getTags().contains("resource")) {
        return new PolicyResponseImpl();
    }
    List<Metacard> previousStateMetacards = ((OperationTransaction) properties.get(OPERATION_TRANSACTION_KEY)).getPreviousStateMetacards();
    Metacard previous;
    try {
        previous = previousStateMetacards.stream().filter((x) -> x.getId().equals(newMetacard.getId())).findFirst().get();
    } catch (NoSuchElementException e) {
        LOGGER.debug("Cannot locate metacard {} for update.", newMetacard.getId());
        return new PolicyResponseImpl();
    }
    return pointOfContactChanged(newMetacard, previous) ? new PolicyResponseImpl(null, PERMISSION_MAP) : new PolicyResponseImpl();
}
Also used : OperationTransaction(ddf.catalog.operation.OperationTransaction) ResourceResponse(ddf.catalog.operation.ResourceResponse) PolicyResponse(ddf.catalog.plugin.PolicyResponse) Logger(org.slf4j.Logger) PolicyPlugin(ddf.catalog.plugin.PolicyPlugin) PolicyResponseImpl(ddf.catalog.plugin.impl.PolicyResponseImpl) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) StopProcessingException(ddf.catalog.plugin.StopProcessingException) OperationTransaction(ddf.catalog.operation.OperationTransaction) OPERATION_TRANSACTION_KEY(ddf.catalog.Constants.OPERATION_TRANSACTION_KEY) Serializable(java.io.Serializable) Query(ddf.catalog.operation.Query) List(java.util.List) Permissions(ddf.security.permission.Permissions) Attribute(ddf.catalog.data.Attribute) Metacard(ddf.catalog.data.Metacard) Map(java.util.Map) ResourceRequest(ddf.catalog.operation.ResourceRequest) NoSuchElementException(java.util.NoSuchElementException) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) PolicyResponseImpl(ddf.catalog.plugin.impl.PolicyResponseImpl) NoSuchElementException(java.util.NoSuchElementException)

Example 10 with PolicyResponse

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

the class PointOfContactPolicyPluginTest method processPostDeleteDoesNothing.

@Test
public void processPostDeleteDoesNothing() throws java.lang.Exception {
    PolicyResponse response = pointOfContactPolicyPlugin.processPostDelete(new MetacardImpl(), Collections.emptyMap());
    responseIsEmpty(response);
}
Also used : 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