Search in sources :

Example 1 with LogoutAction

use of org.keycloak.representations.adapters.action.LogoutAction in project keycloak by keycloak.

the class PreAuthActionsHandler method handleLogout.

protected void handleLogout() {
    if (log.isTraceEnabled()) {
        log.trace("K_LOGOUT sent");
    }
    try {
        JWSInput token = verifyAdminRequest();
        if (token == null) {
            return;
        }
        LogoutAction action = JsonSerialization.readValue(token.getContent(), LogoutAction.class);
        if (!validateAction(action))
            return;
        if (action.getAdapterSessionIds() != null) {
            userSessionManagement.logoutHttpSessions(action.getAdapterSessionIds());
        } else {
            log.debugf("logout of all sessions for application '%s'", action.getResource());
            if (action.getNotBefore() > deployment.getNotBefore()) {
                deployment.updateNotBefore(action.getNotBefore());
            }
            userSessionManagement.logoutAll();
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : LogoutAction(org.keycloak.representations.adapters.action.LogoutAction) JWSInput(org.keycloak.jose.jws.JWSInput) VerificationException(org.keycloak.common.VerificationException)

Example 2 with LogoutAction

use of org.keycloak.representations.adapters.action.LogoutAction in project keycloak by keycloak.

the class ResourceAdminManager method sendLogoutRequest.

protected Response sendLogoutRequest(RealmModel realm, ClientModel resource, List<String> adapterSessionIds, List<String> userSessions, int notBefore, String managementUrl) {
    LogoutAction adminAction = new LogoutAction(TokenIdGenerator.generateId(), Time.currentTime() + 30, resource.getClientId(), adapterSessionIds, notBefore, userSessions);
    String token = session.tokens().encode(adminAction);
    if (logger.isDebugEnabled())
        logger.debugv("logout resource {0} url: {1} sessionIds: " + adapterSessionIds, resource.getClientId(), managementUrl);
    URI target = UriBuilder.fromUri(managementUrl).path(AdapterConstants.K_LOGOUT).build();
    try {
        int status = session.getProvider(HttpClientProvider.class).postText(target.toString(), token);
        boolean success = status == 204 || status == 200;
        logger.debugf("logout success for %s: %s", managementUrl, success);
        return Response.ok().build();
    } catch (IOException e) {
        ServicesLogger.LOGGER.logoutFailed(e, resource.getClientId());
        return Response.serverError().build();
    }
}
Also used : LogoutAction(org.keycloak.representations.adapters.action.LogoutAction) HttpClientProvider(org.keycloak.connections.httpclient.HttpClientProvider) IOException(java.io.IOException) URI(java.net.URI)

Aggregations

LogoutAction (org.keycloak.representations.adapters.action.LogoutAction)2 IOException (java.io.IOException)1 URI (java.net.URI)1 VerificationException (org.keycloak.common.VerificationException)1 HttpClientProvider (org.keycloak.connections.httpclient.HttpClientProvider)1 JWSInput (org.keycloak.jose.jws.JWSInput)1