Search in sources :

Example 6 with StopProcessingException

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

the class CreateOperations method doCreate.

// 
// Private helper methods
// 
private CreateResponse doCreate(CreateRequest createRequest) throws IngestException, SourceUnavailableException {
    CreateResponse createResponse;
    Exception ingestError = null;
    createRequest = queryOperations.setFlagsOnRequest(createRequest);
    createRequest = validateCreateRequest(createRequest);
    createRequest = validateLocalSource(createRequest);
    String fileNames = "";
    if (createRequest != null) {
        List<String> fileList = createRequest.getMetacards().stream().filter(Objects::nonNull).map(Metacard::getTitle).collect(Collectors.toList());
        fileNames = String.join(", ", fileList);
    }
    try {
        INGEST_LOGGER.info("Started ingesting metacard with titles: {}.", fileNames);
        createRequest = injectAttributes(createRequest);
        createRequest = setDefaultValues(createRequest);
        createRequest = processPreAuthorizationPlugins(createRequest);
        createRequest = updateCreateRequestPolicyMap(createRequest);
        createRequest = processPrecreateAccessPlugins(createRequest);
        createRequest.getProperties().put(Constants.OPERATION_TRANSACTION_KEY, new OperationTransactionImpl(OperationTransaction.OperationType.CREATE, Collections.emptyList()));
        createRequest = processPreIngestPlugins(createRequest);
        createRequest = validateCreateRequest(createRequest);
        createResponse = getCreateResponse(createRequest);
        createResponse = performRemoteCreate(createRequest, createResponse);
    } catch (IngestException iee) {
        ingestError = iee;
        throw iee;
    } catch (StopProcessingException see) {
        ingestError = see;
        throw new IngestException(PRE_INGEST_ERROR, see);
    } catch (RuntimeException re) {
        ingestError = re;
        throw new InternalIngestException("Exception during runtime while performing create", re);
    } finally {
        if (createRequest != null && ingestError != null && INGEST_LOGGER.isInfoEnabled()) {
            INGEST_LOGGER.info("Error on create operation. {} metacards failed to ingest. {}", createRequest.getMetacards().size(), buildIngestLog(createRequest), ingestError);
        }
    }
    try {
        createResponse = validateFixCreateResponse(createResponse, createRequest);
    } catch (RuntimeException re) {
        LOGGER.info("Exception during runtime while performing doing post create operations (plugins and pubsub)", re);
    }
    if (createResponse == null) {
        // suppress all npe findings for this method.
        throw new IngestException("CatalogProvider returned null CreateResponse Object.");
    }
    return createResponse;
}
Also used : OperationTransactionImpl(ddf.catalog.operation.impl.OperationTransactionImpl) InternalIngestException(ddf.catalog.source.InternalIngestException) CreateResponse(ddf.catalog.operation.CreateResponse) Objects(java.util.Objects) InternalIngestException(ddf.catalog.source.InternalIngestException) IngestException(ddf.catalog.source.IngestException) StopProcessingException(ddf.catalog.plugin.StopProcessingException) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) StorageException(ddf.catalog.content.StorageException) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) InternalIngestException(ddf.catalog.source.InternalIngestException) IngestException(ddf.catalog.source.IngestException) StopProcessingException(ddf.catalog.plugin.StopProcessingException) IOException(java.io.IOException)

Example 7 with StopProcessingException

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

the class QueryOperations method populateQueryResponsePolicyMap.

private QueryResponse populateQueryResponsePolicyMap(QueryResponse queryResponse) throws FederationException {
    HashMap<String, Set<String>> responsePolicyMap = new HashMap<>();
    Map<String, Serializable> unmodifiableProperties = Collections.unmodifiableMap(queryResponse.getProperties());
    for (Result result : queryResponse.getResults()) {
        HashMap<String, Set<String>> itemPolicyMap = new HashMap<>();
        for (PolicyPlugin plugin : frameworkProperties.getPolicyPlugins()) {
            try {
                PolicyResponse policyResponse = plugin.processPostQuery(result, unmodifiableProperties);
                opsSecuritySupport.buildPolicyMap(itemPolicyMap, policyResponse.itemPolicy().entrySet());
                opsSecuritySupport.buildPolicyMap(responsePolicyMap, policyResponse.operationPolicy().entrySet());
            } catch (StopProcessingException e) {
                throw new FederationException(QUERY_FAILURE_MSG, e);
            }
        }
        result.getMetacard().setAttribute(new AttributeImpl(Metacard.SECURITY, itemPolicyMap));
    }
    queryResponse.getProperties().put(PolicyPlugin.OPERATION_SECURITY, responsePolicyMap);
    return queryResponse;
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) PolicyPlugin(ddf.catalog.plugin.PolicyPlugin) StopProcessingException(ddf.catalog.plugin.StopProcessingException) FederationException(ddf.catalog.federation.FederationException) PolicyResponse(ddf.catalog.plugin.PolicyResponse) Result(ddf.catalog.data.Result)

Example 8 with StopProcessingException

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

the class UpdateOperations method doUpdate.

// 
// Private helper methods
// 
private UpdateResponse doUpdate(UpdateRequest updateRequest) throws IngestException, SourceUnavailableException {
    updateRequest = queryOperations.setFlagsOnRequest(updateRequest);
    updateRequest = validateUpdateRequest(updateRequest);
    updateRequest = validateLocalSource(updateRequest);
    try {
        updateRequest = injectAttributes(updateRequest);
        updateRequest = setDefaultValues(updateRequest);
        updateRequest = populateMetacards(updateRequest);
        updateRequest = processPreAuthorizationPlugins(updateRequest);
        updateRequest = populateUpdateRequestPolicyMap(updateRequest);
        updateRequest = processPreUpdateAccessPlugins(updateRequest);
        updateRequest = processPreIngestPlugins(updateRequest);
        updateRequest = validateUpdateRequest(updateRequest);
        // Call the update on the catalog
        LOGGER.debug("Calling catalog.update() with {} updates.", updateRequest.getUpdates().size());
        UpdateResponse updateResponse = performLocalUpdate(updateRequest);
        updateResponse = performRemoteUpdate(updateRequest, updateResponse);
        // Handle the posting of messages to pubsub
        updateResponse = validateFixUpdateResponse(updateResponse, updateRequest);
        return updateResponse;
    } catch (StopProcessingException see) {
        throw new IngestException(PRE_INGEST_ERROR, see);
    } catch (RuntimeException re) {
        LOGGER.debug("Unhandled runtime exception during update", re);
        throw new InternalIngestException("Exception during runtime while performing update", re);
    }
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) InternalIngestException(ddf.catalog.source.InternalIngestException) InternalIngestException(ddf.catalog.source.InternalIngestException) IngestException(ddf.catalog.source.IngestException) StopProcessingException(ddf.catalog.plugin.StopProcessingException)

Example 9 with StopProcessingException

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

the class DeliveryProcessor method process.

public void process(Event event) {
    String methodName = "process";
    LOGGER.debug("ENTERING: {}", methodName);
    Metacard entry = (Metacard) event.getProperty(PubSubConstants.HEADER_ENTRY_KEY);
    String operation = event.getProperty(PubSubConstants.HEADER_OPERATION_KEY).toString();
    LOGGER.debug("Delivering catalog entry.");
    if (subscription != null) {
        if (entry != null) {
            if (operation.equalsIgnoreCase(PubSubConstants.CREATE)) {
                try {
                    for (PreDeliveryPlugin plugin : preDelivery) {
                        LOGGER.debug("Processing 'created' entry with preDelivery plugin");
                        entry = plugin.processCreate(entry);
                    }
                    subscription.getDeliveryMethod().created(entry);
                } catch (PluginExecutionException e) {
                    LOGGER.debug(PLUGIN_EXCEPTION_MSG, e);
                    subscription.getDeliveryMethod().created(entry);
                } catch (StopProcessingException e) {
                    LOGGER.info(DELIVERY_FAILURE_MSG, e);
                }
            } else if (operation.equalsIgnoreCase(PubSubConstants.UPDATE)) {
                // TODO: Handle hit or miss
                try {
                    for (PreDeliveryPlugin plugin : preDelivery) {
                        LOGGER.debug("Processing 'updated' entry with preDelivery plugin");
                        Update updatedEntry = plugin.processUpdateHit(new UpdateImpl(entry, null));
                        entry = updatedEntry.getNewMetacard();
                    }
                    subscription.getDeliveryMethod().updatedHit(entry, entry);
                } catch (PluginExecutionException e) {
                    LOGGER.debug(PLUGIN_EXCEPTION_MSG, e);
                    subscription.getDeliveryMethod().updatedHit(entry, entry);
                } catch (StopProcessingException e) {
                    LOGGER.info(DELIVERY_FAILURE_MSG, e);
                }
            } else if (operation.equalsIgnoreCase(PubSubConstants.DELETE)) {
                try {
                    for (PreDeliveryPlugin plugin : preDelivery) {
                        LOGGER.debug("Processing 'deleted' entry with preDelivery plugin");
                        entry = plugin.processCreate(entry);
                    }
                    subscription.getDeliveryMethod().deleted(entry);
                } catch (PluginExecutionException e) {
                    LOGGER.debug(PLUGIN_EXCEPTION_MSG, e);
                    subscription.getDeliveryMethod().deleted(entry);
                } catch (StopProcessingException e) {
                    LOGGER.info(DELIVERY_FAILURE_MSG, e);
                }
            } else {
                LOGGER.debug("Could not deliver hit for subscription.");
            }
        } else {
            LOGGER.debug("Could not deliver hit for subscription. Catalog entry is null.");
        }
    } else {
        LOGGER.debug("Could not deliver hit for subscription. Subscription is null.");
    }
    LOGGER.debug("EXITING: {}", methodName);
}
Also used : UpdateImpl(ddf.catalog.operation.impl.UpdateImpl) Metacard(ddf.catalog.data.Metacard) PreDeliveryPlugin(ddf.catalog.plugin.PreDeliveryPlugin) StopProcessingException(ddf.catalog.plugin.StopProcessingException) Update(ddf.catalog.operation.Update) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException)

Example 10 with StopProcessingException

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

the class OAuthPlugin method findExistingTokens.

/**
 * Looks through the user's tokens to see if there are tokens from a different source connected to
 * the same OAuth provider. The discovery URLs need to match. If a match is found an authorize
 * source exception will be thrown so the user can authorize to query the new source instead of
 * logging in.
 */
private void findExistingTokens(OAuthFederatedSource oauthSource, String sessionId, OIDCProviderMetadata metadata) throws StopProcessingException {
    TokenInformation tokenInformation = tokenStorage.read(sessionId);
    if (tokenInformation == null || !tokenInformation.getDiscoveryUrls().contains(oauthSource.getOauthDiscoveryUrl())) {
        return;
    }
    // Verify that an unexpired token exists
    List<TokenInformation.TokenEntry> matchingTokenEntries = tokenInformation.getTokenEntries().entrySet().stream().filter(entry -> !entry.getKey().equals(oauthSource.getId())).filter(entry -> entry.getValue().getDiscoveryUrl().equals(oauthSource.getOauthDiscoveryUrl())).map(Map.Entry::getValue).collect(Collectors.toList());
    TokenInformation.TokenEntry tokenEntry = matchingTokenEntries.stream().filter(entry -> entry.getAccessToken() != null).filter(entry -> !isExpired(entry.getAccessToken())).findAny().orElse(null);
    if (tokenEntry == null) {
        // does one with a valid refresh token exist
        tokenEntry = matchingTokenEntries.stream().filter(entry -> entry.getRefreshToken() != null).filter(entry -> !isExpired(entry.getRefreshToken())).findAny().orElse(null);
        if (tokenEntry == null) {
            return;
        }
        refreshTokens(tokenEntry.getRefreshToken(), oauthSource, sessionId, metadata);
    }
    LOGGER.debug("Unable to process query. The user needs to authorize to query the {} source.", oauthSource.getId());
    Map<String, String> parameters = new HashMap<>();
    parameters.put(SOURCE_ID, oauthSource.getId());
    parameters.put(DISCOVERY_URL, oauthSource.getOauthDiscoveryUrl());
    throw new OAuthPluginException(oauthSource.getId(), buildUrl(AUTHORIZE_SOURCE_ENDPOINT, parameters), AUTHORIZE_SOURCE_ENDPOINT, parameters, AUTH_SOURCE);
}
Also used : STATE(org.codice.ddf.security.token.storage.api.TokenStorage.STATE) Arrays(java.util.Arrays) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) RefreshTokenGrant(org.apache.cxf.rs.security.oauth2.grants.refresh.RefreshTokenGrant) LoggerFactory(org.slf4j.LoggerFactory) DefaultResourceRetriever(com.nimbusds.jose.util.DefaultResourceRetriever) Session(org.apache.shiro.session.Session) ClientAccessToken(org.apache.cxf.rs.security.oauth2.common.ClientAccessToken) GsonBuilder(com.google.gson.GsonBuilder) NO_AUTH(ddf.catalog.plugin.OAuthPluginException.ErrorType.NO_AUTH) OAuthClientUtils(org.apache.cxf.rs.security.oauth2.client.OAuthClientUtils) OAuthFederatedSource(ddf.catalog.source.OAuthFederatedSource) EXPIRES_AT(org.codice.ddf.security.token.storage.api.TokenStorage.EXPIRES_AT) Gson(com.google.gson.Gson) OidcTokenValidator(org.codice.ddf.security.oidc.validator.OidcTokenValidator) Map(java.util.Map) Bundle(org.osgi.framework.Bundle) TokenInformation(org.codice.ddf.security.token.storage.api.TokenInformation) ServiceReference(org.osgi.framework.ServiceReference) Consumer(org.apache.cxf.rs.security.oauth2.client.Consumer) AccessToken(com.nimbusds.oauth2.sdk.token.AccessToken) OAuthPluginException(ddf.catalog.plugin.OAuthPluginException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) URIBuilder(org.apache.http.client.utils.URIBuilder) Collection(java.util.Collection) UUID(java.util.UUID) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) BundleContext(org.osgi.framework.BundleContext) Base64(java.util.Base64) List(java.util.List) OAuthServiceException(org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException) HashMap(java.util.HashMap) TokenEntry(org.codice.ddf.security.token.storage.api.TokenInformation.TokenEntry) SECRET(org.codice.ddf.security.token.storage.api.TokenStorage.SECRET) SOURCE_ID(org.codice.ddf.security.token.storage.api.TokenStorage.SOURCE_ID) Source(ddf.catalog.source.Source) DISCOVERY_URL(org.codice.ddf.security.token.storage.api.TokenStorage.DISCOVERY_URL) QueryRequest(ddf.catalog.operation.QueryRequest) AUTH_SOURCE(ddf.catalog.plugin.OAuthPluginException.ErrorType.AUTH_SOURCE) ParseException(com.nimbusds.oauth2.sdk.ParseException) CLIENT_ID(org.codice.ddf.security.token.storage.api.TokenStorage.CLIENT_ID) GsonTypeAdapters(org.codice.gsonsupport.GsonTypeAdapters) PreFederatedQueryPlugin(ddf.catalog.plugin.PreFederatedQueryPlugin) Logger(org.slf4j.Logger) SystemBaseUrl(org.codice.ddf.configuration.SystemBaseUrl) OIDCProviderMetadata(com.nimbusds.openid.connect.sdk.op.OIDCProviderMetadata) MalformedURLException(java.net.MalformedURLException) WebClient(org.apache.cxf.jaxrs.client.WebClient) BearerAccessToken(com.nimbusds.oauth2.sdk.token.BearerAccessToken) Scope(com.nimbusds.oauth2.sdk.Scope) StopProcessingException(ddf.catalog.plugin.StopProcessingException) Subject(ddf.security.Subject) IOException(java.io.IOException) SECURITY_SUBJECT(ddf.security.SecurityConstants.SECURITY_SUBJECT) OidcValidationException(org.codice.ddf.security.oidc.validator.OidcValidationException) MAP_STRING_TO_OBJECT_TYPE(org.codice.gsonsupport.GsonTypeAdapters.MAP_STRING_TO_OBJECT_TYPE) ResourceRetriever(com.nimbusds.jose.util.ResourceRetriever) SC_OK(org.apache.http.HttpStatus.SC_OK) ChronoUnit(java.time.temporal.ChronoUnit) TokenStorage(org.codice.ddf.security.token.storage.api.TokenStorage) VisibleForTesting(com.google.common.annotations.VisibleForTesting) AccessTokenGrant(org.apache.cxf.rs.security.oauth2.common.AccessTokenGrant) TypelessAccessToken(com.nimbusds.oauth2.sdk.token.TypelessAccessToken) FrameworkUtil(org.osgi.framework.FrameworkUtil) TokenEntry(org.codice.ddf.security.token.storage.api.TokenInformation.TokenEntry) OAuthPluginException(ddf.catalog.plugin.OAuthPluginException) TokenEntry(org.codice.ddf.security.token.storage.api.TokenInformation.TokenEntry) HashMap(java.util.HashMap) TokenInformation(org.codice.ddf.security.token.storage.api.TokenInformation) Map(java.util.Map) HashMap(java.util.HashMap)

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