keycloak-service
公開メンバ関数 | 静的公開メンバ関数 | 静的公開変数類 | 静的限定公開メンバ関数 | 静的限定公開変数類 | 全メンバ一覧
org.keycloak.services.managers.AppAuthManager クラス
org.keycloak.services.managers.AppAuthManager の継承関係図
Inheritance graph
org.keycloak.services.managers.AppAuthManager 連携図
Collaboration graph

公開メンバ関数

AuthResult authenticateIdentityCookie (KeycloakSession session, RealmModel realm)
 
String extractAuthorizationHeaderToken (HttpHeaders headers)
 
AuthResult authenticateBearerToken (KeycloakSession session, RealmModel realm)
 
AuthResult authenticateBearerToken (KeycloakSession session)
 
AuthResult authenticateBearerToken (KeycloakSession session, RealmModel realm, UriInfo uriInfo, ClientConnection connection, HttpHeaders headers)
 
AuthResult authenticateBearerToken (String tokenString, KeycloakSession session, RealmModel realm, UriInfo uriInfo, ClientConnection connection, HttpHeaders headers)
 

静的公開メンバ関数

static boolean isSessionValid (RealmModel realm, UserSessionModel userSession)
 
static boolean isOfflineSessionValid (RealmModel realm, UserSessionModel userSession)
 
static void expireUserSessionCookie (KeycloakSession session, UserSessionModel userSession, RealmModel realm, UriInfo uriInfo, HttpHeaders headers, ClientConnection connection)
 
static void backchannelLogout (KeycloakSession session, UserSessionModel userSession, boolean logoutBroker)
 
static void backchannelLogout (KeycloakSession session, RealmModel realm, UserSessionModel userSession, UriInfo uriInfo, ClientConnection connection, HttpHeaders headers, boolean logoutBroker)
 
static void backchannelLogout (KeycloakSession session, RealmModel realm, UserSessionModel userSession, UriInfo uriInfo, ClientConnection connection, HttpHeaders headers, boolean logoutBroker, boolean offlineSession)
 
static void setClientLogoutAction (AuthenticationSessionModel logoutAuthSession, String clientUuid, AuthenticationSessionModel.Action action)
 
static AuthenticationSessionModel.Action getClientLogoutAction (AuthenticationSessionModel logoutAuthSession, String clientUuid)
 
static void backchannelLogoutUserFromClient (KeycloakSession session, RealmModel realm, UserModel user, ClientModel client, UriInfo uriInfo, HttpHeaders headers)
 
static Response browserLogout (KeycloakSession session, RealmModel realm, UserSessionModel userSession, UriInfo uriInfo, ClientConnection connection, HttpHeaders headers)
 
static Response finishBrowserLogout (KeycloakSession session, RealmModel realm, UserSessionModel userSession, UriInfo uriInfo, ClientConnection connection, HttpHeaders headers)
 
static IdentityCookieToken createIdentityToken (KeycloakSession keycloakSession, RealmModel realm, UserModel user, UserSessionModel session, String issuer)
 
static void createLoginCookie (KeycloakSession keycloakSession, RealmModel realm, UserModel user, UserSessionModel session, UriInfo uriInfo, ClientConnection connection)
 
static void createRememberMeCookie (RealmModel realm, String username, UriInfo uriInfo, ClientConnection connection)
 
static String getRememberMeUsername (RealmModel realm, HttpHeaders headers)
 
static void expireIdentityCookie (RealmModel realm, UriInfo uriInfo, ClientConnection connection)
 
static void expireOldIdentityCookie (RealmModel realm, UriInfo uriInfo, ClientConnection connection)
 
static void expireRememberMeCookie (RealmModel realm, UriInfo uriInfo, ClientConnection connection)
 
static void expireOldAuthSessionCookie (RealmModel realm, UriInfo uriInfo, ClientConnection connection)
 
static String getRealmCookiePath (RealmModel realm, UriInfo uriInfo)
 
static String getOldCookiePath (RealmModel realm, UriInfo uriInfo)
 
static String getAccountCookiePath (RealmModel realm, UriInfo uriInfo)
 
static void expireCookie (RealmModel realm, String cookieName, String path, boolean httpOnly, ClientConnection connection)
 
static AuthResult authenticateIdentityCookie (KeycloakSession session, RealmModel realm, boolean checkActive)
 
static Response redirectAfterSuccessfulFlow (KeycloakSession session, RealmModel realm, UserSessionModel userSession, ClientSessionContext clientSessionCtx, HttpRequest request, UriInfo uriInfo, ClientConnection clientConnection, EventBuilder event, String protocol)
 
static Response redirectAfterSuccessfulFlow (KeycloakSession session, RealmModel realm, UserSessionModel userSession, ClientSessionContext clientSessionCtx, HttpRequest request, UriInfo uriInfo, ClientConnection clientConnection, EventBuilder event, LoginProtocol protocol)
 
static boolean isSSOAuthentication (AuthenticatedClientSessionModel clientSession)
 
static Response nextActionAfterAuthentication (KeycloakSession session, AuthenticationSessionModel authSession, ClientConnection clientConnection, HttpRequest request, UriInfo uriInfo, EventBuilder event)
 
static Response redirectToRequiredActions (KeycloakSession session, RealmModel realm, AuthenticationSessionModel authSession, UriInfo uriInfo, String requiredAction)
 
static Response finishedRequiredActions (KeycloakSession session, AuthenticationSessionModel authSession, UserSessionModel userSession, ClientConnection clientConnection, HttpRequest request, UriInfo uriInfo, EventBuilder event)
 
static String nextRequiredAction (final KeycloakSession session, final AuthenticationSessionModel authSession, final ClientConnection clientConnection, final HttpRequest request, final UriInfo uriInfo, final EventBuilder event)
 
static Response actionRequired (final KeycloakSession session, final AuthenticationSessionModel authSession, final ClientConnection clientConnection, final HttpRequest request, final UriInfo uriInfo, final EventBuilder event)
 
static void setClientScopesInSession (AuthenticationSessionModel authSession)
 
static RequiredActionProvider createRequiredAction (RequiredActionContextResult context)
 
static void evaluateRequiredActionTriggers (final KeycloakSession session, final AuthenticationSessionModel authSession, final ClientConnection clientConnection, final HttpRequest request, final UriInfo uriInfo, final EventBuilder event, final RealmModel realm, final UserModel user)
 
static AuthResult verifyIdentityToken (KeycloakSession session, RealmModel realm, UriInfo uriInfo, ClientConnection connection, boolean checkActive, boolean checkTokenType, boolean isCookie, String tokenString, HttpHeaders headers)
 

静的公開変数類

static final String SET_REDIRECT_URI_AFTER_REQUIRED_ACTIONS = "SET_REDIRECT_URI_AFTER_REQUIRED_ACTIONS"
 
static final String END_AFTER_REQUIRED_ACTIONS = "END_AFTER_REQUIRED_ACTIONS"
 
static final String INVALIDATE_ACTION_TOKEN = "INVALIDATE_ACTION_TOKEN"
 
static final String CLIENT_LOGOUT_STATE = "logout.state."
 
static final String AUTH_TIME = "AUTH_TIME"
 
static final String SSO_AUTH = "SSO_AUTH"
 
static final String FORM_USERNAME = "username"
 
static final String KEYCLOAK_IDENTITY_COOKIE = "KEYCLOAK_IDENTITY"
 
static final String KEYCLOAK_SESSION_COOKIE = "KEYCLOAK_SESSION"
 
static final String KEYCLOAK_REMEMBER_ME = "KEYCLOAK_REMEMBER_ME"
 
static final String KEYCLOAK_LOGOUT_PROTOCOL = "KEYCLOAK_LOGOUT_PROTOCOL"
 

静的限定公開メンバ関数

static String getIdentityCookiePath (RealmModel realm, UriInfo uriInfo)
 
static Response executionActions (KeycloakSession session, AuthenticationSessionModel authSession, HttpRequest request, EventBuilder event, RealmModel realm, UserModel user, Set< String > requiredActions)
 

静的限定公開変数類

static final Logger logger = Logger.getLogger(AuthenticationManager.class)
 

詳解

著者
Bill Burke
Stian Thorgersen

関数詳解

◆ actionRequired()

static Response org.keycloak.services.managers.AuthenticationManager.actionRequired ( final KeycloakSession  session,
final AuthenticationSessionModel  authSession,
final ClientConnection  clientConnection,
final HttpRequest  request,
final UriInfo  uriInfo,
final EventBuilder  event 
)
inlinestaticinherited
918  {
919  final RealmModel realm = authSession.getRealm();
920  final UserModel user = authSession.getAuthenticatedUser();
921  final ClientModel client = authSession.getClient();
922 
923  evaluateRequiredActionTriggers(session, authSession, clientConnection, request, uriInfo, event, realm, user);
924 
925 
926  logger.debugv("processAccessCode: go to oauth page?: {0}", client.isConsentRequired());
927 
928  event.detail(Details.CODE_ID, authSession.getParentSession().getId());
929 
930  Set<String> requiredActions = user.getRequiredActions();
931  Response action = executionActions(session, authSession, request, event, realm, user, requiredActions);
932  if (action != null) return action;
933 
934  // executionActions() method should remove any duplicate actions that might be in the clientSession
935  requiredActions = authSession.getRequiredActions();
936  action = executionActions(session, authSession, request, event, realm, user, requiredActions);
937  if (action != null) return action;
938 
939  if (client.isConsentRequired()) {
940 
941  UserConsentModel grantedConsent = getEffectiveGrantedConsent(session, authSession);
942 
943  List<ClientScopeModel> clientScopesToApprove = getClientScopesToApproveOnConsentScreen(realm, grantedConsent, authSession);
944 
945  // Skip grant screen if everything was already approved by this user
946  if (clientScopesToApprove.size() > 0) {
947  String execution = AuthenticatedClientSessionModel.Action.OAUTH_GRANT.name();
948 
949  ClientSessionCode<AuthenticationSessionModel> accessCode = new ClientSessionCode<>(session, realm, authSession);
950  accessCode.setAction(AuthenticatedClientSessionModel.Action.REQUIRED_ACTIONS.name());
951  authSession.setAuthNote(AuthenticationProcessor.CURRENT_AUTHENTICATION_EXECUTION, execution);
952 
953  return session.getProvider(LoginFormsProvider.class)
954  .setAuthenticationSession(authSession)
955  .setExecution(execution)
956  .setClientSessionCode(accessCode.getOrGenerateCode())
957  .setAccessRequest(clientScopesToApprove)
958  .createOAuthGrant();
959  } else {
960  String consentDetail = (grantedConsent != null) ? Details.CONSENT_VALUE_PERSISTED_CONSENT : Details.CONSENT_VALUE_NO_CONSENT_REQUIRED;
961  event.detail(Details.CONSENT, consentDetail);
962  }
963  } else {
964  event.detail(Details.CONSENT, Details.CONSENT_VALUE_NO_CONSENT_REQUIRED);
965  }
966  return null;
967 
968  }
static List< ClientScopeModel > getClientScopesToApproveOnConsentScreen(RealmModel realm, UserConsentModel grantedConsent, AuthenticationSessionModel authSession)
Definition: AuthenticationManager.java:970
static void evaluateRequiredActionTriggers(final KeycloakSession session, final AuthenticationSessionModel authSession, final ClientConnection clientConnection, final HttpRequest request, final UriInfo uriInfo, final EventBuilder event, final RealmModel realm, final UserModel user)
Definition: AuthenticationManager.java:1090
static final Logger logger
Definition: AuthenticationManager.java:117
static UserConsentModel getEffectiveGrantedConsent(KeycloakSession session, AuthenticationSessionModel authSession)
Definition: AuthenticationManager.java:901
static Response executionActions(KeycloakSession session, AuthenticationSessionModel authSession, HttpRequest request, EventBuilder event, RealmModel realm, UserModel user, Set< String > requiredActions)
Definition: AuthenticationManager.java:1026

◆ authenticateBearerToken() [1/4]

AuthResult org.keycloak.services.managers.AppAuthManager.authenticateBearerToken ( KeycloakSession  session,
RealmModel  realm 
)
inline
56  {
57  KeycloakContext ctx = session.getContext();
58  return authenticateBearerToken(session, realm, ctx.getUri(), ctx.getConnection(), ctx.getRequestHeaders());
59  }
AuthResult authenticateBearerToken(KeycloakSession session, RealmModel realm)
Definition: AppAuthManager.java:56

◆ authenticateBearerToken() [2/4]

AuthResult org.keycloak.services.managers.AppAuthManager.authenticateBearerToken ( KeycloakSession  session)
inline
61  {
62  return authenticateBearerToken(session, session.getContext().getRealm(), session.getContext().getUri(), session.getContext().getConnection(), session.getContext().getRequestHeaders());
63  }
AuthResult authenticateBearerToken(KeycloakSession session, RealmModel realm)
Definition: AppAuthManager.java:56

◆ authenticateBearerToken() [3/4]

AuthResult org.keycloak.services.managers.AppAuthManager.authenticateBearerToken ( KeycloakSession  session,
RealmModel  realm,
UriInfo  uriInfo,
ClientConnection  connection,
HttpHeaders  headers 
)
inline
65  {
66  return authenticateBearerToken(extractAuthorizationHeaderToken(headers), session, realm, uriInfo, connection, headers);
67  }
String extractAuthorizationHeaderToken(HttpHeaders headers)
Definition: AppAuthManager.java:44
AuthResult authenticateBearerToken(KeycloakSession session, RealmModel realm)
Definition: AppAuthManager.java:56

◆ authenticateBearerToken() [4/4]

AuthResult org.keycloak.services.managers.AppAuthManager.authenticateBearerToken ( String  tokenString,
KeycloakSession  session,
RealmModel  realm,
UriInfo  uriInfo,
ClientConnection  connection,
HttpHeaders  headers 
)
inline
69  {
70  if (tokenString == null) return null;
71  AuthResult authResult = verifyIdentityToken(session, realm, uriInfo, connection, true, true, false, tokenString, headers);
72  return authResult;
73  }
static AuthResult verifyIdentityToken(KeycloakSession session, RealmModel realm, UriInfo uriInfo, ClientConnection connection, boolean checkActive, boolean checkTokenType, boolean isCookie, String tokenString, HttpHeaders headers)
Definition: AuthenticationManager.java:1127

◆ authenticateIdentityCookie() [1/2]

AuthResult org.keycloak.services.managers.AppAuthManager.authenticateIdentityCookie ( KeycloakSession  session,
RealmModel  realm 
)
inline
35  {
36  AuthResult authResult = super.authenticateIdentityCookie(session, realm);
37  if (authResult == null) return null;
38  // refresh the cookies!
39  createLoginCookie(session, realm, authResult.getUser(), authResult.getSession(), session.getContext().getUri(), session.getContext().getConnection());
40  if (authResult.getSession().isRememberMe()) createRememberMeCookie(realm, authResult.getUser().getUsername(), session.getContext().getUri(), session.getContext().getConnection());
41  return authResult;
42  }
static void createRememberMeCookie(RealmModel realm, String username, UriInfo uriInfo, ClientConnection connection)
Definition: AuthenticationManager.java:614
static void createLoginCookie(KeycloakSession keycloakSession, RealmModel realm, UserModel user, UserSessionModel session, UriInfo uriInfo, ClientConnection connection)
Definition: AuthenticationManager.java:590

◆ authenticateIdentityCookie() [2/2]

static AuthResult org.keycloak.services.managers.AuthenticationManager.authenticateIdentityCookie ( KeycloakSession  session,
RealmModel  realm,
boolean  checkActive 
)
inlinestaticinherited
699  {
700  Cookie cookie = session.getContext().getRequestHeaders().getCookies().get(KEYCLOAK_IDENTITY_COOKIE);
701  if (cookie == null || "".equals(cookie.getValue())) {
702  logger.debugv("Could not find cookie: {0}", KEYCLOAK_IDENTITY_COOKIE);
703  return null;
704  }
705 
706  String tokenString = cookie.getValue();
707  AuthResult authResult = verifyIdentityToken(session, realm, session.getContext().getUri(), session.getContext().getConnection(), checkActive, false, true, tokenString, session.getContext().getRequestHeaders());
708  if (authResult == null) {
709  expireIdentityCookie(realm, session.getContext().getUri(), session.getContext().getConnection());
710  expireOldIdentityCookie(realm, session.getContext().getUri(), session.getContext().getConnection());
711  return null;
712  }
713  authResult.getSession().setLastSessionRefresh(Time.currentTime());
714  return authResult;
715  }
static AuthResult verifyIdentityToken(KeycloakSession session, RealmModel realm, UriInfo uriInfo, ClientConnection connection, boolean checkActive, boolean checkTokenType, boolean isCookie, String tokenString, HttpHeaders headers)
Definition: AuthenticationManager.java:1127
static void expireOldIdentityCookie(RealmModel realm, UriInfo uriInfo, ClientConnection connection)
Definition: AuthenticationManager.java:646
static void expireIdentityCookie(RealmModel realm, UriInfo uriInfo, ClientConnection connection)
Definition: AuthenticationManager.java:636
static final Logger logger
Definition: AuthenticationManager.java:117
static final String KEYCLOAK_IDENTITY_COOKIE
Definition: AuthenticationManager.java:121

◆ backchannelLogout() [1/3]

static void org.keycloak.services.managers.AuthenticationManager.backchannelLogout ( KeycloakSession  session,
UserSessionModel  userSession,
boolean  logoutBroker 
)
inlinestaticinherited
186  {
188  session,
189  session.getContext().getRealm(),
190  userSession,
191  session.getContext().getUri(),
192  session.getContext().getConnection(),
193  session.getContext().getRequestHeaders(),
194  logoutBroker
195  );
196  }
static void backchannelLogout(KeycloakSession session, UserSessionModel userSession, boolean logoutBroker)
Definition: AuthenticationManager.java:186

◆ backchannelLogout() [2/3]

static void org.keycloak.services.managers.AuthenticationManager.backchannelLogout ( KeycloakSession  session,
RealmModel  realm,
UserSessionModel  userSession,
UriInfo  uriInfo,
ClientConnection  connection,
HttpHeaders  headers,
boolean  logoutBroker 
)
inlinestaticinherited
201  {
202  backchannelLogout(session, realm, userSession, uriInfo, connection, headers, logoutBroker, false);
203  }
static void backchannelLogout(KeycloakSession session, UserSessionModel userSession, boolean logoutBroker)
Definition: AuthenticationManager.java:186

◆ backchannelLogout() [3/3]

static void org.keycloak.services.managers.AuthenticationManager.backchannelLogout ( KeycloakSession  session,
RealmModel  realm,
UserSessionModel  userSession,
UriInfo  uriInfo,
ClientConnection  connection,
HttpHeaders  headers,
boolean  logoutBroker,
boolean  offlineSession 
)
inlinestaticinherited
引数
session
realm
userSession
uriInfo
connection
headers
logoutBroker
offlineSession
220  {
221  if (userSession == null) return;
222  UserModel user = userSession.getUser();
223  if (userSession.getState() != UserSessionModel.State.LOGGING_OUT) {
224  userSession.setState(UserSessionModel.State.LOGGING_OUT);
225  }
226 
227  logger.debugv("Logging out: {0} ({1}) offline: {2}", user.getUsername(), userSession.getId(), userSession.isOffline());
228  expireUserSessionCookie(session, userSession, realm, uriInfo, headers, connection);
229 
230  final AuthenticationSessionManager asm = new AuthenticationSessionManager(session);
231  AuthenticationSessionModel logoutAuthSession = createOrJoinLogoutSession(session, realm, asm, userSession, false);
232 
233  try {
234  backchannelLogoutAll(session, realm, userSession, logoutAuthSession, uriInfo, headers, logoutBroker);
235  checkUserSessionOnlyHasLoggedOutClients(realm, userSession, logoutAuthSession);
236  } finally {
237  asm.removeAuthenticationSession(realm, logoutAuthSession, false);
238  }
239 
240  userSession.setState(UserSessionModel.State.LOGGED_OUT);
241 
242  if (offlineSession) {
243  new UserSessionManager(session).revokeOfflineUserSession(userSession);
244 
245  // Check if "online" session still exists and remove it too
246  UserSessionModel onlineUserSession = session.sessions().getUserSession(realm, userSession.getId());
247  if (onlineUserSession != null) {
248  session.sessions().removeUserSession(realm, onlineUserSession);
249  }
250  } else {
251  session.sessions().removeUserSession(realm, userSession);
252  }
253  }
static void backchannelLogoutAll(KeycloakSession session, RealmModel realm, UserSessionModel userSession, AuthenticationSessionModel logoutAuthSession, UriInfo uriInfo, HttpHeaders headers, boolean logoutBroker)
Definition: AuthenticationManager.java:296
static void expireUserSessionCookie(KeycloakSession session, UserSessionModel userSession, RealmModel realm, UriInfo uriInfo, HttpHeaders headers, ClientConnection connection)
Definition: AuthenticationManager.java:159
static final Logger logger
Definition: AuthenticationManager.java:117
static boolean checkUserSessionOnlyHasLoggedOutClients(RealmModel realm, UserSessionModel userSession, AuthenticationSessionModel logoutAuthSession)
Definition: AuthenticationManager.java:323
static AuthenticationSessionModel createOrJoinLogoutSession(KeycloakSession session, RealmModel realm, final AuthenticationSessionManager asm, UserSessionModel userSession, boolean browserCookie)
Definition: AuthenticationManager.java:255

◆ backchannelLogoutUserFromClient()

static void org.keycloak.services.managers.AuthenticationManager.backchannelLogoutUserFromClient ( KeycloakSession  session,
RealmModel  realm,
UserModel  user,
ClientModel  client,
UriInfo  uriInfo,
HttpHeaders  headers 
)
inlinestaticinherited

Logout all clientSessions of this user and client

引数
session
realm
user
client
uriInfo
headers
480  {
481  List<UserSessionModel> userSessions = session.sessions().getUserSessions(realm, user);
482  for (UserSessionModel userSession : userSessions) {
483  AuthenticatedClientSessionModel clientSession = userSession.getAuthenticatedClientSessionByClient(client.getId());
484  if (clientSession != null) {
485  AuthenticationManager.backchannelLogoutClientSession(session, realm, clientSession, null, uriInfo, headers);
486  clientSession.setAction(AuthenticationSessionModel.Action.LOGGED_OUT.name());
487  org.keycloak.protocol.oidc.TokenManager.dettachClientSession(session.sessions(), realm, clientSession);
488  }
489  }
490  }
Definition: AuthorizationEndpointBase.java:18
Definition: TokenManager.java:84
Definition: AccessTokenIntrospectionProvider.java:18
static void dettachClientSession(UserSessionProvider sessions, RealmModel realm, AuthenticatedClientSessionModel clientSession)
Definition: TokenManager.java:459

◆ browserLogout()

static Response org.keycloak.services.managers.AuthenticationManager.browserLogout ( KeycloakSession  session,
RealmModel  realm,
UserSessionModel  userSession,
UriInfo  uriInfo,
ClientConnection  connection,
HttpHeaders  headers 
)
inlinestaticinherited
492  {
493  if (userSession == null) return null;
494 
495  if (logger.isDebugEnabled()) {
496  UserModel user = userSession.getUser();
497  logger.debugv("Logging out: {0} ({1})", user.getUsername(), userSession.getId());
498  }
499 
500  if (userSession.getState() != UserSessionModel.State.LOGGING_OUT) {
501  userSession.setState(UserSessionModel.State.LOGGING_OUT);
502  }
503 
504  final AuthenticationSessionManager asm = new AuthenticationSessionManager(session);
505  AuthenticationSessionModel logoutAuthSession = createOrJoinLogoutSession(session, realm, asm, userSession, true);
506 
507  Response response = browserLogoutAllClients(userSession, session, realm, headers, uriInfo, logoutAuthSession);
508  if (response != null) {
509  return response;
510  }
511 
512  String brokerId = userSession.getNote(Details.IDENTITY_PROVIDER);
513  if (brokerId != null) {
514  IdentityProvider identityProvider = IdentityBrokerService.getIdentityProvider(session, realm, brokerId);
515  response = identityProvider.keycloakInitiatedBrowserLogout(session, userSession, uriInfo, realm);
516  if (response != null) {
517  return response;
518  }
519  }
520 
521  return finishBrowserLogout(session, realm, userSession, uriInfo, connection, headers);
522  }
static Response finishBrowserLogout(KeycloakSession session, RealmModel realm, UserSessionModel userSession, UriInfo uriInfo, ClientConnection connection, HttpHeaders headers)
Definition: AuthenticationManager.java:544
static Response browserLogoutAllClients(UserSessionModel userSession, KeycloakSession session, RealmModel realm, HttpHeaders headers, UriInfo uriInfo, AuthenticationSessionModel logoutAuthSession)
Definition: AuthenticationManager.java:524
static final Logger logger
Definition: AuthenticationManager.java:117
static AuthenticationSessionModel createOrJoinLogoutSession(KeycloakSession session, RealmModel realm, final AuthenticationSessionManager asm, UserSessionModel userSession, boolean browserCookie)
Definition: AuthenticationManager.java:255

◆ createIdentityToken()

static IdentityCookieToken org.keycloak.services.managers.AuthenticationManager.createIdentityToken ( KeycloakSession  keycloakSession,
RealmModel  realm,
UserModel  user,
UserSessionModel  session,
String  issuer 
)
inlinestaticinherited
567  {
568  IdentityCookieToken token = new IdentityCookieToken();
569  token.id(KeycloakModelUtils.generateId());
570  token.issuedNow();
571  token.subject(user.getId());
572  token.issuer(issuer);
573  if (session != null) {
574  token.setSessionState(session.getId());
575  }
576  if (realm.getSsoSessionMaxLifespan() > 0) {
577  token.expiration(Time.currentTime() + realm.getSsoSessionMaxLifespan());
578  }
579 
580  String stateChecker = (String) keycloakSession.getAttribute("state_checker");
581  if (stateChecker == null) {
582  stateChecker = Base64Url.encode(KeycloakModelUtils.generateSecret());
583  keycloakSession.setAttribute("state_checker", stateChecker);
584  }
585  token.getOtherClaims().put("state_checker", stateChecker);
586 
587  return token;
588  }

◆ createLoginCookie()

static void org.keycloak.services.managers.AuthenticationManager.createLoginCookie ( KeycloakSession  keycloakSession,
RealmModel  realm,
UserModel  user,
UserSessionModel  session,
UriInfo  uriInfo,
ClientConnection  connection 
)
inlinestaticinherited
590  {
591  String cookiePath = getIdentityCookiePath(realm, uriInfo);
592  String issuer = Urls.realmIssuer(uriInfo.getBaseUri(), realm.getName());
593  IdentityCookieToken identityCookieToken = createIdentityToken(keycloakSession, realm, user, session, issuer);
594  String encoded = keycloakSession.tokens().encode(identityCookieToken);
595  boolean secureOnly = realm.getSslRequired().isRequired(connection);
596  int maxAge = NewCookie.DEFAULT_MAX_AGE;
597  if (session != null && session.isRememberMe()) {
598  maxAge = realm.getSsoSessionMaxLifespan();
599  }
600  logger.debugv("Create login cookie - name: {0}, path: {1}, max-age: {2}", KEYCLOAK_IDENTITY_COOKIE, cookiePath, maxAge);
601  CookieHelper.addCookie(KEYCLOAK_IDENTITY_COOKIE, encoded, cookiePath, null, null, maxAge, secureOnly, true);
602  //builder.cookie(new NewCookie(cookieName, encoded, cookiePath, null, null, maxAge, secureOnly));// todo httponly , true);
603 
604  String sessionCookieValue = realm.getName() + "/" + user.getId();
605  if (session != null) {
606  sessionCookieValue += "/" + session.getId();
607  }
608  // THIS SHOULD NOT BE A HTTPONLY COOKIE! It is used for OpenID Connect Iframe Session support!
609  // Max age should be set to the max lifespan of the session as it's used to invalidate old-sessions on re-login
610  CookieHelper.addCookie(KEYCLOAK_SESSION_COOKIE, sessionCookieValue, cookiePath, null, null, realm.getSsoSessionMaxLifespan(), secureOnly, false);
611  P3PHelper.addP3PHeader(keycloakSession);
612  }
static final String KEYCLOAK_SESSION_COOKIE
Definition: AuthenticationManager.java:123
static final Logger logger
Definition: AuthenticationManager.java:117
static final String KEYCLOAK_IDENTITY_COOKIE
Definition: AuthenticationManager.java:121
static IdentityCookieToken createIdentityToken(KeycloakSession keycloakSession, RealmModel realm, UserModel user, UserSessionModel session, String issuer)
Definition: AuthenticationManager.java:567
static String getIdentityCookiePath(RealmModel realm, UriInfo uriInfo)
Definition: AuthenticationManager.java:669

◆ createRememberMeCookie()

static void org.keycloak.services.managers.AuthenticationManager.createRememberMeCookie ( RealmModel  realm,
String  username,
UriInfo  uriInfo,
ClientConnection  connection 
)
inlinestaticinherited
614  {
615  String path = getIdentityCookiePath(realm, uriInfo);
616  boolean secureOnly = realm.getSslRequired().isRequired(connection);
617  // remember me cookie should be persistent (hardcoded to 365 days for now)
618  //NewCookie cookie = new NewCookie(KEYCLOAK_REMEMBER_ME, "true", path, null, null, realm.getCentralLoginLifespan(), secureOnly);// todo httponly , true);
619  CookieHelper.addCookie(KEYCLOAK_REMEMBER_ME, "username:" + username, path, null, null, 31536000, secureOnly, true);
620  }
static final String KEYCLOAK_REMEMBER_ME
Definition: AuthenticationManager.java:124
static String getIdentityCookiePath(RealmModel realm, UriInfo uriInfo)
Definition: AuthenticationManager.java:669

◆ createRequiredAction()

static RequiredActionProvider org.keycloak.services.managers.AuthenticationManager.createRequiredAction ( RequiredActionContextResult  context)
inlinestaticinherited
1006  {
1007  String display = context.getAuthenticationSession().getAuthNote(OAuth2Constants.DISPLAY);
1008  if (display == null) return context.getFactory().create(context.getSession());
1009 
1010 
1011  if (context.getFactory() instanceof DisplayTypeRequiredActionFactory) {
1012  RequiredActionProvider provider = ((DisplayTypeRequiredActionFactory)context.getFactory()).createDisplay(context.getSession(), display);
1013  if (provider != null) return provider;
1014  }
1015  // todo create a provider for handling lack of display support
1016  if (OAuth2Constants.DISPLAY_CONSOLE.equalsIgnoreCase(display)) {
1017  context.getAuthenticationSession().removeAuthNote(OAuth2Constants.DISPLAY);
1018  throw new AuthenticationFlowException(AuthenticationFlowError.DISPLAY_NOT_SUPPORTED, ConsoleDisplayMode.browserContinue(context.getSession(), context.getUriInfo().getRequestUri().toString()));
1019 
1020  } else {
1021  return context.getFactory().create(context.getSession());
1022  }
1023  }

◆ evaluateRequiredActionTriggers()

static void org.keycloak.services.managers.AuthenticationManager.evaluateRequiredActionTriggers ( final KeycloakSession  session,
final AuthenticationSessionModel  authSession,
final ClientConnection  clientConnection,
final HttpRequest  request,
final UriInfo  uriInfo,
final EventBuilder  event,
final RealmModel  realm,
final UserModel  user 
)
inlinestaticinherited
1090  {
1091 
1092  // see if any required actions need triggering, i.e. an expired password
1093  for (RequiredActionProviderModel model : realm.getRequiredActionProviders()) {
1094  if (!model.isEnabled()) continue;
1095  RequiredActionFactory factory = (RequiredActionFactory)session.getKeycloakSessionFactory().getProviderFactory(RequiredActionProvider.class, model.getProviderId());
1096  if (factory == null) {
1097  throw new RuntimeException("Unable to find factory for Required Action: " + model.getProviderId() + " did you forget to declare it in a META-INF/services file?");
1098  }
1099  RequiredActionProvider provider = factory.create(session);
1100  RequiredActionContextResult result = new RequiredActionContextResult(authSession, realm, event, session, request, user, factory) {
1101  @Override
1102  public void challenge(Response response) {
1103  throw new RuntimeException("Not allowed to call challenge() within evaluateTriggers()");
1104  }
1105 
1106  @Override
1107  public void failure() {
1108  throw new RuntimeException("Not allowed to call failure() within evaluateTriggers()");
1109  }
1110 
1111  @Override
1112  public void success() {
1113  throw new RuntimeException("Not allowed to call success() within evaluateTriggers()");
1114  }
1115 
1116  @Override
1117  public void ignore() {
1118  throw new RuntimeException("Not allowed to call ignore() within evaluateTriggers()");
1119  }
1120  };
1121 
1122  provider.evaluateTriggers(result);
1123  }
1124  }

◆ executionActions()

static Response org.keycloak.services.managers.AuthenticationManager.executionActions ( KeycloakSession  session,
AuthenticationSessionModel  authSession,
HttpRequest  request,
EventBuilder  event,
RealmModel  realm,
UserModel  user,
Set< String >  requiredActions 
)
inlinestaticprotectedinherited
1028  {
1029 
1030  List<RequiredActionProviderModel> sortedRequiredActions = sortRequiredActionsByPriority(realm, requiredActions);
1031 
1032  for (RequiredActionProviderModel model : sortedRequiredActions) {
1033  RequiredActionFactory factory = (RequiredActionFactory)session.getKeycloakSessionFactory().getProviderFactory(RequiredActionProvider.class, model.getProviderId());
1034  if (factory == null) {
1035  throw new RuntimeException("Unable to find factory for Required Action: " + model.getProviderId() + " did you forget to declare it in a META-INF/services file?");
1036  }
1037  RequiredActionContextResult context = new RequiredActionContextResult(authSession, realm, event, session, request, user, factory);
1038  RequiredActionProvider actionProvider = null;
1039  try {
1040  actionProvider = createRequiredAction(context);
1041  } catch (AuthenticationFlowException e) {
1042  if (e.getResponse() != null) {
1043  return e.getResponse();
1044  }
1045  throw e;
1046  }
1047  actionProvider.requiredActionChallenge(context);
1048 
1049  if (context.getStatus() == RequiredActionContext.Status.FAILURE) {
1050  LoginProtocol protocol = context.getSession().getProvider(LoginProtocol.class, context.getAuthenticationSession().getProtocol());
1051  protocol.setRealm(context.getRealm())
1052  .setHttpHeaders(context.getHttpRequest().getHttpHeaders())
1053  .setUriInfo(context.getUriInfo())
1054  .setEventBuilder(event);
1055  Response response = protocol.sendError(context.getAuthenticationSession(), Error.CONSENT_DENIED);
1056  event.error(Errors.REJECTED_BY_USER);
1057  return response;
1058  }
1059  else if (context.getStatus() == RequiredActionContext.Status.CHALLENGE) {
1060  authSession.setAuthNote(AuthenticationProcessor.CURRENT_AUTHENTICATION_EXECUTION, model.getProviderId());
1061  return context.getChallenge();
1062  }
1063  else if (context.getStatus() == RequiredActionContext.Status.SUCCESS) {
1064  event.clone().event(EventType.CUSTOM_REQUIRED_ACTION).detail(Details.CUSTOM_REQUIRED_ACTION, factory.getId()).success();
1065  // don't have to perform the same action twice, so remove it from both the user and session required actions
1066  authSession.getAuthenticatedUser().removeRequiredAction(factory.getId());
1067  authSession.removeRequiredAction(factory.getId());
1068  }
1069  }
1070  return null;
1071  }
static RequiredActionProvider createRequiredAction(RequiredActionContextResult context)
Definition: AuthenticationManager.java:1006
static List< RequiredActionProviderModel > sortRequiredActionsByPriority(RealmModel realm, Set< String > requiredActions)
Definition: AuthenticationManager.java:1073

◆ expireCookie()

static void org.keycloak.services.managers.AuthenticationManager.expireCookie ( RealmModel  realm,
String  cookieName,
String  path,
boolean  httpOnly,
ClientConnection  connection 
)
inlinestaticinherited
689  {
690  logger.debugv("Expiring cookie: {0} path: {1}", cookieName, path);
691  boolean secureOnly = realm.getSslRequired().isRequired(connection);;
692  CookieHelper.addCookie(cookieName, "", path, null, "Expiring cookie", 0, secureOnly, httpOnly);
693  }
static final Logger logger
Definition: AuthenticationManager.java:117

◆ expireIdentityCookie()

static void org.keycloak.services.managers.AuthenticationManager.expireIdentityCookie ( RealmModel  realm,
UriInfo  uriInfo,
ClientConnection  connection 
)
inlinestaticinherited
636  {
637  logger.debug("Expiring identity cookie");
638  String path = getIdentityCookiePath(realm, uriInfo);
639  expireCookie(realm, KEYCLOAK_IDENTITY_COOKIE, path, true, connection);
640  expireCookie(realm, KEYCLOAK_SESSION_COOKIE, path, false, connection);
641 
642  String oldPath = getOldCookiePath(realm, uriInfo);
643  expireCookie(realm, KEYCLOAK_IDENTITY_COOKIE, oldPath, true, connection);
644  expireCookie(realm, KEYCLOAK_SESSION_COOKIE, oldPath, false, connection);
645  }
static final String KEYCLOAK_SESSION_COOKIE
Definition: AuthenticationManager.java:123
static void expireCookie(RealmModel realm, String cookieName, String path, boolean httpOnly, ClientConnection connection)
Definition: AuthenticationManager.java:689
static final Logger logger
Definition: AuthenticationManager.java:117
static final String KEYCLOAK_IDENTITY_COOKIE
Definition: AuthenticationManager.java:121
static String getOldCookiePath(RealmModel realm, UriInfo uriInfo)
Definition: AuthenticationManager.java:679
static String getIdentityCookiePath(RealmModel realm, UriInfo uriInfo)
Definition: AuthenticationManager.java:669

◆ expireOldAuthSessionCookie()

static void org.keycloak.services.managers.AuthenticationManager.expireOldAuthSessionCookie ( RealmModel  realm,
UriInfo  uriInfo,
ClientConnection  connection 
)
inlinestaticinherited
662  {
663  logger.debugv("Expire {1} cookie .", AuthenticationSessionManager.AUTH_SESSION_ID);
664 
665  String oldPath = getOldCookiePath(realm, uriInfo);
666  expireCookie(realm, AuthenticationSessionManager.AUTH_SESSION_ID, oldPath, true, connection);
667  }
static void expireCookie(RealmModel realm, String cookieName, String path, boolean httpOnly, ClientConnection connection)
Definition: AuthenticationManager.java:689
static final Logger logger
Definition: AuthenticationManager.java:117
static String getOldCookiePath(RealmModel realm, UriInfo uriInfo)
Definition: AuthenticationManager.java:679

◆ expireOldIdentityCookie()

static void org.keycloak.services.managers.AuthenticationManager.expireOldIdentityCookie ( RealmModel  realm,
UriInfo  uriInfo,
ClientConnection  connection 
)
inlinestaticinherited
646  {
647  logger.debug("Expiring old identity cookie with wrong path");
648 
649  String oldPath = getOldCookiePath(realm, uriInfo);
650  expireCookie(realm, KEYCLOAK_IDENTITY_COOKIE, oldPath, true, connection);
651  expireCookie(realm, KEYCLOAK_SESSION_COOKIE, oldPath, false, connection);
652  }
static final String KEYCLOAK_SESSION_COOKIE
Definition: AuthenticationManager.java:123
static void expireCookie(RealmModel realm, String cookieName, String path, boolean httpOnly, ClientConnection connection)
Definition: AuthenticationManager.java:689
static final Logger logger
Definition: AuthenticationManager.java:117
static final String KEYCLOAK_IDENTITY_COOKIE
Definition: AuthenticationManager.java:121
static String getOldCookiePath(RealmModel realm, UriInfo uriInfo)
Definition: AuthenticationManager.java:679

◆ expireRememberMeCookie()

static void org.keycloak.services.managers.AuthenticationManager.expireRememberMeCookie ( RealmModel  realm,
UriInfo  uriInfo,
ClientConnection  connection 
)
inlinestaticinherited
655  {
656  logger.debug("Expiring remember me cookie");
657  String path = getIdentityCookiePath(realm, uriInfo);
658  String cookieName = KEYCLOAK_REMEMBER_ME;
659  expireCookie(realm, cookieName, path, true, connection);
660  }
static final String KEYCLOAK_REMEMBER_ME
Definition: AuthenticationManager.java:124
static void expireCookie(RealmModel realm, String cookieName, String path, boolean httpOnly, ClientConnection connection)
Definition: AuthenticationManager.java:689
static final Logger logger
Definition: AuthenticationManager.java:117
static String getIdentityCookiePath(RealmModel realm, UriInfo uriInfo)
Definition: AuthenticationManager.java:669

◆ expireUserSessionCookie()

static void org.keycloak.services.managers.AuthenticationManager.expireUserSessionCookie ( KeycloakSession  session,
UserSessionModel  userSession,
RealmModel  realm,
UriInfo  uriInfo,
HttpHeaders  headers,
ClientConnection  connection 
)
inlinestaticinherited
159  {
160  try {
161  // check to see if any identity cookie is set with the same session and expire it if necessary
162  Cookie cookie = headers.getCookies().get(KEYCLOAK_IDENTITY_COOKIE);
163  if (cookie == null) return;
164  String tokenString = cookie.getValue();
165 
166  TokenVerifier<AccessToken> verifier = TokenVerifier.create(tokenString, AccessToken.class)
167  .realmUrl(Urls.realmIssuer(uriInfo.getBaseUri(), realm.getName()))
168  .checkActive(false)
169  .checkTokenType(false);
170 
171  String kid = verifier.getHeader().getKeyId();
172  String algorithm = verifier.getHeader().getAlgorithm().name();
173 
174  SignatureVerifierContext signatureVerifier = session.getProvider(SignatureProvider.class, algorithm).verifier(kid);
175  verifier.verifierContext(signatureVerifier);
176 
177  AccessToken token = verifier.verify().getToken();
178  UserSessionModel cookieSession = session.sessions().getUserSession(realm, token.getSessionState());
179  if (cookieSession == null || !cookieSession.getId().equals(userSession.getId())) return;
180  expireIdentityCookie(realm, uriInfo, connection);
181  } catch (Exception e) {
182  }
183 
184  }
static void expireIdentityCookie(RealmModel realm, UriInfo uriInfo, ClientConnection connection)
Definition: AuthenticationManager.java:636
static final String KEYCLOAK_IDENTITY_COOKIE
Definition: AuthenticationManager.java:121

◆ extractAuthorizationHeaderToken()

String org.keycloak.services.managers.AppAuthManager.extractAuthorizationHeaderToken ( HttpHeaders  headers)
inline
44  {
45  String tokenString = null;
46  String authHeader = headers.getRequestHeaders().getFirst(HttpHeaders.AUTHORIZATION);
47  if (authHeader != null) {
48  String[] split = authHeader.trim().split("\\s+");
49  if (split == null || split.length != 2) throw new UnauthorizedException("Bearer");
50  if (!split[0].equalsIgnoreCase("Bearer")) throw new UnauthorizedException("Bearer");
51  tokenString = split[1];
52  }
53  return tokenString;
54  }

◆ finishBrowserLogout()

static Response org.keycloak.services.managers.AuthenticationManager.finishBrowserLogout ( KeycloakSession  session,
RealmModel  realm,
UserSessionModel  userSession,
UriInfo  uriInfo,
ClientConnection  connection,
HttpHeaders  headers 
)
inlinestaticinherited
544  {
545  final AuthenticationSessionManager asm = new AuthenticationSessionManager(session);
546  AuthenticationSessionModel logoutAuthSession = createOrJoinLogoutSession(session, realm, asm, userSession, true);
547 
548  checkUserSessionOnlyHasLoggedOutClients(realm, userSession, logoutAuthSession);
549 
550  expireIdentityCookie(realm, uriInfo, connection);
551  expireRememberMeCookie(realm, uriInfo, connection);
552  userSession.setState(UserSessionModel.State.LOGGED_OUT);
553  String method = userSession.getNote(KEYCLOAK_LOGOUT_PROTOCOL);
554  EventBuilder event = new EventBuilder(realm, session, connection);
555  LoginProtocol protocol = session.getProvider(LoginProtocol.class, method);
556  protocol.setRealm(realm)
557  .setHttpHeaders(headers)
558  .setUriInfo(uriInfo)
559  .setEventBuilder(event);
560  Response response = protocol.finishLogout(userSession);
561  session.sessions().removeUserSession(realm, userSession);
562  session.authenticationSessions().removeRootAuthenticationSession(realm, logoutAuthSession.getParentSession());
563  return response;
564  }
static final String KEYCLOAK_LOGOUT_PROTOCOL
Definition: AuthenticationManager.java:125
static void expireRememberMeCookie(RealmModel realm, UriInfo uriInfo, ClientConnection connection)
Definition: AuthenticationManager.java:655
static void expireIdentityCookie(RealmModel realm, UriInfo uriInfo, ClientConnection connection)
Definition: AuthenticationManager.java:636
static boolean checkUserSessionOnlyHasLoggedOutClients(RealmModel realm, UserSessionModel userSession, AuthenticationSessionModel logoutAuthSession)
Definition: AuthenticationManager.java:323
static AuthenticationSessionModel createOrJoinLogoutSession(KeycloakSession session, RealmModel realm, final AuthenticationSessionManager asm, UserSessionModel userSession, boolean browserCookie)
Definition: AuthenticationManager.java:255

◆ finishedRequiredActions()

static Response org.keycloak.services.managers.AuthenticationManager.finishedRequiredActions ( KeycloakSession  session,
AuthenticationSessionModel  authSession,
UserSessionModel  userSession,
ClientConnection  clientConnection,
HttpRequest  request,
UriInfo  uriInfo,
EventBuilder  event 
)
inlinestaticinherited
824  {
825  String actionTokenKeyToInvalidate = authSession.getAuthNote(INVALIDATE_ACTION_TOKEN);
826  if (actionTokenKeyToInvalidate != null) {
827  ActionTokenKeyModel actionTokenKey = DefaultActionTokenKey.from(actionTokenKeyToInvalidate);
828 
829  if (actionTokenKey != null) {
830  ActionTokenStoreProvider actionTokenStore = session.getProvider(ActionTokenStoreProvider.class);
831  actionTokenStore.put(actionTokenKey, null); // Token is invalidated
832  }
833  }
834 
835  if (authSession.getAuthNote(END_AFTER_REQUIRED_ACTIONS) != null) {
836  LoginFormsProvider infoPage = session.getProvider(LoginFormsProvider.class).setAuthenticationSession(authSession)
837  .setSuccess(Messages.ACCOUNT_UPDATED);
838  if (authSession.getAuthNote(SET_REDIRECT_URI_AFTER_REQUIRED_ACTIONS) != null) {
839  if (authSession.getRedirectUri() != null) {
840  infoPage.setAttribute("pageRedirectUri", authSession.getRedirectUri());
841  }
842 
843  } else {
844  infoPage.setAttribute(Constants.SKIP_LINK, true);
845  }
846  Response response = infoPage
847  .createInfoPage();
848 
849  new AuthenticationSessionManager(session).removeAuthenticationSession(authSession.getRealm(), authSession, true);
850 
851  return response;
852  }
853  RealmModel realm = authSession.getRealm();
854 
855  ClientSessionContext clientSessionCtx = AuthenticationProcessor.attachSession(authSession, userSession, session, realm, clientConnection, event);
856  userSession = clientSessionCtx.getClientSession().getUserSession();
857 
858  event.event(EventType.LOGIN);
859  event.session(userSession);
860  event.success();
861  return redirectAfterSuccessfulFlow(session, realm, userSession, clientSessionCtx, request, uriInfo, clientConnection, event, authSession.getProtocol());
862  }
static final String SET_REDIRECT_URI_AFTER_REQUIRED_ACTIONS
Definition: AuthenticationManager.java:103
static final String END_AFTER_REQUIRED_ACTIONS
Definition: AuthenticationManager.java:104
static Response redirectAfterSuccessfulFlow(KeycloakSession session, RealmModel realm, UserSessionModel userSession, ClientSessionContext clientSessionCtx, HttpRequest request, UriInfo uriInfo, ClientConnection clientConnection, EventBuilder event, String protocol)
Definition: AuthenticationManager.java:718
static final String INVALIDATE_ACTION_TOKEN
Definition: AuthenticationManager.java:105

◆ getAccountCookiePath()

static String org.keycloak.services.managers.AuthenticationManager.getAccountCookiePath ( RealmModel  realm,
UriInfo  uriInfo 
)
inlinestaticinherited
684  {
685  URI uri = RealmsResource.accountUrl(uriInfo.getBaseUriBuilder()).build(realm.getName());
686  return uri.getRawPath();
687  }

◆ getClientLogoutAction()

static AuthenticationSessionModel.Action org.keycloak.services.managers.AuthenticationManager.getClientLogoutAction ( AuthenticationSessionModel  logoutAuthSession,
String  clientUuid 
)
inlinestaticinherited

Returns the logout state of the particular client as per the

logoutAuthSession
引数
logoutAuthSessionlogoutAuthSession. May be
null
in which case this is a no-op.
clientUuidInternal ID of the client. Must not be
null
戻り値
State if it can be determined,
null
otherwise.
462  {
463  if (logoutAuthSession == null || clientUuid == null) {
464  return null;
465  }
466 
467  String state = logoutAuthSession.getAuthNote(CLIENT_LOGOUT_STATE + clientUuid);
468  return state == null ? null : AuthenticationSessionModel.Action.valueOf(state);
469  }
static final String CLIENT_LOGOUT_STATE
Definition: AuthenticationManager.java:110

◆ getIdentityCookiePath()

static String org.keycloak.services.managers.AuthenticationManager.getIdentityCookiePath ( RealmModel  realm,
UriInfo  uriInfo 
)
inlinestaticprotectedinherited
669  {
670  return getRealmCookiePath(realm, uriInfo);
671  }
static String getRealmCookiePath(RealmModel realm, UriInfo uriInfo)
Definition: AuthenticationManager.java:673

◆ getOldCookiePath()

static String org.keycloak.services.managers.AuthenticationManager.getOldCookiePath ( RealmModel  realm,
UriInfo  uriInfo 
)
inlinestaticinherited
679  {
680  URI uri = RealmsResource.realmBaseUrl(uriInfo).build(realm.getName());
681  return uri.getRawPath();
682  }

◆ getRealmCookiePath()

static String org.keycloak.services.managers.AuthenticationManager.getRealmCookiePath ( RealmModel  realm,
UriInfo  uriInfo 
)
inlinestaticinherited
673  {
674  URI uri = RealmsResource.realmBaseUrl(uriInfo).build(realm.getName());
675  // KEYCLOAK-5270
676  return uri.getRawPath() + "/";
677  }

◆ getRememberMeUsername()

static String org.keycloak.services.managers.AuthenticationManager.getRememberMeUsername ( RealmModel  realm,
HttpHeaders  headers 
)
inlinestaticinherited
622  {
623  if (realm.isRememberMe()) {
624  Cookie cookie = headers.getCookies().get(AuthenticationManager.KEYCLOAK_REMEMBER_ME);
625  if (cookie != null) {
626  String value = cookie.getValue();
627  String[] s = value.split(":");
628  if (s[0].equals("username") && s.length == 2) {
629  return s[1];
630  }
631  }
632  }
633  return null;
634  }

◆ isOfflineSessionValid()

static boolean org.keycloak.services.managers.AuthenticationManager.isOfflineSessionValid ( RealmModel  realm,
UserSessionModel  userSession 
)
inlinestaticinherited
141  {
142  if (userSession == null) {
143  logger.debug("No offline user session");
144  return false;
145  }
146  int currentTime = Time.currentTime();
147  // Additional time window is added for the case when session was updated in different DC and the update to current DC was postponed
148  int maxIdle = realm.getOfflineSessionIdleTimeout() + SessionTimeoutHelper.IDLE_TIMEOUT_WINDOW_SECONDS;
149 
150  // KEYCLOAK-7688 Offline Session Max for Offline Token
151  if (realm.isOfflineSessionMaxLifespanEnabled()) {
152  int max = userSession.getStarted() + realm.getOfflineSessionMaxLifespan();
153  return userSession.getLastSessionRefresh() + maxIdle > currentTime && max > currentTime;
154  } else {
155  return userSession.getLastSessionRefresh() + maxIdle > currentTime;
156  }
157  }
static final Logger logger
Definition: AuthenticationManager.java:117

◆ isSessionValid()

static boolean org.keycloak.services.managers.AuthenticationManager.isSessionValid ( RealmModel  realm,
UserSessionModel  userSession 
)
inlinestaticinherited
127  {
128  if (userSession == null) {
129  logger.debug("No user session");
130  return false;
131  }
132  int currentTime = Time.currentTime();
133  int max = userSession.getStarted() + realm.getSsoSessionMaxLifespan();
134 
135  // Additional time window is added for the case when session was updated in different DC and the update to current DC was postponed
136  int maxIdle = realm.getSsoSessionIdleTimeout() + SessionTimeoutHelper.IDLE_TIMEOUT_WINDOW_SECONDS;
137 
138  return userSession.getLastSessionRefresh() + maxIdle > currentTime && max > currentTime;
139  }
static final Logger logger
Definition: AuthenticationManager.java:117

◆ isSSOAuthentication()

static boolean org.keycloak.services.managers.AuthenticationManager.isSSOAuthentication ( AuthenticatedClientSessionModel  clientSession)
inlinestaticinherited
779  {
780  String ssoAuth = clientSession.getNote(SSO_AUTH);
781  return Boolean.parseBoolean(ssoAuth);
782  }
static final String SSO_AUTH
Definition: AuthenticationManager.java:115

◆ nextActionAfterAuthentication()

static Response org.keycloak.services.managers.AuthenticationManager.nextActionAfterAuthentication ( KeycloakSession  session,
AuthenticationSessionModel  authSession,
ClientConnection  clientConnection,
HttpRequest  request,
UriInfo  uriInfo,
EventBuilder  event 
)
inlinestaticinherited
787  {
788  Response requiredAction = actionRequired(session, authSession, clientConnection, request, uriInfo, event);
789  if (requiredAction != null) return requiredAction;
790  return finishedRequiredActions(session, authSession, null, clientConnection, request, uriInfo, event);
791 
792  }
static Response actionRequired(final KeycloakSession session, final AuthenticationSessionModel authSession, final ClientConnection clientConnection, final HttpRequest request, final UriInfo uriInfo, final EventBuilder event)
Definition: AuthenticationManager.java:916
static Response finishedRequiredActions(KeycloakSession session, AuthenticationSessionModel authSession, UserSessionModel userSession, ClientConnection clientConnection, HttpRequest request, UriInfo uriInfo, EventBuilder event)
Definition: AuthenticationManager.java:823

◆ nextRequiredAction()

static String org.keycloak.services.managers.AuthenticationManager.nextRequiredAction ( final KeycloakSession  session,
final AuthenticationSessionModel  authSession,
final ClientConnection  clientConnection,
final HttpRequest  request,
final UriInfo  uriInfo,
final EventBuilder  event 
)
inlinestaticinherited
867  {
868  final RealmModel realm = authSession.getRealm();
869  final UserModel user = authSession.getAuthenticatedUser();
870  final ClientModel client = authSession.getClient();
871 
872  evaluateRequiredActionTriggers(session, authSession, clientConnection, request, uriInfo, event, realm, user);
873 
874  if (!user.getRequiredActions().isEmpty()) {
875  return user.getRequiredActions().iterator().next();
876  }
877  if (!authSession.getRequiredActions().isEmpty()) {
878  return authSession.getRequiredActions().iterator().next();
879  }
880 
881  if (client.isConsentRequired()) {
882 
883  UserConsentModel grantedConsent = getEffectiveGrantedConsent(session, authSession);
884 
885  // See if any clientScopes need to be approved on consent screen
886  List<ClientScopeModel> clientScopesToApprove = getClientScopesToApproveOnConsentScreen(realm, grantedConsent, authSession);
887  if (!clientScopesToApprove.isEmpty()) {
888  return CommonClientSessionModel.Action.OAUTH_GRANT.name();
889  }
890 
891  String consentDetail = (grantedConsent != null) ? Details.CONSENT_VALUE_PERSISTED_CONSENT : Details.CONSENT_VALUE_NO_CONSENT_REQUIRED;
892  event.detail(Details.CONSENT, consentDetail);
893  } else {
894  event.detail(Details.CONSENT, Details.CONSENT_VALUE_NO_CONSENT_REQUIRED);
895  }
896  return null;
897 
898  }
static List< ClientScopeModel > getClientScopesToApproveOnConsentScreen(RealmModel realm, UserConsentModel grantedConsent, AuthenticationSessionModel authSession)
Definition: AuthenticationManager.java:970
static void evaluateRequiredActionTriggers(final KeycloakSession session, final AuthenticationSessionModel authSession, final ClientConnection clientConnection, final HttpRequest request, final UriInfo uriInfo, final EventBuilder event, final RealmModel realm, final UserModel user)
Definition: AuthenticationManager.java:1090
static UserConsentModel getEffectiveGrantedConsent(KeycloakSession session, AuthenticationSessionModel authSession)
Definition: AuthenticationManager.java:901

◆ redirectAfterSuccessfulFlow() [1/2]

static Response org.keycloak.services.managers.AuthenticationManager.redirectAfterSuccessfulFlow ( KeycloakSession  session,
RealmModel  realm,
UserSessionModel  userSession,
ClientSessionContext  clientSessionCtx,
HttpRequest  request,
UriInfo  uriInfo,
ClientConnection  clientConnection,
EventBuilder  event,
String  protocol 
)
inlinestaticinherited
721  {
722  LoginProtocol protocolImpl = session.getProvider(LoginProtocol.class, protocol);
723  protocolImpl.setRealm(realm)
724  .setHttpHeaders(request.getHttpHeaders())
725  .setUriInfo(uriInfo)
726  .setEventBuilder(event);
727  return redirectAfterSuccessfulFlow(session, realm, userSession, clientSessionCtx, request, uriInfo, clientConnection, event, protocolImpl);
728 
729  }
static Response redirectAfterSuccessfulFlow(KeycloakSession session, RealmModel realm, UserSessionModel userSession, ClientSessionContext clientSessionCtx, HttpRequest request, UriInfo uriInfo, ClientConnection clientConnection, EventBuilder event, String protocol)
Definition: AuthenticationManager.java:718

◆ redirectAfterSuccessfulFlow() [2/2]

static Response org.keycloak.services.managers.AuthenticationManager.redirectAfterSuccessfulFlow ( KeycloakSession  session,
RealmModel  realm,
UserSessionModel  userSession,
ClientSessionContext  clientSessionCtx,
HttpRequest  request,
UriInfo  uriInfo,
ClientConnection  clientConnection,
EventBuilder  event,
LoginProtocol  protocol 
)
inlinestaticinherited
734  {
735  Cookie sessionCookie = request.getHttpHeaders().getCookies().get(AuthenticationManager.KEYCLOAK_SESSION_COOKIE);
736  if (sessionCookie != null) {
737 
738  String[] split = sessionCookie.getValue().split("/");
739  if (split.length >= 3) {
740  String oldSessionId = split[2];
741  if (!oldSessionId.equals(userSession.getId())) {
742  UserSessionModel oldSession = session.sessions().getUserSession(realm, oldSessionId);
743  if (oldSession != null) {
744  logger.debugv("Removing old user session: session: {0}", oldSessionId);
745  session.sessions().removeUserSession(realm, oldSession);
746  }
747  }
748  }
749  }
750 
751  // Updates users locale if required
752  session.getContext().resolveLocale(userSession.getUser());
753 
754  // refresh the cookies!
755  createLoginCookie(session, realm, userSession.getUser(), userSession, uriInfo, clientConnection);
756  if (userSession.getState() != UserSessionModel.State.LOGGED_IN) userSession.setState(UserSessionModel.State.LOGGED_IN);
757  if (userSession.isRememberMe()) {
758  createRememberMeCookie(realm, userSession.getLoginUsername(), uriInfo, clientConnection);
759  } else {
760  expireRememberMeCookie(realm, uriInfo, clientConnection);
761  }
762 
763  AuthenticatedClientSessionModel clientSession = clientSessionCtx.getClientSession();
764 
765  // Update userSession note with authTime. But just if flag SSO_AUTH is not set
766  boolean isSSOAuthentication = "true".equals(session.getAttribute(SSO_AUTH));
767  if (isSSOAuthentication) {
768  clientSession.setNote(SSO_AUTH, "true");
769  } else {
770  int authTime = Time.currentTime();
771  userSession.setNote(AUTH_TIME, String.valueOf(authTime));
772  clientSession.removeNote(SSO_AUTH);
773  }
774 
775  return protocol.authenticated(userSession, clientSessionCtx);
776 
777  }
static void expireRememberMeCookie(RealmModel realm, UriInfo uriInfo, ClientConnection connection)
Definition: AuthenticationManager.java:655
static final String SSO_AUTH
Definition: AuthenticationManager.java:115
static void createRememberMeCookie(RealmModel realm, String username, UriInfo uriInfo, ClientConnection connection)
Definition: AuthenticationManager.java:614
static void createLoginCookie(KeycloakSession keycloakSession, RealmModel realm, UserModel user, UserSessionModel session, UriInfo uriInfo, ClientConnection connection)
Definition: AuthenticationManager.java:590
static boolean isSSOAuthentication(AuthenticatedClientSessionModel clientSession)
Definition: AuthenticationManager.java:779
static final Logger logger
Definition: AuthenticationManager.java:117
static final String AUTH_TIME
Definition: AuthenticationManager.java:113

◆ redirectToRequiredActions()

static Response org.keycloak.services.managers.AuthenticationManager.redirectToRequiredActions ( KeycloakSession  session,
RealmModel  realm,
AuthenticationSessionModel  authSession,
UriInfo  uriInfo,
String  requiredAction 
)
inlinestaticinherited
795  {
796  // redirect to non-action url so browser refresh button works without reposting past data
797  ClientSessionCode<AuthenticationSessionModel> accessCode = new ClientSessionCode<>(session, realm, authSession);
798  accessCode.setAction(AuthenticationSessionModel.Action.REQUIRED_ACTIONS.name());
799  authSession.setAuthNote(AuthenticationProcessor.CURRENT_FLOW_PATH, LoginActionsService.REQUIRED_ACTION);
800  authSession.setAuthNote(AuthenticationProcessor.CURRENT_AUTHENTICATION_EXECUTION, requiredAction);
801 
802  UriBuilder uriBuilder = LoginActionsService.loginActionsBaseUrl(uriInfo)
803  .path(LoginActionsService.REQUIRED_ACTION);
804 
805  if (requiredAction != null) {
806  uriBuilder.queryParam(Constants.EXECUTION, requiredAction);
807  }
808 
809  uriBuilder.queryParam(Constants.CLIENT_ID, authSession.getClient().getClientId());
810  uriBuilder.queryParam(Constants.TAB_ID, authSession.getTabId());
811 
812  if (uriInfo.getQueryParameters().containsKey(LoginActionsService.AUTH_SESSION_ID)) {
813  uriBuilder.queryParam(LoginActionsService.AUTH_SESSION_ID, authSession.getParentSession().getId());
814 
815  }
816 
817  URI redirect = uriBuilder.build(realm.getName());
818  return Response.status(302).location(redirect).build();
819 
820  }

◆ setClientLogoutAction()

static void org.keycloak.services.managers.AuthenticationManager.setClientLogoutAction ( AuthenticationSessionModel  logoutAuthSession,
String  clientUuid,
AuthenticationSessionModel.Action  action 
)
inlinestaticinherited

Sets logout state of the particular client into the

logoutAuthSession
引数
logoutAuthSessionlogoutAuthSession. May be
null
in which case this is a no-op.
clientUuidClient. Must not be
null
action
450  {
451  if (logoutAuthSession != null && clientUuid != null) {
452  logoutAuthSession.setAuthNote(CLIENT_LOGOUT_STATE + clientUuid, action.name());
453  }
454  }
static final String CLIENT_LOGOUT_STATE
Definition: AuthenticationManager.java:110

◆ setClientScopesInSession()

static void org.keycloak.services.managers.AuthenticationManager.setClientScopesInSession ( AuthenticationSessionModel  authSession)
inlinestaticinherited
992  {
993  ClientModel client = authSession.getClient();
994  UserModel user = authSession.getAuthenticatedUser();
995 
996  // todo scope param protocol independent
997  String scopeParam = authSession.getClientNote(OAuth2Constants.SCOPE);
998 
999  Set<String> requestedClientScopes = new HashSet<String>();
1000  for (ClientScopeModel clientScope : org.keycloak.protocol.oidc.TokenManager.getRequestedClientScopes(scopeParam, client)) {
1001  requestedClientScopes.add(clientScope.getId());
1002  }
1003  authSession.setClientScopes(requestedClientScopes);
1004  }
Definition: AuthorizationEndpointBase.java:18
Definition: TokenManager.java:84
static Set< ClientScopeModel > getRequestedClientScopes(String scopeParam, ClientModel client)
Definition: TokenManager.java:523
Definition: AccessTokenIntrospectionProvider.java:18

◆ verifyIdentityToken()

static AuthResult org.keycloak.services.managers.AuthenticationManager.verifyIdentityToken ( KeycloakSession  session,
RealmModel  realm,
UriInfo  uriInfo,
ClientConnection  connection,
boolean  checkActive,
boolean  checkTokenType,
boolean  isCookie,
String  tokenString,
HttpHeaders  headers 
)
inlinestaticinherited
1128  {
1129  try {
1130  TokenVerifier<AccessToken> verifier = TokenVerifier.create(tokenString, AccessToken.class)
1131  .withDefaultChecks()
1132  .realmUrl(Urls.realmIssuer(uriInfo.getBaseUri(), realm.getName()))
1133  .checkActive(checkActive)
1134  .checkTokenType(checkTokenType);
1135  String kid = verifier.getHeader().getKeyId();
1136  String algorithm = verifier.getHeader().getAlgorithm().name();
1137 
1138  SignatureVerifierContext signatureVerifier = session.getProvider(SignatureProvider.class, algorithm).verifier(kid);
1139  verifier.verifierContext(signatureVerifier);
1140 
1141  AccessToken token = verifier.verify().getToken();
1142  if (checkActive) {
1143  if (!token.isActive() || token.getIssuedAt() < realm.getNotBefore()) {
1144  logger.debug("Identity cookie expired");
1145  return null;
1146  }
1147  }
1148 
1149  UserSessionModel userSession = session.sessions().getUserSession(realm, token.getSessionState());
1150  UserModel user = null;
1151  if (userSession != null) {
1152  user = userSession.getUser();
1153  if (user == null || !user.isEnabled()) {
1154  logger.debug("Unknown user in identity token");
1155  return null;
1156  }
1157 
1158  int userNotBefore = session.users().getNotBeforeOfUser(realm, user);
1159  if (token.getIssuedAt() < userNotBefore) {
1160  logger.debug("User notBefore newer than token");
1161  return null;
1162  }
1163  }
1164 
1165  if (!isSessionValid(realm, userSession)) {
1166  // Check if accessToken was for the offline session.
1167  if (!isCookie) {
1168  UserSessionModel offlineUserSession = session.sessions().getOfflineUserSession(realm, token.getSessionState());
1169  if (isOfflineSessionValid(realm, offlineUserSession)) {
1170  user = offlineUserSession.getUser();
1171  return new AuthResult(user, offlineUserSession, token);
1172  }
1173  }
1174 
1175  if (userSession != null) backchannelLogout(session, realm, userSession, uriInfo, connection, headers, true);
1176  logger.debug("User session not active");
1177  return null;
1178  }
1179 
1180  session.setAttribute("state_checker", token.getOtherClaims().get("state_checker"));
1181 
1182  return new AuthResult(user, userSession, token);
1183  } catch (VerificationException e) {
1184  logger.debugf("Failed to verify identity token: %s", e.getMessage());
1185  }
1186  return null;
1187  }
static final Logger logger
Definition: AuthenticationManager.java:117
static boolean isSessionValid(RealmModel realm, UserSessionModel userSession)
Definition: AuthenticationManager.java:127
static boolean isOfflineSessionValid(RealmModel realm, UserSessionModel userSession)
Definition: AuthenticationManager.java:141
static void backchannelLogout(KeycloakSession session, UserSessionModel userSession, boolean logoutBroker)
Definition: AuthenticationManager.java:186

メンバ詳解

◆ AUTH_TIME

final String org.keycloak.services.managers.AuthenticationManager.AUTH_TIME = "AUTH_TIME"
staticinherited

◆ CLIENT_LOGOUT_STATE

final String org.keycloak.services.managers.AuthenticationManager.CLIENT_LOGOUT_STATE = "logout.state."
staticinherited

Auth session note on client logout state (when logging out)

◆ END_AFTER_REQUIRED_ACTIONS

final String org.keycloak.services.managers.AuthenticationManager.END_AFTER_REQUIRED_ACTIONS = "END_AFTER_REQUIRED_ACTIONS"
staticinherited

◆ FORM_USERNAME

final String org.keycloak.services.managers.AuthenticationManager.FORM_USERNAME = "username"
staticinherited

◆ INVALIDATE_ACTION_TOKEN

final String org.keycloak.services.managers.AuthenticationManager.INVALIDATE_ACTION_TOKEN = "INVALIDATE_ACTION_TOKEN"
staticinherited

◆ KEYCLOAK_IDENTITY_COOKIE

final String org.keycloak.services.managers.AuthenticationManager.KEYCLOAK_IDENTITY_COOKIE = "KEYCLOAK_IDENTITY"
staticinherited

◆ KEYCLOAK_LOGOUT_PROTOCOL

final String org.keycloak.services.managers.AuthenticationManager.KEYCLOAK_LOGOUT_PROTOCOL = "KEYCLOAK_LOGOUT_PROTOCOL"
staticinherited

◆ KEYCLOAK_REMEMBER_ME

final String org.keycloak.services.managers.AuthenticationManager.KEYCLOAK_REMEMBER_ME = "KEYCLOAK_REMEMBER_ME"
staticinherited

◆ KEYCLOAK_SESSION_COOKIE

final String org.keycloak.services.managers.AuthenticationManager.KEYCLOAK_SESSION_COOKIE = "KEYCLOAK_SESSION"
staticinherited

◆ logger

final Logger org.keycloak.services.managers.AuthenticationManager.logger = Logger.getLogger(AuthenticationManager.class)
staticprotectedinherited

◆ SET_REDIRECT_URI_AFTER_REQUIRED_ACTIONS

final String org.keycloak.services.managers.AuthenticationManager.SET_REDIRECT_URI_AFTER_REQUIRED_ACTIONS = "SET_REDIRECT_URI_AFTER_REQUIRED_ACTIONS"
staticinherited

◆ SSO_AUTH

final String org.keycloak.services.managers.AuthenticationManager.SSO_AUTH = "SSO_AUTH"
staticinherited

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