Search in sources :

Example 26 with StopProcessingException

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

the class FilterPlugin method processPostResource.

@Override
public ResourceResponse processPostResource(ResourceResponse input, Metacard metacard) throws StopProcessingException {
    if (input.getRequest() == null || input.getRequest().getProperties() == null) {
        throw new StopProcessingException(UNABLE_TO_FILTER_MSG);
    }
    KeyValueCollectionPermission securityPermission = permissions.buildKeyValueCollectionPermission(CollectionPermission.READ_ACTION);
    Subject subject = getSubject(input);
    Attribute attr = metacard.getAttribute(Metacard.SECURITY);
    if (!checkPermissions(attr, securityPermission, subject, CollectionPermission.READ_ACTION)) {
        for (FilterStrategy filterStrategy : filterStrategies.values()) {
            FilterResult filterResult = filterStrategy.process(input, metacard);
            if (filterResult.processed()) {
                if (filterResult.response() == null) {
                    throw new StopProcessingException("Subject not permitted to receive resource");
                } else {
                    input = (ResourceResponse) filterResult.response();
                }
                break;
            // returned metacards are ignored for resource requests
            }
        }
        if (filterStrategies.isEmpty()) {
            throw new StopProcessingException("Subject not permitted to receive resource");
        }
    }
    return input;
}
Also used : KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) Attribute(ddf.catalog.data.Attribute) FilterStrategy(ddf.catalog.security.FilterStrategy) StopProcessingException(ddf.catalog.plugin.StopProcessingException) FilterResult(ddf.catalog.security.FilterResult) Subject(org.apache.shiro.subject.Subject)

Example 27 with StopProcessingException

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

the class FilterPlugin method getSubject.

private Subject getSubject(Request input) throws StopProcessingException {
    Object securityAssertion = input.getProperties().get(SecurityConstants.SECURITY_SUBJECT);
    Subject subject;
    if (securityAssertion instanceof Subject) {
        subject = (Subject) securityAssertion;
        LOGGER.debug("Filter plugin found Subject for query response.");
    } else {
        throw new StopProcessingException(UNABLE_TO_FILTER_MSG);
    }
    return subject;
}
Also used : StopProcessingException(ddf.catalog.plugin.StopProcessingException) Subject(org.apache.shiro.subject.Subject)

Example 28 with StopProcessingException

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

the class ResourceOperations method getResource.

// 
// 
// 
@SuppressWarnings("javadoc")
ResourceResponse getResource(ResourceRequest resourceRequest, boolean isEnterprise, String resourceSiteName, boolean fanoutEnabled) throws IOException, ResourceNotFoundException, ResourceNotSupportedException {
    ResourceResponse resourceResponse = null;
    ResourceRequest resourceReq = resourceRequest;
    ResourceRetriever retriever = null;
    if (fanoutEnabled) {
        isEnterprise = true;
    }
    if (resourceSiteName == null && !isEnterprise) {
        throw new ResourceNotFoundException("resourceSiteName cannot be null when obtaining resource.");
    }
    validateGetResourceRequest(resourceReq);
    try {
        resourceReq = preProcessPreAuthorizationPlugins(resourceReq);
        resourceReq = processPreResourcePolicyPlugins(resourceReq);
        resourceReq = processPreResourceAccessPlugins(resourceReq);
        resourceReq = processPreResourcePlugins(resourceReq);
        Map<String, Serializable> requestProperties = resourceReq.getProperties();
        LOGGER.debug("Attempting to get resource from siteName: {}", resourceSiteName);
        // At this point we pull out the properties and use them.
        Serializable sourceIdProperty = requestProperties.get(ResourceRequest.SOURCE_ID);
        final String namedSource = (sourceIdProperty != null) ? sourceIdProperty.toString() : resourceSiteName;
        Serializable enterpriseProperty = requestProperties.get(ResourceRequest.IS_ENTERPRISE);
        if (enterpriseProperty != null && Boolean.parseBoolean(enterpriseProperty.toString())) {
            isEnterprise = true;
        }
        // check if the resourceRequest has an ID only
        // If so, the metacard needs to be found and the Resource URI
        StringBuilder resolvedSourceIdHolder = new StringBuilder();
        ResourceInfo resourceInfo = getResourceInfo(resourceReq, namedSource, isEnterprise, resolvedSourceIdHolder, requestProperties, fanoutEnabled);
        if (resourceInfo == null) {
            throw new ResourceNotFoundException("Resource could not be found for the given attribute value: " + resourceReq.getAttributeValue());
        }
        final URI responseURI = resourceInfo.getResourceUri();
        final Metacard metacard = resourceInfo.getMetacard();
        final String resolvedSourceId = resolvedSourceIdHolder.toString();
        LOGGER.debug("resolvedSourceId = {}", resolvedSourceId);
        LOGGER.debug("ID = {}", getId());
        // since resolvedSourceId specifies what source the product
        // metacard resides on, we can just
        // change resourceSiteName to be that value, and then the
        // following if-else statements will
        // handle retrieving the product on the correct source
        final String resourceSourceName = (isEnterprise) ? resolvedSourceId : namedSource;
        // retrieve product from specified federated site if not in cache
        if (!resourceSourceName.equals(getId())) {
            LOGGER.debug("Searching federatedSource {} for resource.", resourceSourceName);
            LOGGER.debug("metacard for product found on source: {}", resolvedSourceId);
            final List<FederatedSource> sources = frameworkProperties.getFederatedSources().stream().filter(e -> e.getId().equals(resourceSourceName)).collect(Collectors.toList());
            if (!sources.isEmpty()) {
                if (sources.size() != 1) {
                    LOGGER.debug("Found multiple federatedSources for id: {}", resourceSourceName);
                }
                FederatedSource source = sources.get(0);
                LOGGER.debug("Adding federated site to federated query: {}", source.getId());
                LOGGER.debug("Retrieving product from remote source {}", source.getId());
                retriever = new RemoteResourceRetriever(source, responseURI, requestProperties);
            } else {
                LOGGER.debug("Could not find federatedSource: {}", resourceSourceName);
            }
        } else {
            LOGGER.debug("Retrieving product from local source {}", resourceSourceName);
            retriever = new LocalResourceRetriever(frameworkProperties.getResourceReaders(), responseURI, metacard, requestProperties);
        }
        try {
            resourceResponse = frameworkProperties.getDownloadManager().download(resourceRequest, metacard, retriever);
        } catch (DownloadException e) {
            LOGGER.info("Unable to download resource", e);
        }
        resourceResponse = putPropertiesInResponse(resourceRequest, resourceResponse);
        resourceResponse = validateFixGetResourceResponse(resourceResponse, resourceReq);
        resourceResponse = postProcessPreAuthorizationPlugins(resourceResponse, metacard);
        resourceResponse = processPostResourcePolicyPlugins(resourceResponse, metacard);
        resourceResponse = processPostResourceAccessPlugins(resourceResponse, metacard);
        resourceResponse = processPostResourcePlugins(resourceResponse);
        resourceResponse.getProperties().put(Constants.METACARD_PROPERTY, metacard);
    } catch (DataUsageLimitExceededException e) {
        LOGGER.info("RuntimeException caused by: ", e);
        throw e;
    } catch (RuntimeException e) {
        LOGGER.info("RuntimeException caused by: ", e);
        throw new ResourceNotFoundException("Unable to find resource");
    } catch (StopProcessingException e) {
        LOGGER.info("Resource not supported", e);
        throw new ResourceNotSupportedException(FAILED_BY_GET_RESOURCE_PLUGIN + e.getMessage());
    }
    return resourceResponse;
}
Also used : LiteralImpl(ddf.catalog.filter.impl.LiteralImpl) StringUtils(org.apache.commons.lang.StringUtils) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) ResourceRetriever(ddf.catalog.resourceretriever.ResourceRetriever) DataUsageLimitExceededException(ddf.catalog.resource.DataUsageLimitExceededException) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) SystemInfo(org.codice.ddf.configuration.SystemInfo) Map(java.util.Map) PropertyIsEqualToLiteral(ddf.catalog.filter.impl.PropertyIsEqualToLiteral) PreResourcePlugin(ddf.catalog.plugin.PreResourcePlugin) URI(java.net.URI) PostResourcePlugin(ddf.catalog.plugin.PostResourcePlugin) PolicyPlugin(ddf.catalog.plugin.PolicyPlugin) FederatedSource(ddf.catalog.source.FederatedSource) Set(java.util.Set) ResourceReader(ddf.catalog.resource.ResourceReader) Collectors(java.util.stream.Collectors) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) Serializable(java.io.Serializable) QueryResponse(ddf.catalog.operation.QueryResponse) List(java.util.List) PreAuthorizationPlugin(ddf.catalog.plugin.PreAuthorizationPlugin) ResourceResponseImpl(ddf.catalog.operation.impl.ResourceResponseImpl) AccessPlugin(ddf.catalog.plugin.AccessPlugin) FilterDelegate(ddf.catalog.filter.FilterDelegate) ResourceResponse(ddf.catalog.operation.ResourceResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) PropertyNameImpl(ddf.catalog.filter.impl.PropertyNameImpl) HashMap(java.util.HashMap) ContentItem(ddf.catalog.content.data.ContentItem) Constants(ddf.catalog.Constants) Metacard(ddf.catalog.data.Metacard) ResourceRequest(ddf.catalog.operation.ResourceRequest) QueryRequest(ddf.catalog.operation.QueryRequest) RemoteResourceRetriever(ddf.catalog.resourceretriever.RemoteResourceRetriever) DownloadException(org.codice.ddf.catalog.resource.download.DownloadException) LocalResourceRetriever(ddf.catalog.resourceretriever.LocalResourceRetriever) Result(ddf.catalog.data.Result) DescribableImpl(ddf.catalog.util.impl.DescribableImpl) QueryImpl(ddf.catalog.operation.impl.QueryImpl) PolicyResponse(ddf.catalog.plugin.PolicyResponse) Logger(org.slf4j.Logger) StopProcessingException(ddf.catalog.plugin.StopProcessingException) IOException(java.io.IOException) FederationException(ddf.catalog.federation.FederationException) FrameworkProperties(ddf.catalog.impl.FrameworkProperties) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) Query(ddf.catalog.operation.Query) Filter(org.opengis.filter.Filter) Collections(java.util.Collections) RemoteResourceRetriever(ddf.catalog.resourceretriever.RemoteResourceRetriever) Serializable(java.io.Serializable) ResourceRetriever(ddf.catalog.resourceretriever.ResourceRetriever) RemoteResourceRetriever(ddf.catalog.resourceretriever.RemoteResourceRetriever) LocalResourceRetriever(ddf.catalog.resourceretriever.LocalResourceRetriever) StopProcessingException(ddf.catalog.plugin.StopProcessingException) URI(java.net.URI) Metacard(ddf.catalog.data.Metacard) FederatedSource(ddf.catalog.source.FederatedSource) ResourceResponse(ddf.catalog.operation.ResourceResponse) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) DataUsageLimitExceededException(ddf.catalog.resource.DataUsageLimitExceededException) DownloadException(org.codice.ddf.catalog.resource.download.DownloadException) LocalResourceRetriever(ddf.catalog.resourceretriever.LocalResourceRetriever) ResourceRequest(ddf.catalog.operation.ResourceRequest) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException)

Example 29 with StopProcessingException

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

the class DeleteOperations method populateMetacards.

private DeleteRequest populateMetacards(DeleteRequest deleteRequest, List<String> fanoutTagBlacklist) throws IngestException, StopProcessingException {
    QueryRequestImpl queryRequest = createQueryRequest(deleteRequest);
    QueryResponse query;
    try {
        query = queryOperations.doQuery(queryRequest, frameworkProperties.getFederationStrategy());
    } catch (FederationException e) {
        LOGGER.debug("Unable to complete query for updated metacards.", e);
        throw new IngestException("Exception during runtime while performing delete");
    }
    List<Metacard> metacards = query.getResults().stream().map(Result::getMetacard).collect(Collectors.toList());
    if (blockDeleteMetacards(metacards, fanoutTagBlacklist)) {
        String message = "Fanout proxy does not support delete operations with blacklisted metacard tag";
        LOGGER.debug("{}. Tags blacklist: {}", message, fanoutTagBlacklist);
        throw new IngestException(message);
    }
    if (!foundAllDeleteRequestMetacards(deleteRequest, query)) {
        logFailedQueryInfo(deleteRequest, query);
        throw new StopProcessingException("Could not find all metacards specified in request");
    }
    deleteRequest = rewriteRequestToAvoidHistoryConflicts(deleteRequest, query);
    deleteRequest.getProperties().put(Constants.OPERATION_TRANSACTION_KEY, new OperationTransactionImpl(OperationTransaction.OperationType.DELETE, metacards));
    return deleteRequest;
}
Also used : Metacard(ddf.catalog.data.Metacard) OperationTransactionImpl(ddf.catalog.operation.impl.OperationTransactionImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) InternalIngestException(ddf.catalog.source.InternalIngestException) IngestException(ddf.catalog.source.IngestException) StopProcessingException(ddf.catalog.plugin.StopProcessingException) FederationException(ddf.catalog.federation.FederationException)

Example 30 with StopProcessingException

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

the class DeleteOperations method doDelete.

// 
// Private helper methods
// 
public DeleteResponse doDelete(DeleteRequest deleteRequest, List<String> fanoutTagBlacklist) throws IngestException, SourceUnavailableException {
    DeleteStorageRequest deleteStorageRequest = null;
    DeleteResponse deleteResponse = null;
    deleteRequest = queryOperations.setFlagsOnRequest(deleteRequest);
    deleteRequest = validateDeleteRequest(deleteRequest);
    deleteRequest = validateLocalSource(deleteRequest);
    try {
        deleteRequest = populateMetacards(deleteRequest, fanoutTagBlacklist);
        deleteRequest = preProcessPreAuthorizationPlugins(deleteRequest);
        deleteStorageRequest = new DeleteStorageRequestImpl(getDeleteMetacards(deleteRequest), deleteRequest.getProperties());
        deleteRequest = processPreDeletePolicyPlugins(deleteRequest);
        deleteRequest = processPreDeleteAccessPlugins(deleteRequest);
        deleteRequest = processPreIngestPlugins(deleteRequest);
        deleteRequest = validateDeleteRequest(deleteRequest);
        // Call the Provider delete method
        LOGGER.debug("Calling catalog.delete() with {} entries.", deleteRequest.getAttributeValues().size());
        deleteResponse = performLocalDelete(deleteRequest, deleteStorageRequest);
        deleteResponse = remoteDeleteOperations.performRemoteDelete(deleteRequest, deleteResponse);
        deleteResponse = postProcessPreAuthorizationPlugins(deleteResponse);
        deleteRequest = populateDeleteRequestPolicyMap(deleteRequest, deleteResponse);
        deleteResponse = processPostDeleteAccessPlugins(deleteResponse);
        // Post results to be available for pubsub
        deleteResponse = validateFixDeleteResponse(deleteResponse, deleteRequest);
    } catch (StopProcessingException see) {
        LOGGER.debug(PRE_INGEST_ERROR + see.getMessage(), see);
        throw new IngestException(PRE_INGEST_ERROR + see.getMessage());
    } catch (RuntimeException re) {
        LOGGER.debug("Unhandled runtime exception during delete", re);
        throw new InternalIngestException("Exception during runtime while performing delete.");
    } finally {
        if (deleteStorageRequest != null) {
            try {
                sourceOperations.getStorage().commit(deleteStorageRequest);
            } catch (StorageException e) {
                LOGGER.info("Unable to remove stored content items.", e);
            }
        }
    }
    if (deleteResponse == null) {
        // suppress all npe findings for this method.
        throw new IngestException("CatalogProvider returned null DeleteResponse Object.");
    }
    deleteResponse = doPostIngest(deleteResponse);
    return deleteResponse;
}
Also used : DeleteStorageRequest(ddf.catalog.content.operation.DeleteStorageRequest) DeleteStorageRequestImpl(ddf.catalog.content.operation.impl.DeleteStorageRequestImpl) DeleteResponse(ddf.catalog.operation.DeleteResponse) InternalIngestException(ddf.catalog.source.InternalIngestException) InternalIngestException(ddf.catalog.source.InternalIngestException) IngestException(ddf.catalog.source.IngestException) StopProcessingException(ddf.catalog.plugin.StopProcessingException) StorageException(ddf.catalog.content.StorageException)

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