Java Code Examples for org.keycloak.models.KeycloakSession#getAttribute()
The following examples show how to use
org.keycloak.models.KeycloakSession#getAttribute() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CrossDCLastSessionRefreshChecker.java From keycloak with Apache License 2.0 | 6 votes |
private SessionUpdateTask.CrossDCMessageStatus baseChecks(KeycloakSession kcSession, RealmModel realm, boolean offline) { // revokeRefreshToken always writes everything to remoteCache immediately if (realm.isRevokeRefreshToken()) { return SessionUpdateTask.CrossDCMessageStatus.SYNC; } // We're likely not in cross-dc environment. Doesn't matter what we return CrossDCLastSessionRefreshStore storeToUse = offline ? offlineStore : store; if (storeToUse == null) { return SessionUpdateTask.CrossDCMessageStatus.SYNC; } // Received the message from the other DC that we should update the lastSessionRefresh in local cluster Boolean ignoreRemoteCacheUpdate = (Boolean) kcSession.getAttribute(CrossDCLastSessionRefreshListener.IGNORE_REMOTE_CACHE_UPDATE); if (ignoreRemoteCacheUpdate != null && ignoreRemoteCacheUpdate) { return SessionUpdateTask.CrossDCMessageStatus.NOT_NEEDED; } return null; }
Example 2
Source File: AuthenticationManager.java From keycloak with Apache License 2.0 | 5 votes |
public static IdentityCookieToken createIdentityToken(KeycloakSession keycloakSession, RealmModel realm, UserModel user, UserSessionModel session, String issuer) { IdentityCookieToken token = new IdentityCookieToken(); token.id(KeycloakModelUtils.generateId()); token.issuedNow(); token.subject(user.getId()); token.issuer(issuer); token.type(TokenUtil.TOKEN_TYPE_KEYCLOAK_ID); if (session != null) { token.setSessionState(session.getId()); } if (session != null && session.isRememberMe() && realm.getSsoSessionMaxLifespanRememberMe() > 0) { token.expiration(Time.currentTime() + realm.getSsoSessionMaxLifespanRememberMe()); } else if (realm.getSsoSessionMaxLifespan() > 0) { token.expiration(Time.currentTime() + realm.getSsoSessionMaxLifespan()); } String stateChecker = (String) keycloakSession.getAttribute("state_checker"); if (stateChecker == null) { stateChecker = Base64Url.encode(KeycloakModelUtils.generateSecret()); keycloakSession.setAttribute("state_checker", stateChecker); } token.getOtherClaims().put("state_checker", stateChecker); return token; }
Example 3
Source File: UserStorageManager.java From keycloak with Apache License 2.0 | 5 votes |
public static UserStorageProvider getStorageProviderInstance(KeycloakSession session, UserStorageProviderModel model, UserStorageProviderFactory factory) { UserStorageProvider instance = (UserStorageProvider)session.getAttribute(model.getId()); if (instance != null) return instance; instance = factory.create(session, model); if (instance == null) { throw new IllegalStateException("UserStorageProvideFactory (of type " + factory.getClass().getName() + ") produced a null instance"); } session.enlistForClose(instance); session.setAttribute(model.getId(), instance); return instance; }
Example 4
Source File: ClientStorageManager.java From keycloak with Apache License 2.0 | 5 votes |
public static ClientStorageProvider getStorageProviderInstance(KeycloakSession session, ClientStorageProviderModel model, ClientStorageProviderFactory factory) { ClientStorageProvider instance = (ClientStorageProvider)session.getAttribute(model.getId()); if (instance != null) return instance; instance = factory.create(session, model); if (instance == null) { throw new IllegalStateException("ClientStorageProvideFactory (of type " + factory.getClass().getName() + ") produced a null instance"); } session.enlistForClose(instance); session.setAttribute(model.getId(), instance); return instance; }
Example 5
Source File: AbstractLDAPStorageMapperFactory.java From keycloak with Apache License 2.0 | 5 votes |
@Override public LDAPStorageMapper create(KeycloakSession session, ComponentModel model) { // LDAPStorageProvider is in the session already as mappers are always called from it String ldapProviderModelId = model.getParentId(); LDAPStorageProvider ldapProvider = (LDAPStorageProvider) session.getAttribute(ldapProviderModelId); return createMapper(model, ldapProvider); }