Search in sources :

Example 1 with FoundAction

use of org.pac4j.core.exception.http.FoundAction in project cas by apereo.

the class OAuth20DefaultCasClientRedirectActionBuilder method build.

/**
 * Build with predefined renew and gateway parameters.
 *
 * @param casClient the cas client config
 * @param context   the context
 * @param renew     ask for credentials again
 * @param gateway   skip asking for credentials
 * @return the redirect action
 */
protected Optional<RedirectionAction> build(final CasClient casClient, final WebContext context, final boolean renew, final boolean gateway) {
    val serviceUrl = casClient.computeFinalCallbackUrl(context);
    val casServerLoginUrl = casClient.getConfiguration().getLoginUrl();
    val redirectionUrl = casServerLoginUrl + (casServerLoginUrl.contains("?") ? "&" : "?") + CasProtocolConstants.PARAMETER_SERVICE + '=' + EncodingUtils.urlEncode(serviceUrl) + (renew ? '&' + CasProtocolConstants.PARAMETER_RENEW + "=true" : StringUtils.EMPTY) + (gateway ? '&' + CasProtocolConstants.PARAMETER_GATEWAY + "=true" : StringUtils.EMPTY);
    LOGGER.debug("Final redirect url is [{}]", redirectionUrl);
    return Optional.of(new FoundAction(redirectionUrl));
}
Also used : lombok.val(lombok.val) FoundAction(org.pac4j.core.exception.http.FoundAction)

Example 2 with FoundAction

use of org.pac4j.core.exception.http.FoundAction in project ddf by codice.

the class OidcLogoutActionProviderTest method testGetAction.

@Test
public void testGetAction() {
    String actionUrl = "https://localhost:8993/services/oidc/logout";
    FoundAction foundAction = mock(FoundAction.class);
    when(foundAction.getLocation()).thenReturn(actionUrl);
    when(oidcLogoutActionBuilder.getLogoutAction(any(), any(), any())).thenReturn(Optional.of(foundAction));
    Action action = oidcLogoutActionProvider.getAction(ImmutableMap.of(SecurityConstants.SECURITY_SUBJECT, subject, "http_request", request, "http_response", response));
    assertEquals(actionUrl, action.getUrl().toString());
}
Also used : FoundAction(org.pac4j.core.exception.http.FoundAction) Action(ddf.action.Action) FoundAction(org.pac4j.core.exception.http.FoundAction) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 3 with FoundAction

use of org.pac4j.core.exception.http.FoundAction in project cas by apereo.

the class DelegatedAuthenticationClientFinishLogoutActionTests method verifyOperationFailsWithError.

@Test
public void verifyOperationFailsWithError() throws Exception {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    request.addParameter(SamlProtocolConstants.PARAMETER_SAML_RELAY_STATE, "SAML2Client");
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val samlClient = (SAML2Client) builtClients.findClient("SAML2Client").get();
    val handler = mock(SAML2ProfileHandler.class);
    when(handler.receive(any())).thenThrow(new FoundAction("https://google.com"));
    samlClient.setLogoutProfileHandler(handler);
    val result = delegatedAuthenticationClientFinishLogoutAction.execute(context);
    assertNull(result);
    assertEquals(HttpStatus.FOUND.value(), response.getStatus());
    assertEquals("https://google.com", response.getHeader("Location"));
}
Also used : lombok.val(lombok.val) FoundAction(org.pac4j.core.exception.http.FoundAction) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) SAML2Client(org.pac4j.saml.client.SAML2Client) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.apereo.cas.util.MockServletContext) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

FoundAction (org.pac4j.core.exception.http.FoundAction)3 lombok.val (lombok.val)2 Action (ddf.action.Action)1 MockServletContext (org.apereo.cas.util.MockServletContext)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 SAML2Client (org.pac4j.saml.client.SAML2Client)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)1 MockRequestContext (org.springframework.webflow.test.MockRequestContext)1