keycloak-service
公開メンバ関数 | 静的公開変数類 | 関数 | 非公開変数類 | 静的非公開変数類 | 全メンバ一覧
org.keycloak.services.managers.AuthenticationSessionManager クラス
org.keycloak.services.managers.AuthenticationSessionManager 連携図
Collaboration graph

公開メンバ関数

 AuthenticationSessionManager (KeycloakSession session)
 
RootAuthenticationSessionModel createAuthenticationSession (RealmModel realm, boolean browserCookie)
 
RootAuthenticationSessionModel getCurrentRootAuthenticationSession (RealmModel realm)
 
UserSessionModel getUserSessionFromAuthCookie (RealmModel realm)
 
AuthenticationSessionModel getCurrentAuthenticationSession (RealmModel realm, ClientModel client, String tabId)
 
void setAuthSessionCookie (String authSessionId, RealmModel realm)
 
void removeAuthenticationSession (RealmModel realm, AuthenticationSessionModel authSession, boolean expireRestartCookie)
 
UserSessionModel getUserSession (AuthenticationSessionModel authSession)
 
AuthenticationSessionModel getAuthenticationSessionByIdAndClient (RealmModel realm, String authSessionId, ClientModel client, String tabId)
 

静的公開変数類

static final String AUTH_SESSION_ID = "AUTH_SESSION_ID"
 
static final int AUTH_SESSION_LIMIT = 3
 

関数

AuthSessionId decodeAuthSessionId (String encodedAuthSessionId)
 
void reencodeAuthSessionCookie (String oldEncodedAuthSessionId, AuthSessionId newAuthSessionId, RealmModel realm)
 
List< String > getAuthSessionCookies (RealmModel realm)
 

非公開変数類

final KeycloakSession session
 

静的非公開変数類

static final Logger log = Logger.getLogger(AuthenticationSessionManager.class)
 

詳解

著者
Marek Posolda

構築子と解体子

◆ AuthenticationSessionManager()

org.keycloak.services.managers.AuthenticationSessionManager.AuthenticationSessionManager ( KeycloakSession  session)
inline
52  {
53  this.session = session;
54  }
final KeycloakSession session
Definition: AuthenticationSessionManager.java:50

関数詳解

◆ createAuthenticationSession()

RootAuthenticationSessionModel org.keycloak.services.managers.AuthenticationSessionManager.createAuthenticationSession ( RealmModel  realm,
boolean  browserCookie 
)
inline

Creates a fresh authentication session for the given realm . Optionally sets the browser authentication session cookie AUTH_SESSION_ID with the ID of the new session.

引数
realm
browserCookieSet the cookie in the browser for the
戻り値
64  {
65  RootAuthenticationSessionModel rootAuthSession = session.authenticationSessions().createRootAuthenticationSession(realm);
66 
67  if (browserCookie) {
68  setAuthSessionCookie(rootAuthSession.getId(), realm);
69  }
70 
71  return rootAuthSession;
72  }
final KeycloakSession session
Definition: AuthenticationSessionManager.java:50
void setAuthSessionCookie(String authSessionId, RealmModel realm)
Definition: AuthenticationSessionManager.java:141

◆ decodeAuthSessionId()

AuthSessionId org.keycloak.services.managers.AuthenticationSessionManager.decodeAuthSessionId ( String  encodedAuthSessionId)
inlinepackage
引数
encodedAuthSessionIdencoded ID with attached route in cluster environment (EG. "5e161e00-d426-4ea6-98e9-52eb9844e2d7.node1" )
戻り値
object with decoded and actually encoded authSessionId
161  {
162  log.debugf("Found AUTH_SESSION_ID cookie with value %s", encodedAuthSessionId);
163  StickySessionEncoderProvider encoder = session.getProvider(StickySessionEncoderProvider.class);
164  String decodedAuthSessionId = encoder.decodeSessionId(encodedAuthSessionId);
165  String reencoded = encoder.encodeSessionId(decodedAuthSessionId);
166 
167  return new AuthSessionId(decodedAuthSessionId, reencoded);
168  }
static final Logger log
Definition: AuthenticationSessionManager.java:48
final KeycloakSession session
Definition: AuthenticationSessionManager.java:50

◆ getAuthenticationSessionByIdAndClient()

AuthenticationSessionModel org.keycloak.services.managers.AuthenticationSessionManager.getAuthenticationSessionByIdAndClient ( RealmModel  realm,
String  authSessionId,
ClientModel  client,
String  tabId 
)
inline
223  {
224  RootAuthenticationSessionModel rootAuthSession = session.authenticationSessions().getRootAuthenticationSession(realm, authSessionId);
225  return rootAuthSession==null ? null : rootAuthSession.getAuthenticationSession(client, tabId);
226  }
final KeycloakSession session
Definition: AuthenticationSessionManager.java:50

◆ getAuthSessionCookies()

List<String> org.keycloak.services.managers.AuthenticationSessionManager.getAuthSessionCookies ( RealmModel  realm)
inlinepackage
引数
realm
戻り値
list of the values of AUTH_SESSION_ID cookies. It is assumed that values could be encoded with route added (EG. "5e161e00-d426-4ea6-98e9-52eb9844e2d7.node1" )
184  {
185  Set<String> cookiesVal = CookieHelper.getCookieValue(AUTH_SESSION_ID);
186 
187  if (cookiesVal.size() > 1) {
188  AuthenticationManager.expireOldAuthSessionCookie(realm, session.getContext().getUri(), session.getContext().getConnection());
189  }
190 
191  List<String> authSessionIds = cookiesVal.stream().limit(AUTH_SESSION_LIMIT).collect(Collectors.toList());
192 
193  if (authSessionIds.isEmpty()) {
194  log.debugf("Not found AUTH_SESSION_ID cookie");
195  }
196 
197  return authSessionIds;
198  }
static final Logger log
Definition: AuthenticationSessionManager.java:48
static final int AUTH_SESSION_LIMIT
Definition: AuthenticationSessionManager.java:46
final KeycloakSession session
Definition: AuthenticationSessionManager.java:50
static final String AUTH_SESSION_ID
Definition: AuthenticationSessionManager.java:44

◆ getCurrentAuthenticationSession()

AuthenticationSessionModel org.keycloak.services.managers.AuthenticationSessionManager.getCurrentAuthenticationSession ( RealmModel  realm,
ClientModel  client,
String  tabId 
)
inline

Returns current authentication session if it exists, otherwise returns

null

.

引数
realm
戻り値
118  {
119  List<String> authSessionCookies = getAuthSessionCookies(realm);
120 
121  return authSessionCookies.stream().map(oldEncodedId -> {
122  AuthSessionId authSessionId = decodeAuthSessionId(oldEncodedId);
123  String sessionId = authSessionId.getDecodedId();
124 
125  AuthenticationSessionModel authSession = getAuthenticationSessionByIdAndClient(realm, sessionId, client, tabId);
126 
127  if (authSession != null) {
128  reencodeAuthSessionCookie(oldEncodedId, authSessionId, realm);
129  return authSession;
130  }
131 
132  return null;
133  }).filter(authSession -> Objects.nonNull(authSession)).findFirst().orElse(null);
134  }
void reencodeAuthSessionCookie(String oldEncodedAuthSessionId, AuthSessionId newAuthSessionId, RealmModel realm)
Definition: AuthenticationSessionManager.java:171
AuthSessionId decodeAuthSessionId(String encodedAuthSessionId)
Definition: AuthenticationSessionManager.java:161
AuthenticationSessionModel getAuthenticationSessionByIdAndClient(RealmModel realm, String authSessionId, ClientModel client, String tabId)
Definition: AuthenticationSessionManager.java:223
List< String > getAuthSessionCookies(RealmModel realm)
Definition: AuthenticationSessionManager.java:184

◆ getCurrentRootAuthenticationSession()

RootAuthenticationSessionModel org.keycloak.services.managers.AuthenticationSessionManager.getCurrentRootAuthenticationSession ( RealmModel  realm)
inline
75  {
76  List<String> authSessionCookies = getAuthSessionCookies(realm);
77 
78  return authSessionCookies.stream().map(oldEncodedId -> {
79  AuthSessionId authSessionId = decodeAuthSessionId(oldEncodedId);
80  String sessionId = authSessionId.getDecodedId();
81 
82  RootAuthenticationSessionModel rootAuthSession = session.authenticationSessions().getRootAuthenticationSession(realm, sessionId);
83 
84  if (rootAuthSession != null) {
85  reencodeAuthSessionCookie(oldEncodedId, authSessionId, realm);
86  return rootAuthSession;
87  }
88 
89  return null;
90  }).filter(authSession -> Objects.nonNull(authSession)).findFirst().orElse(null);
91  }
void reencodeAuthSessionCookie(String oldEncodedAuthSessionId, AuthSessionId newAuthSessionId, RealmModel realm)
Definition: AuthenticationSessionManager.java:171
AuthSessionId decodeAuthSessionId(String encodedAuthSessionId)
Definition: AuthenticationSessionManager.java:161
final KeycloakSession session
Definition: AuthenticationSessionManager.java:50
List< String > getAuthSessionCookies(RealmModel realm)
Definition: AuthenticationSessionManager.java:184

◆ getUserSession()

UserSessionModel org.keycloak.services.managers.AuthenticationSessionManager.getUserSession ( AuthenticationSessionModel  authSession)
inline
217  {
218  return session.sessions().getUserSession(authSession.getRealm(), authSession.getParentSession().getId());
219  }
final KeycloakSession session
Definition: AuthenticationSessionManager.java:50

◆ getUserSessionFromAuthCookie()

UserSessionModel org.keycloak.services.managers.AuthenticationSessionManager.getUserSessionFromAuthCookie ( RealmModel  realm)
inline
94  {
95  List<String> authSessionCookies = getAuthSessionCookies(realm);
96 
97  return authSessionCookies.stream().map(oldEncodedId -> {
98  AuthSessionId authSessionId = decodeAuthSessionId(oldEncodedId);
99  String sessionId = authSessionId.getDecodedId();
100 
101  UserSessionModel userSession = session.sessions().getUserSession(realm, sessionId);
102 
103  if (userSession != null) {
104  reencodeAuthSessionCookie(oldEncodedId, authSessionId, realm);
105  return userSession;
106  }
107 
108  return null;
109  }).filter(authSession -> Objects.nonNull(authSession)).findFirst().orElse(null);
110  }
void reencodeAuthSessionCookie(String oldEncodedAuthSessionId, AuthSessionId newAuthSessionId, RealmModel realm)
Definition: AuthenticationSessionManager.java:171
AuthSessionId decodeAuthSessionId(String encodedAuthSessionId)
Definition: AuthenticationSessionManager.java:161
final KeycloakSession session
Definition: AuthenticationSessionManager.java:50
List< String > getAuthSessionCookies(RealmModel realm)
Definition: AuthenticationSessionManager.java:184

◆ reencodeAuthSessionCookie()

void org.keycloak.services.managers.AuthenticationSessionManager.reencodeAuthSessionCookie ( String  oldEncodedAuthSessionId,
AuthSessionId  newAuthSessionId,
RealmModel  realm 
)
inlinepackage
171  {
172  if (!oldEncodedAuthSessionId.equals(newAuthSessionId.getEncodedId())) {
173  log.debugf("Route changed. Will update authentication session cookie. Old: '%s', New: '%s'", oldEncodedAuthSessionId,
174  newAuthSessionId.getEncodedId());
175  setAuthSessionCookie(newAuthSessionId.getDecodedId(), realm);
176  }
177  }
static final Logger log
Definition: AuthenticationSessionManager.java:48
void setAuthSessionCookie(String authSessionId, RealmModel realm)
Definition: AuthenticationSessionManager.java:141

◆ removeAuthenticationSession()

void org.keycloak.services.managers.AuthenticationSessionManager.removeAuthenticationSession ( RealmModel  realm,
AuthenticationSessionModel  authSession,
boolean  expireRestartCookie 
)
inline
201  {
202  RootAuthenticationSessionModel rootAuthSession = authSession.getParentSession();
203 
204  log.debugf("Removing authSession '%s'. Expire restart cookie: %b", rootAuthSession.getId(), expireRestartCookie);
205  session.authenticationSessions().removeRootAuthenticationSession(realm, rootAuthSession);
206 
207  // expire restart cookie
208  if (expireRestartCookie) {
209  ClientConnection clientConnection = session.getContext().getConnection();
210  UriInfo uriInfo = session.getContext().getUri();
211  RestartLoginCookie.expireRestartCookie(realm, clientConnection, uriInfo);
212  }
213  }
static final Logger log
Definition: AuthenticationSessionManager.java:48
final KeycloakSession session
Definition: AuthenticationSessionManager.java:50

◆ setAuthSessionCookie()

void org.keycloak.services.managers.AuthenticationSessionManager.setAuthSessionCookie ( String  authSessionId,
RealmModel  realm 
)
inline
引数
authSessionIddecoded authSessionId (without route info attached)
realm
141  {
142  UriInfo uriInfo = session.getContext().getUri();
143  String cookiePath = AuthenticationManager.getRealmCookiePath(realm, uriInfo);
144 
145  boolean sslRequired = realm.getSslRequired().isRequired(session.getContext().getConnection());
146 
147  StickySessionEncoderProvider encoder = session.getProvider(StickySessionEncoderProvider.class);
148  String encodedAuthSessionId = encoder.encodeSessionId(authSessionId);
149 
150  CookieHelper.addCookie(AUTH_SESSION_ID, encodedAuthSessionId, cookiePath, null, null, -1, sslRequired, true);
151 
152  log.debugf("Set AUTH_SESSION_ID cookie with value %s", encodedAuthSessionId);
153  }
static final Logger log
Definition: AuthenticationSessionManager.java:48
final KeycloakSession session
Definition: AuthenticationSessionManager.java:50
static final String AUTH_SESSION_ID
Definition: AuthenticationSessionManager.java:44

メンバ詳解

◆ AUTH_SESSION_ID

final String org.keycloak.services.managers.AuthenticationSessionManager.AUTH_SESSION_ID = "AUTH_SESSION_ID"
static

◆ AUTH_SESSION_LIMIT

final int org.keycloak.services.managers.AuthenticationSessionManager.AUTH_SESSION_LIMIT = 3
static

◆ log

final Logger org.keycloak.services.managers.AuthenticationSessionManager.log = Logger.getLogger(AuthenticationSessionManager.class)
staticprivate

◆ session

final KeycloakSession org.keycloak.services.managers.AuthenticationSessionManager.session
private

このクラス詳解は次のファイルから抽出されました: