Search in sources :

Example 6 with ActionImpl

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

the class DerivedContentActionProviderTest method testGetActionsNonContentUriWithQualifier.

@Test
public void testGetActionsNonContentUriWithQualifier() 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(actionUri));
    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().toString(), is(actionUri.toString()));
    assertThat(actions.get(0).getTitle(), is("View " + QUALIFIER_VALUE));
}
Also used : Metacard(ddf.catalog.data.Metacard) Action(ddf.action.Action) ActionImpl(ddf.action.impl.ActionImpl) Test(org.junit.Test)

Example 7 with ActionImpl

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

the class DerivedContentActionProviderTest method testGetActions.

@Test
public void testGetActions() throws Exception {
    ActionImpl expectedAction = new ActionImpl("expected", "expected", "expected", actionUri.toURL());
    when(mockResourceActionProvider.getAction(any(Metacard.class))).thenReturn(expectedAction);
    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().getQuery(), containsString(ContentItem.QUALIFIER_KEYWORD + "=" + QUALIFIER_VALUE));
}
Also used : Metacard(ddf.catalog.data.Metacard) Action(ddf.action.Action) ActionImpl(ddf.action.impl.ActionImpl) Test(org.junit.Test)

Example 8 with ActionImpl

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

the class OidcLogoutActionProvider method getAction.

/**
 * *
 *
 * @param <T> is a Map<String, Subject>
 * @param subjectMap containing the corresponding subject
 * @return OidcLogoutActionProvider containing the logout url
 */
@Override
public <T> Action getAction(T subjectMap) {
    if (!canHandle(subjectMap)) {
        return null;
    }
    String logoutUrlString = "";
    URL logoutUrl = null;
    try {
        HttpServletRequest request = (HttpServletRequest) ((Map) subjectMap).get("http_request");
        HttpServletResponse response = (HttpServletResponse) ((Map) subjectMap).get("http_response");
        JEESessionStore sessionStore = new JEESessionStore();
        JEEContext jeeContext = new JEEContext(request, response, sessionStore);
        HttpSession session = request.getSession(false);
        PrincipalHolder principalHolder = null;
        if (session != null) {
            principalHolder = (PrincipalHolder) session.getAttribute(SecurityConstants.SECURITY_TOKEN_KEY);
        }
        OidcProfile oidcProfile = null;
        if (principalHolder != null && principalHolder.getPrincipals() != null) {
            Collection<SecurityAssertion> securityAssertions = principalHolder.getPrincipals().byType(SecurityAssertion.class);
            for (SecurityAssertion securityAssertion : securityAssertions) {
                if (SecurityAssertionJwt.JWT_TOKEN_TYPE.equals(securityAssertion.getTokenType())) {
                    oidcProfile = (OidcProfile) securityAssertion.getToken();
                    break;
                }
            }
        }
        if (oidcProfile == null) {
            throw new IllegalStateException("Unable to determine OIDC profile for logout");
        }
        OidcLogoutActionBuilder logoutActionBuilder = handlerConfiguration.getOidcLogoutActionBuilder();
        logoutActionBuilder.setAjaxRequestResolver(new DefaultAjaxRequestResolver() {

            @Override
            public boolean isAjax(final WebContext context) {
                return false;
            }
        });
        URIBuilder urlBuilder = new URIBuilder(SystemBaseUrl.EXTERNAL.constructUrl("/oidc/logout", true));
        String prevUrl = getPreviousUrl(request);
        if (prevUrl != null) {
            urlBuilder.addParameter(PREV_URL, prevUrl);
        }
        RedirectionAction logoutAction = logoutActionBuilder.getLogoutAction(jeeContext, oidcProfile, urlBuilder.build().toString()).orElse(null);
        if (logoutAction instanceof WithLocationAction) {
            logoutUrlString = ((WithLocationAction) logoutAction).getLocation();
        }
        logoutUrl = new URL(logoutUrlString);
    } catch (MalformedURLException | URISyntaxException e) {
        LOGGER.info("Unable to resolve logout URL: {}", logoutUrlString);
    } catch (ClassCastException e) {
        LOGGER.debug("Unable to cast parameter to Map<String, Object>, {}", subjectMap, e);
    }
    return new ActionImpl(ID, TITLE, DESCRIPTION, logoutUrl);
}
Also used : RedirectionAction(org.pac4j.core.exception.http.RedirectionAction) MalformedURLException(java.net.MalformedURLException) WebContext(org.pac4j.core.context.WebContext) HttpSession(javax.servlet.http.HttpSession) JEEContext(org.pac4j.core.context.JEEContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) JEESessionStore(org.pac4j.core.context.session.JEESessionStore) WithLocationAction(org.pac4j.core.exception.http.WithLocationAction) URISyntaxException(java.net.URISyntaxException) SecurityAssertion(ddf.security.assertion.SecurityAssertion) URL(java.net.URL) URIBuilder(org.apache.http.client.utils.URIBuilder) HttpServletRequest(javax.servlet.http.HttpServletRequest) DefaultAjaxRequestResolver(org.pac4j.core.http.ajax.DefaultAjaxRequestResolver) OidcLogoutActionBuilder(org.pac4j.oidc.logout.OidcLogoutActionBuilder) ActionImpl(ddf.action.impl.ActionImpl) OidcProfile(org.pac4j.oidc.profile.OidcProfile) PrincipalHolder(ddf.security.common.PrincipalHolder)

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