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);
}
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);
}
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")));
}
Aggregations