Search in sources :

Example 1 with Permissions

use of ddf.security.permission.Permissions in project ddf by codice.

the class ResourceUriPolicy method processPreUpdate.

@Override
public PolicyResponse processPreUpdate(Metacard input, Map<String, Serializable> properties) throws StopProcessingException {
    if (!Requests.isLocal(properties)) {
        return new PolicyResponseImpl();
    }
    PolicyResponseImpl policyResponse = new PolicyResponseImpl(null, Permissions.parsePermissionsFromString(getUpdatePermissions()));
    List<Metacard> previousStateMetacards = ((OperationTransaction) properties.get(OPERATION_TRANSACTION_KEY)).getPreviousStateMetacards();
    Metacard previous;
    try {
        previous = previousStateMetacards.stream().filter((x) -> x.getId().equals(input.getId())).findFirst().get();
    } catch (NoSuchElementException e) {
        LOGGER.debug("Cannot locate metacard {} for update. Applying permissions to the item", input.getId());
        return policyResponse;
    }
    return requiresPermission(input.getResourceURI(), previous.getResourceURI()) ? policyResponse : 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) StopProcessingException(ddf.catalog.plugin.StopProcessingException) OperationTransaction(ddf.catalog.operation.OperationTransaction) OPERATION_TRANSACTION_KEY(ddf.catalog.Constants.OPERATION_TRANSACTION_KEY) StringUtils(org.apache.commons.lang3.StringUtils) Serializable(java.io.Serializable) Query(ddf.catalog.operation.Query) List(java.util.List) Permissions(ddf.security.permission.Permissions) Requests(ddf.catalog.util.impl.Requests) Metacard(ddf.catalog.data.Metacard) Map(java.util.Map) ResourceRequest(ddf.catalog.operation.ResourceRequest) URI(java.net.URI) NoSuchElementException(java.util.NoSuchElementException) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) PolicyResponseImpl(ddf.catalog.plugin.impl.PolicyResponseImpl) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

OPERATION_TRANSACTION_KEY (ddf.catalog.Constants.OPERATION_TRANSACTION_KEY)1 Metacard (ddf.catalog.data.Metacard)1 Result (ddf.catalog.data.Result)1 OperationTransaction (ddf.catalog.operation.OperationTransaction)1 Query (ddf.catalog.operation.Query)1 ResourceRequest (ddf.catalog.operation.ResourceRequest)1 ResourceResponse (ddf.catalog.operation.ResourceResponse)1 PolicyPlugin (ddf.catalog.plugin.PolicyPlugin)1 PolicyResponse (ddf.catalog.plugin.PolicyResponse)1 StopProcessingException (ddf.catalog.plugin.StopProcessingException)1 PolicyResponseImpl (ddf.catalog.plugin.impl.PolicyResponseImpl)1 Requests (ddf.catalog.util.impl.Requests)1 Permissions (ddf.security.permission.Permissions)1 Serializable (java.io.Serializable)1 URI (java.net.URI)1 List (java.util.List)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Logger (org.slf4j.Logger)1