Package org.keycloak.models
Interface KeycloakContext
- All Known Implementing Classes:
DefaultKeycloakContext
public interface KeycloakContext
- Author:
- Stian Thorgersen
-
Method Summary
Modifier and TypeMethodDescriptionGet current AuthenticationSessionModel, can be null out of the AuthenticationSession context.Returns aTokenrepresenting the bearer token used to authenticate and authorize the current request.If there is no active request, aClientConnectionwill still be returneddefault <T> TgetContextObject(Class<T> clazz) Deprecated, for removal: This API element is subject to removal in a future version.If there is no active request, aContextNotActiveExceptionwill be thrownIf there is no active request, aContextNotActiveExceptionwill be thrownReturns the permissions evaluator that can be used to check if the current user has permissions to perform an action on realm resources.getRealm()jakarta.ws.rs.core.HttpHeadersDeprecated.getUri()Returns the URI assuming it is a frontend request.Returns the URI.getUser()Returns theUserModelbound to this context.resolveLocale(UserModel user) default LocaleresolveLocale(UserModel user, boolean ignoreAcceptLanguageHeader) default LocaleresolveLocale(UserModel user, Theme.Type themeType) voidsetAuthenticationSession(AuthenticationSessionModel authenticationSession) voidsetBearerToken(Token token) voidsetClient(ClientModel client) voidsetConnection(ClientConnection clientConnection) voidsetHttpRequest(HttpRequest httpRequest) voidsetHttpResponse(HttpResponse httpResponse) voidsetOrganization(OrganizationModel organization) voidsetRealm(RealmModel realm) voidsetUserSession(UserSessionModel session)
-
Method Details
-
getAuthServerUrl
URI getAuthServerUrl()- Throws:
jakarta.enterprise.context.ContextNotActiveException- if no request is active and a non-full URL hostname is configured
-
getContextPath
String getContextPath()- Throws:
jakarta.enterprise.context.ContextNotActiveException- if no request is active and a non-full URL hostname is configured
-
getRequestHeaders
Deprecated.UsegetHttpRequest()to obtain the request headers.- Throws:
jakarta.enterprise.context.ContextNotActiveException- when no request is active
-
getUri
KeycloakUriInfo getUri()Returns the URI assuming it is a frontend request. To resolve URI for a backend request usegetUri(UrlType)method calls on the returnedKeycloakUriInfomay throw aContextNotActiveExceptionif no request is active -
getUri
Returns the URI. If a frontend request (from user-agent) @frontendRequest should be set to true. If a backend request (request from a client) should be set to false. Depending on the configure hostname provider it may return a hard-coded base URL for frontend request (for example https://auth.mycompany.com) and use the request URL for backend requests. Frontend URI should also be used for realm issuer fields in tokens.Method calls on the returned
KeycloakUriInfomay throw aContextNotActiveExceptionif no request is active.- Parameters:
type- the type of the request- Throws:
jakarta.enterprise.context.ContextNotActiveException- if no request is active and information from a current request is needed to determine the base URI.
-
getContextObject
Deprecated, for removal: This API element is subject to removal in a future version.Will always return null. You should not need access to a general context object. -
getRealm
RealmModel getRealm() -
setRealm
-
getClient
ClientModel getClient() -
setClient
-
getOrganization
OrganizationModel getOrganization() -
setOrganization
-
getConnection
ClientConnection getConnection()If there is no active request, aClientConnectionwill still be returned -
resolveLocale
-
resolveLocale
-
resolveLocale
-
getAuthenticationSession
AuthenticationSessionModel getAuthenticationSession()Get current AuthenticationSessionModel, can be null out of the AuthenticationSession context.- Returns:
- current AuthenticationSessionModel or null
-
setAuthenticationSession
-
getHttpRequest
HttpRequest getHttpRequest()If there is no active request, aContextNotActiveExceptionwill be thrown -
getHttpResponse
HttpResponse getHttpResponse()If there is no active request, aContextNotActiveExceptionwill be thrown -
setConnection
-
setHttpRequest
-
setHttpResponse
-
getUserSession
UserSessionModel getUserSession() -
setUserSession
-
getBearerToken
Token getBearerToken()Returns aTokenrepresenting the bearer token used to authenticate and authorize the current request.- Returns:
- the bearer token
-
setBearerToken
-
getUser
UserModel getUser()Returns theUserModelbound to this context. The user is first resolved from thegetBearerToken()set to this context, if any. Otherwise, it will be resolved from thegetUserSession()set to this context, if any.- Returns:
- the
UserModelbound to this context.
-
getPermissions
Permissions getPermissions()Returns the permissions evaluator that can be used to check if the current user has permissions to perform an action on realm resources.- Returns:
- the permissions evaluator
-
getHttpRequest()to obtain the request headers.