KEYCLOAK-10209 - AuthenticationSessionModel made available through
KeycloakContext in KeycloakSession
This commit is contained in:
parent
8b203d48ce
commit
4571f65d1e
5 changed files with 37 additions and 4 deletions
|
@ -99,6 +99,7 @@ public class RootAuthenticationSessionAdapter implements RootAuthenticationSessi
|
||||||
|
|
||||||
AuthenticationSessionModel authSession = getAuthenticationSessions().get(tabId);
|
AuthenticationSessionModel authSession = getAuthenticationSessions().get(tabId);
|
||||||
if (authSession != null && client.equals(authSession.getClient())) {
|
if (authSession != null && client.equals(authSession.getClient())) {
|
||||||
|
session.getContext().setAuthenticationSession(authSession);
|
||||||
return authSession;
|
return authSession;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
@ -118,7 +119,9 @@ public class RootAuthenticationSessionAdapter implements RootAuthenticationSessi
|
||||||
|
|
||||||
update();
|
update();
|
||||||
|
|
||||||
return new AuthenticationSessionAdapter(session, this, tabId, authSessionEntity);
|
AuthenticationSessionAdapter authSession = new AuthenticationSessionAdapter(session, this, tabId, authSessionEntity);
|
||||||
|
session.getContext().setAuthenticationSession(authSession);
|
||||||
|
return authSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -18,9 +18,9 @@
|
||||||
package org.keycloak.models;
|
package org.keycloak.models;
|
||||||
|
|
||||||
import org.keycloak.common.ClientConnection;
|
import org.keycloak.common.ClientConnection;
|
||||||
|
import org.keycloak.sessions.AuthenticationSessionModel;
|
||||||
|
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
import javax.ws.rs.core.UriInfo;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
@ -52,5 +52,13 @@ public interface KeycloakContext {
|
||||||
void setConnection(ClientConnection connection);
|
void setConnection(ClientConnection connection);
|
||||||
|
|
||||||
Locale resolveLocale(UserModel user);
|
Locale resolveLocale(UserModel user);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current AuthenticationSessionModel, can be null out of the AuthenticationSession context.
|
||||||
|
*
|
||||||
|
* @return current AuthenticationSessionModel or null
|
||||||
|
*/
|
||||||
|
AuthenticationSessionModel getAuthenticationSession();
|
||||||
|
|
||||||
|
void setAuthenticationSession(AuthenticationSessionModel authenticationSession);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.keycloak.events.EventListenerProvider;
|
||||||
import org.keycloak.events.admin.AdminEvent;
|
import org.keycloak.events.admin.AdminEvent;
|
||||||
import org.keycloak.models.KeycloakContext;
|
import org.keycloak.models.KeycloakContext;
|
||||||
import org.keycloak.models.KeycloakSession;
|
import org.keycloak.models.KeycloakSession;
|
||||||
|
import org.keycloak.sessions.AuthenticationSessionModel;
|
||||||
|
|
||||||
import javax.ws.rs.core.Cookie;
|
import javax.ws.rs.core.Cookie;
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
@ -84,6 +85,14 @@ public class JBossLoggingEventListenerProvider implements EventListenerProvider
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AuthenticationSessionModel authSession = session.getContext().getAuthenticationSession();
|
||||||
|
if(authSession!=null) {
|
||||||
|
sb.append(", authSessionParentId=");
|
||||||
|
sb.append(authSession.getParentSession().getId());
|
||||||
|
sb.append(", authSessionTabId=");
|
||||||
|
sb.append(authSession.getTabId());
|
||||||
|
}
|
||||||
|
|
||||||
if(logger.isTraceEnabled()) {
|
if(logger.isTraceEnabled()) {
|
||||||
setKeycloakContext(sb);
|
setKeycloakContext(sb);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import org.keycloak.models.KeycloakUriInfo;
|
||||||
import org.keycloak.models.RealmModel;
|
import org.keycloak.models.RealmModel;
|
||||||
import org.keycloak.models.UserModel;
|
import org.keycloak.models.UserModel;
|
||||||
import org.keycloak.services.resources.KeycloakApplication;
|
import org.keycloak.services.resources.KeycloakApplication;
|
||||||
|
import org.keycloak.sessions.AuthenticationSessionModel;
|
||||||
|
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
import javax.ws.rs.core.UriInfo;
|
import javax.ws.rs.core.UriInfo;
|
||||||
|
@ -47,6 +48,8 @@ public class DefaultKeycloakContext implements KeycloakContext {
|
||||||
private KeycloakSession session;
|
private KeycloakSession session;
|
||||||
|
|
||||||
private KeycloakUriInfo uriInfo;
|
private KeycloakUriInfo uriInfo;
|
||||||
|
|
||||||
|
private AuthenticationSessionModel authenticationSession;
|
||||||
|
|
||||||
public DefaultKeycloakContext(KeycloakSession session) {
|
public DefaultKeycloakContext(KeycloakSession session) {
|
||||||
this.session = session;
|
this.session = session;
|
||||||
|
@ -119,4 +122,14 @@ public class DefaultKeycloakContext implements KeycloakContext {
|
||||||
public Locale resolveLocale(UserModel user) {
|
public Locale resolveLocale(UserModel user) {
|
||||||
return session.getProvider(LocaleSelectorProvider.class).resolveLocale(realm, user);
|
return session.getProvider(LocaleSelectorProvider.class).resolveLocale(realm, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AuthenticationSessionModel getAuthenticationSession() {
|
||||||
|
return authenticationSession;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setAuthenticationSession(AuthenticationSessionModel authenticationSession) {
|
||||||
|
this.authenticationSession = authenticationSession;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -299,12 +299,12 @@ public class AuthenticationManager {
|
||||||
|
|
||||||
// See if we have logoutAuthSession inside current rootSession. Create new if not
|
// See if we have logoutAuthSession inside current rootSession. Create new if not
|
||||||
Optional<AuthenticationSessionModel> found = rootLogoutSession.getAuthenticationSessions().values().stream().filter((AuthenticationSessionModel authSession) -> {
|
Optional<AuthenticationSessionModel> found = rootLogoutSession.getAuthenticationSessions().values().stream().filter((AuthenticationSessionModel authSession) -> {
|
||||||
|
|
||||||
return client.equals(authSession.getClient()) && Objects.equals(AuthenticationSessionModel.Action.LOGGING_OUT.name(), authSession.getAction());
|
return client.equals(authSession.getClient()) && Objects.equals(AuthenticationSessionModel.Action.LOGGING_OUT.name(), authSession.getAction());
|
||||||
|
|
||||||
}).findFirst();
|
}).findFirst();
|
||||||
|
|
||||||
AuthenticationSessionModel logoutAuthSession = found.isPresent() ? found.get() : rootLogoutSession.createAuthenticationSession(client);
|
AuthenticationSessionModel logoutAuthSession = found.isPresent() ? found.get() : rootLogoutSession.createAuthenticationSession(client);
|
||||||
|
session.getContext().setAuthenticationSession(logoutAuthSession);
|
||||||
|
|
||||||
logoutAuthSession.setAction(AuthenticationSessionModel.Action.LOGGING_OUT.name());
|
logoutAuthSession.setAction(AuthenticationSessionModel.Action.LOGGING_OUT.name());
|
||||||
return logoutAuthSession;
|
return logoutAuthSession;
|
||||||
|
|
Loading…
Reference in a new issue