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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations