Search in sources :

Example 1 with ActionImpl

use of ddf.action.impl.ActionImpl in project ddf by codice.

the class IdpLogoutActionProvider method getAction.

/**
 * *
 *
 * @param <T> is a Map<String, Subject>
 * @param subjectMap containing the corresponding subject
 * @return IdpLogoutActionProvider containing the logout url
 */
@Override
public <T> Action getAction(T subjectMap) {
    if (!canHandle(subjectMap)) {
        return null;
    }
    String logoutUrlString = "";
    URL logoutUrl = null;
    try {
        @SuppressWarnings("unchecked") Object subject = ((Map) subjectMap).get(SecurityConstants.SECURITY_SUBJECT);
        String nameId = subjectOperations.getName((Subject) subject, "You", true);
        String nameIdTimestamp = nameId + "\n" + System.currentTimeMillis();
        nameIdTimestamp = URLEncoder.encode(encryptionService.encrypt(nameIdTimestamp), StandardCharsets.UTF_8.name());
        logoutUrlString = SystemBaseUrl.EXTERNAL.constructUrl("/saml/logout/request?EncryptedNameIdTime=" + nameIdTimestamp, true);
        logoutUrl = new URL(logoutUrlString);
    } catch (MalformedURLException e) {
        LOGGER.info("Unable to resolve URL: {}", LogSanitizer.sanitize(logoutUrlString));
    } catch (ClassCastException e) {
        LOGGER.debug("Unable to cast parameter to Map<String, Object>, {}", LogSanitizer.sanitize(subjectMap), e);
    } catch (UnsupportedEncodingException e) {
        LOGGER.debug("Unable to encode the encrypted timestamp.", e);
    }
    return new ActionImpl(ID, TITLE, DESCRIPTION, logoutUrl);
}
Also used : MalformedURLException(java.net.MalformedURLException) ActionImpl(ddf.action.impl.ActionImpl) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Map(java.util.Map) URL(java.net.URL)

Example 2 with ActionImpl

use of ddf.action.impl.ActionImpl in project ddf by codice.

the class OverlayActionProvider method getAction.

@Override
public <T> Action getAction(T subject) {
    if (canHandle(subject)) {
        final Metacard metacard = (Metacard) subject;
        try {
            final String sourceId = URLEncoder.encode(metacard.getSourceId(), UTF_8);
            final String metacardId = URLEncoder.encode(metacard.getId(), UTF_8);
            final String encodedTransformerId = URLEncoder.encode(transformerId, UTF_8);
            final URI uri = new URI(SystemBaseUrl.EXTERNAL.constructUrl("/catalog/sources/" + sourceId + "/" + metacardId + "?transform=" + encodedTransformerId, true));
            final String overlayName = transformerId.substring(OVERLAY_PREFIX.length());
            return new ActionImpl(ID + transformerId, TITLE + overlayName + " overlay", DESCRIPTION + overlayName + " overlay transformer", uri.toURL());
        } catch (URISyntaxException | MalformedURLException | UnsupportedEncodingException e) {
            LOGGER.debug("Error constructing URL", e);
        }
    } else {
        LOGGER.debug("Cannot handle the input [{}]", subject);
    }
    return null;
}
Also used : Metacard(ddf.catalog.data.Metacard) MalformedURLException(java.net.MalformedURLException) ActionImpl(ddf.action.impl.ActionImpl) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 3 with ActionImpl

use of ddf.action.impl.ActionImpl in project ddf by codice.

the class DerivedContentActionProviderTest method testGetActionsNonContentUriDefault.

@Test
public void testGetActionsNonContentUriDefault() throws Exception {
    ActionImpl expectedAction = new ActionImpl("expected", "expected", "expected", actionUri.toURL());
    when(mockResourceActionProvider.getAction(any(Metacard.class))).thenReturn(expectedAction);
    when(attribute.getValues()).thenReturn(Arrays.asList(EXAMPLE_URL));
    List<Action> actions = actionProvider.getActions(metacard);
    assertThat(actions, hasSize(1));
    assertThat(actions.get(0), notNullValue());
    assertThat(actions.get(0).getUrl(), notNullValue());
    assertThat(actions.get(0).getUrl(), is(new URL(EXAMPLE_URL)));
}
Also used : Metacard(ddf.catalog.data.Metacard) Action(ddf.action.Action) ActionImpl(ddf.action.impl.ActionImpl) URL(java.net.URL) Test(org.junit.Test)

Example 4 with ActionImpl

use of ddf.action.impl.ActionImpl in project ddf by codice.

the class RegistryPublicationActionProvider method getAction.

private Action getAction(String regId, String destinationId, String destinationName, boolean publish) {
    URL url;
    String title = publish ? PUBLISH_TITLE + destinationName : UNPUBLISH_TITLE + destinationName;
    String description = publish ? PUBLISH_DESCRIPTION + destinationName : UNPUBLISH_DESCRIPTION + destinationName;
    String operation = publish ? PUBLISH_OPERATION : UNPUBLISH_OPERATION;
    String httpOp = publish ? HTTP_POST : HTTP_DELETE;
    try {
        String path = String.format("%s/%s/%s/%s", REGISTRY_PATH, regId, PUBLICATION_PATH, URLEncoder.encode(destinationId, "UTF-8"));
        URI uri = new URI(SystemBaseUrl.constructUrl(path, true));
        url = uri.toURL();
    } catch (MalformedURLException | URISyntaxException | UnsupportedEncodingException e) {
        LOGGER.debug("Malformed URL exception", e);
        return null;
    }
    String id = String.format("%s.%s.%s", getId(), operation, httpOp);
    return new ActionImpl(id, title, description, url);
}
Also used : MalformedURLException(java.net.MalformedURLException) ActionImpl(ddf.action.impl.ActionImpl) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URL(java.net.URL)

Example 5 with ActionImpl

use of ddf.action.impl.ActionImpl in project ddf by codice.

the class RegistryReportActionProvider method getAction.

private Action getAction(String metacardId, String sourceId) {
    if (StringUtils.isNotBlank(sourceId)) {
        sourceId = SOURCE_ID_QUERY_PARAM + sourceId;
    }
    URL url;
    try {
        URI uri = new URI(SystemBaseUrl.constructUrl(String.format("%s/%s%s%s%s", REGISTRY_PATH, metacardId, REPORT_PATH, FORMAT, sourceId), true));
        url = uri.toURL();
    } catch (MalformedURLException e) {
        LOGGER.debug("Malformed URL exception", e);
        return null;
    } catch (URISyntaxException e) {
        LOGGER.debug("URI Syntax exception", e);
        return null;
    }
    return new ActionImpl(getId(), title, description, url);
}
Also used : MalformedURLException(java.net.MalformedURLException) ActionImpl(ddf.action.impl.ActionImpl) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URL(java.net.URL)

Aggregations

ActionImpl (ddf.action.impl.ActionImpl)8 MalformedURLException (java.net.MalformedURLException)5 URL (java.net.URL)5 Metacard (ddf.catalog.data.Metacard)4 URISyntaxException (java.net.URISyntaxException)4 Action (ddf.action.Action)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 URI (java.net.URI)3 Test (org.junit.Test)3 SecurityAssertion (ddf.security.assertion.SecurityAssertion)1 PrincipalHolder (ddf.security.common.PrincipalHolder)1 Map (java.util.Map)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpSession (javax.servlet.http.HttpSession)1 URIBuilder (org.apache.http.client.utils.URIBuilder)1 JEEContext (org.pac4j.core.context.JEEContext)1 WebContext (org.pac4j.core.context.WebContext)1 JEESessionStore (org.pac4j.core.context.session.JEESessionStore)1 RedirectionAction (org.pac4j.core.exception.http.RedirectionAction)1