Search in sources :

Example 1 with GetLogoutUriResponse

use of io.jans.ca.common.response.GetLogoutUriResponse in project jans by JanssenProject.

the class GetLogoutUrlOperation method execute.

@Override
public IOpResponse execute(GetLogoutUrlParams params) throws Exception {
    final Rp rp = getRp();
    OpenIdConfigurationResponse discoveryResponse = getDiscoveryService().getConnectDiscoveryResponse(rp);
    String endSessionEndpoint = discoveryResponse.getEndSessionEndpoint();
    String postLogoutRedirectUrl = params.getPostLogoutRedirectUri();
    if (Strings.isNullOrEmpty(postLogoutRedirectUrl)) {
        postLogoutRedirectUrl = rp.getPostLogoutRedirectUri();
    }
    if (Strings.isNullOrEmpty(postLogoutRedirectUrl)) {
        postLogoutRedirectUrl = "";
    }
    if (Strings.isNullOrEmpty(endSessionEndpoint)) {
        if (rp.getOpHost().startsWith(GOOGLE_OP_HOST) && getInstance(ConfigurationService.class).get().getSupportGoogleLogout()) {
            String logoutUrl = "https://www.google.com/accounts/Logout?continue=https://appengine.google.com/_ah/logout?continue=" + postLogoutRedirectUrl;
            return new GetLogoutUriResponse(logoutUrl);
        }
        LOG.error("Failed to get end_session_endpoint at: " + getDiscoveryService().getConnectDiscoveryUrl(rp));
        throw new HttpException(ErrorResponseCode.FAILED_TO_GET_END_SESSION_ENDPOINT);
    }
    String uri = endSessionEndpoint;
    if (!Strings.isNullOrEmpty(postLogoutRedirectUrl)) {
        uri += separator(uri) + "post_logout_redirect_uri=" + URLEncoder.encode(postLogoutRedirectUrl, "UTF-8");
    }
    if (!Strings.isNullOrEmpty(params.getState())) {
        uri += separator(uri) + "state=" + getStateService().encodeExpiredObject(params.getState(), ExpiredObjectType.STATE);
    }
    if (!Strings.isNullOrEmpty(params.getSessionState())) {
        uri += separator(uri) + "session_state=" + params.getSessionState();
    }
    if (!Strings.isNullOrEmpty(params.getIdTokenHint())) {
        uri += separator(uri) + "id_token_hint=" + params.getIdTokenHint();
    }
    return new GetLogoutUriResponse(uri);
}
Also used : GetLogoutUriResponse(io.jans.ca.common.response.GetLogoutUriResponse) OpenIdConfigurationResponse(io.jans.as.client.OpenIdConfigurationResponse) HttpException(io.jans.ca.server.HttpException) ConfigurationService(io.jans.ca.server.service.ConfigurationService) Rp(io.jans.ca.server.service.Rp)

Example 2 with GetLogoutUriResponse

use of io.jans.ca.common.response.GetLogoutUriResponse in project jans by JanssenProject.

the class AuthorizationCodeFlowTest method getLogoutUrl.

public static void getLogoutUrl(ClientInterface client, RegisterSiteResponse site, String postLogoutRedirectUrl) {
    final GetLogoutUrlParams logoutParams = new GetLogoutUrlParams();
    logoutParams.setRpId(site.getRpId());
    logoutParams.setIdTokenHint("dummy_token");
    logoutParams.setPostLogoutRedirectUri(postLogoutRedirectUrl);
    logoutParams.setState(UUID.randomUUID().toString());
    // here must be real session instead of dummy UUID
    logoutParams.setSessionState(UUID.randomUUID().toString());
    final GetLogoutUriResponse resp = client.getLogoutUri(Tester.getAuthorization(), null, logoutParams);
    assertNotNull(resp);
}
Also used : GetLogoutUriResponse(io.jans.ca.common.response.GetLogoutUriResponse)

Example 3 with GetLogoutUriResponse

use of io.jans.ca.common.response.GetLogoutUriResponse in project jans by JanssenProject.

the class GetLogoutUrlTest method test.

@Parameters({ "host", "opHost", "redirectUrls", "postLogoutRedirectUrl" })
@Test
public void test(String host, String opHost, String redirectUrls, String postLogoutRedirectUrl) throws IOException {
    ClientInterface client = Tester.newClient(host);
    final RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, redirectUrls, postLogoutRedirectUrl, "", false);
    final GetLogoutUrlParams params = new GetLogoutUrlParams();
    params.setRpId(site.getRpId());
    params.setIdTokenHint("dummy_token");
    params.setPostLogoutRedirectUri(postLogoutRedirectUrl);
    params.setState(UUID.randomUUID().toString());
    // here must be real session instead of dummy UUID
    params.setSessionState(UUID.randomUUID().toString());
    final GetLogoutUriResponse resp = client.getLogoutUri(Tester.getAuthorization(site), null, params);
    assertNotNull(resp);
    assertTrue(resp.getUri().contains(URLEncoder.encode(postLogoutRedirectUrl, "UTF-8")));
}
Also used : GetLogoutUriResponse(io.jans.ca.common.response.GetLogoutUriResponse) ClientInterface(io.jans.ca.client.ClientInterface) RegisterSiteResponse(io.jans.ca.common.response.RegisterSiteResponse) GetLogoutUrlParams(io.jans.ca.common.params.GetLogoutUrlParams) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Aggregations

GetLogoutUriResponse (io.jans.ca.common.response.GetLogoutUriResponse)3 OpenIdConfigurationResponse (io.jans.as.client.OpenIdConfigurationResponse)1 ClientInterface (io.jans.ca.client.ClientInterface)1 GetLogoutUrlParams (io.jans.ca.common.params.GetLogoutUrlParams)1 RegisterSiteResponse (io.jans.ca.common.response.RegisterSiteResponse)1 HttpException (io.jans.ca.server.HttpException)1 ConfigurationService (io.jans.ca.server.service.ConfigurationService)1 Rp (io.jans.ca.server.service.Rp)1 Parameters (org.testng.annotations.Parameters)1 Test (org.testng.annotations.Test)1