Search in sources :

Example 1 with PolicyResponseImpl

use of ddf.catalog.plugin.impl.PolicyResponseImpl in project ddf by codice.

the class MetacardValidityFilterPlugin method processPostQuery.

@Override
public PolicyResponse processPostQuery(Result input, Map<String, Serializable> properties) throws StopProcessingException {
    if (input == null || input.getMetacard() == null) {
        return new PolicyResponseImpl();
    }
    Metacard metacard = input.getMetacard();
    HashMap<String, Set<String>> securityMap = new HashMap<>();
    if (isMarkedForFilter(filterErrors, metacard, Validation.VALIDATION_ERRORS) || isMarkedForFilter(filterWarnings, metacard, Validation.VALIDATION_WARNINGS)) {
        for (Map.Entry<String, List<String>> attributeMapping : attributeMap.entrySet()) {
            securityMap.put(attributeMapping.getKey(), new HashSet<>(attributeMapping.getValue()));
        }
    }
    return new PolicyResponseImpl(new HashMap<>(), securityMap);
}
Also used : Metacard(ddf.catalog.data.Metacard) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) List(java.util.List) PolicyResponseImpl(ddf.catalog.plugin.impl.PolicyResponseImpl) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with PolicyResponseImpl

use of ddf.catalog.plugin.impl.PolicyResponseImpl in project ddf by codice.

the class RegistryPolicyPlugin method getWritePolicy.

private PolicyResponse getWritePolicy(Metacard input, Map<String, Serializable> properties, Map<String, Set<String>> policy) {
    Map<String, Set<String>> operationPolicy = new HashMap<>();
    Map<String, Set<String>> securityAttributes = new HashMap<>();
    if (Requests.isLocal(properties) && input != null && (RegistryUtility.isInternalRegistryMetacard(input) || RegistryUtility.isRegistryMetacard(input))) {
        Attribute securityAttribute = input.getAttribute(RegistryObjectMetacardType.SECURITY_LEVEL);
        if (securityAttribute != null) {
            securityAttributes.putAll(Permissions.parsePermissionsFromString(securityAttribute.getValues().stream().map(Object::toString).collect(Collectors.toList())));
        }
        String registryBaseUrl = RegistryUtility.getStringAttribute(input, RegistryObjectMetacardType.REGISTRY_BASE_URL, null);
        if (isRegistryDisabled() || (registryBaseUrl != null && registryBaseUrl.startsWith(SystemBaseUrl.getBaseUrl()))) {
            operationPolicy.putAll(bypassAccessPolicy);
        } else {
            operationPolicy.putAll(policy);
        }
    }
    if (securityAttributes.isEmpty()) {
        return new PolicyResponseImpl(operationPolicy, operationPolicy);
    } else {
        return new PolicyResponseImpl(operationPolicy, securityAttributes);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Attribute(ddf.catalog.data.Attribute) PolicyResponseImpl(ddf.catalog.plugin.impl.PolicyResponseImpl)

Example 3 with PolicyResponseImpl

use of ddf.catalog.plugin.impl.PolicyResponseImpl 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 4 with PolicyResponseImpl

use of ddf.catalog.plugin.impl.PolicyResponseImpl 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)

Example 5 with PolicyResponseImpl

use of ddf.catalog.plugin.impl.PolicyResponseImpl in project ddf by codice.

the class FilterPostQueryPlugin method processPostQuery.

@Override
public PolicyResponse processPostQuery(Result input, Map<String, Serializable> properties) throws StopProcessingException {
    HashMap<String, Set<String>> securityFinalMap = new HashMap<>();
    securityFinalMap.put(Metacard.POINT_OF_CONTACT, new HashSet(Arrays.asList("admin")));
    return new PolicyResponseImpl(new HashMap<>(), securityFinalMap);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) PolicyResponseImpl(ddf.catalog.plugin.impl.PolicyResponseImpl) HashSet(java.util.HashSet)

Aggregations

PolicyResponseImpl (ddf.catalog.plugin.impl.PolicyResponseImpl)6 Set (java.util.Set)5 Metacard (ddf.catalog.data.Metacard)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 List (java.util.List)3 Map (java.util.Map)3 OPERATION_TRANSACTION_KEY (ddf.catalog.Constants.OPERATION_TRANSACTION_KEY)2 Attribute (ddf.catalog.data.Attribute)2 Result (ddf.catalog.data.Result)2 OperationTransaction (ddf.catalog.operation.OperationTransaction)2 Query (ddf.catalog.operation.Query)2 ResourceRequest (ddf.catalog.operation.ResourceRequest)2 ResourceResponse (ddf.catalog.operation.ResourceResponse)2 PolicyPlugin (ddf.catalog.plugin.PolicyPlugin)2 PolicyResponse (ddf.catalog.plugin.PolicyResponse)2 StopProcessingException (ddf.catalog.plugin.StopProcessingException)2 Permissions (ddf.security.permission.Permissions)2 Serializable (java.io.Serializable)2 NoSuchElementException (java.util.NoSuchElementException)2