Search in sources :

Example 16 with StopProcessingException

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

the class SendEvent method sendEvent.

private void sendEvent(String operation, Metacard... metacards) {
    if (subject == null) {
        return;
    }
    try {
        List<Result> results = Arrays.asList(metacards).stream().map(ResultImpl::new).collect(Collectors.toList());
        QueryResponse queryResponse = new QueryResponseImpl(query, results, true, metacards.length);
        CswRecordCollection recordCollection = new CswRecordCollection();
        recordCollection.setElementName(elementName);
        recordCollection.setElementSetType(elementSetType);
        recordCollection.setById(false);
        recordCollection.setRequest(request);
        recordCollection.setResultType(resultType);
        recordCollection.setDoWriteNamespaces(false);
        recordCollection.setMimeType(mimeType);
        recordCollection.setOutputSchema(outputSchema);
        queryResponse.getRequest().getProperties().put(SecurityConstants.SECURITY_SUBJECT, subject);
        for (AccessPlugin plugin : getAccessPlugins()) {
            queryResponse = plugin.processPostQuery(queryResponse);
        }
        if (queryResponse.getResults().isEmpty()) {
            return;
        }
        recordCollection.setSourceResponse(queryResponse);
        send(operation, recordCollection);
    } catch (StopProcessingException | InvalidSyntaxException e) {
        LOGGER.debug("Unable to send event error running AccessPlugin processPostQuery. ", e);
    }
}
Also used : QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) AccessPlugin(ddf.catalog.plugin.AccessPlugin) QueryResponse(ddf.catalog.operation.QueryResponse) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) StopProcessingException(ddf.catalog.plugin.StopProcessingException) Result(ddf.catalog.data.Result)

Example 17 with StopProcessingException

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

the class GeoCoderPlugin method process.

@Override
public CreateRequest process(CreateRequest input) throws PluginExecutionException, StopProcessingException {
    if (input.getMetacards() == null) {
        return input;
    }
    try {
        GeoCoder geoCoder = geoCoderFactory.getService();
        input.getMetacards().forEach(metacard -> setCountryCode(metacard, geoCoder));
    } catch (Exception e) {
        throw new PluginExecutionException("Unable to determine country code for data", e);
    }
    return input;
}
Also used : GeoCoder(org.codice.ddf.spatial.geocoder.GeoCoder) StopProcessingException(ddf.catalog.plugin.StopProcessingException) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException)

Example 18 with StopProcessingException

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

the class OperationPlugin method checkOperation.

/**
 * checkOperation will throw a StopProcessingException if the operation is not permitted based on
 * the the subjects attributes and the operations property "operation.security"
 *
 * @param operation The operation to check
 * @throws StopProcessingException
 */
private void checkOperation(Operation operation) throws StopProcessingException {
    if (!operation.hasProperties() || !operation.containsPropertyName(PolicyPlugin.OPERATION_SECURITY)) {
        return;
    }
    Object securityAssertion = operation.getPropertyValue(SecurityConstants.SECURITY_SUBJECT);
    Subject subject;
    if (securityAssertion instanceof Subject) {
        subject = (Subject) securityAssertion;
    } else {
        throw new StopProcessingException("Unable to filter contents of current message, no user Subject available.");
    }
    Map<String, Set<String>> perms = (Map<String, Set<String>>) operation.getPropertyValue(PolicyPlugin.OPERATION_SECURITY);
    KeyValueCollectionPermission securityPermission = permissions.buildKeyValueCollectionPermission(CollectionPermission.READ_ACTION, perms);
    if (!subject.isPermitted(securityPermission)) {
        String userName = "UNKNOWN";
        if (subjectOperations != null) {
            userName = subjectOperations.getName(subject, userName);
        }
        throw new StopProcessingException("User " + userName + " does not have the required attributes " + perms);
    }
}
Also used : KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) Set(java.util.Set) StopProcessingException(ddf.catalog.plugin.StopProcessingException) Map(java.util.Map) Subject(ddf.security.Subject)

Example 19 with StopProcessingException

use of ddf.catalog.plugin.StopProcessingException 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;
    previous = previousStateMetacards.stream().filter(x -> x.getId().equals(newMetacard.getId())).findFirst().orElse(null);
    return pointOfContactChanged(newMetacard, previous) ? new PolicyResponseImpl(null, permissionMap) : 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) Set(java.util.Set) OperationTransaction(ddf.catalog.operation.OperationTransaction) OPERATION_TRANSACTION_KEY(ddf.catalog.Constants.OPERATION_TRANSACTION_KEY) Serializable(java.io.Serializable) Query(ddf.catalog.operation.Query) Permissions(ddf.security.permission.Permissions) List(java.util.List) Attribute(ddf.catalog.data.Attribute) Metacard(ddf.catalog.data.Metacard) ResourceRequest(ddf.catalog.operation.ResourceRequest) Map(java.util.Map) Result(ddf.catalog.data.Result) Nullable(javax.annotation.Nullable) Metacard(ddf.catalog.data.Metacard) PolicyResponseImpl(ddf.catalog.plugin.impl.PolicyResponseImpl)

Example 20 with StopProcessingException

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

the class FilterPluginTest method testPluginFilterNoStrategies.

@Test
public void testPluginFilterNoStrategies() {
    plugin = new FilterPlugin(new Security());
    plugin.setPermissions(new PermissionsImpl());
    plugin.setSubjectOperations(new SubjectUtils());
    plugin.setSecurityLogger(mock(SecurityLogger.class));
    try {
        QueryResponse response = plugin.processPostQuery(incomingResponse);
        verifyFilterResponse(response);
    } catch (StopProcessingException e) {
        LOGGER.error("Stopped processing the redaction plugin", e);
    }
}
Also used : SubjectUtils(ddf.security.service.impl.SubjectUtils) FilterPlugin(ddf.catalog.security.filter.plugin.FilterPlugin) PermissionsImpl(ddf.security.permission.impl.PermissionsImpl) QueryResponse(ddf.catalog.operation.QueryResponse) StopProcessingException(ddf.catalog.plugin.StopProcessingException) Security(org.codice.ddf.security.impl.Security) SecurityLogger(ddf.security.audit.SecurityLogger) Test(org.junit.Test)

Aggregations

StopProcessingException (ddf.catalog.plugin.StopProcessingException)38 QueryResponse (ddf.catalog.operation.QueryResponse)11 Metacard (ddf.catalog.data.Metacard)10 PluginExecutionException (ddf.catalog.plugin.PluginExecutionException)10 QueryRequest (ddf.catalog.operation.QueryRequest)9 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)8 Attribute (ddf.catalog.data.Attribute)7 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)7 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)7 Serializable (java.io.Serializable)7 HashMap (java.util.HashMap)7 Result (ddf.catalog.data.Result)6 Query (ddf.catalog.operation.Query)6 PreFederatedQueryPlugin (ddf.catalog.plugin.PreFederatedQueryPlugin)6 Source (ddf.catalog.source.Source)6 Map (java.util.Map)6 Subject (org.apache.shiro.subject.Subject)6 KeyValueCollectionPermission (ddf.security.permission.KeyValueCollectionPermission)5 List (java.util.List)5