Interface KeycloakContext

All Known Implementing Classes:
DefaultKeycloakContext

public interface KeycloakContext
Author:
Stian Thorgersen
  • 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 jakarta.ws.rs.core.HttpHeaders getRequestHeaders()
      Deprecated.
      Use getHttpRequest() 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 use getUri(UrlType) method calls on the returned KeycloakUriInfo may throw a ContextNotActiveException if no request is active
    • getUri

      KeycloakUriInfo getUri(UrlType type)
      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 KeycloakUriInfo may throw a ContextNotActiveException if 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(forRemoval=true) default <T> T getContextObject(Class<T> clazz)
      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

      void setRealm(RealmModel realm)
    • getClient

      ClientModel getClient()
    • setClient

      void setClient(ClientModel client)
    • getOrganization

      OrganizationModel getOrganization()
    • setOrganization

      void setOrganization(OrganizationModel organization)
    • getConnection

      ClientConnection getConnection()
      If there is no active request, a ClientConnection will still be returned
    • resolveLocale

      Locale resolveLocale(UserModel user)
    • resolveLocale

      default Locale resolveLocale(UserModel user, Theme.Type themeType)
    • resolveLocale

      default Locale resolveLocale(UserModel user, boolean ignoreAcceptLanguageHeader)
    • getAuthenticationSession

      AuthenticationSessionModel getAuthenticationSession()
      Get current AuthenticationSessionModel, can be null out of the AuthenticationSession context.
      Returns:
      current AuthenticationSessionModel or null
    • setAuthenticationSession

      void setAuthenticationSession(AuthenticationSessionModel authenticationSession)
    • getHttpRequest

      HttpRequest getHttpRequest()
      If there is no active request, a ContextNotActiveException will be thrown
    • getHttpResponse

      HttpResponse getHttpResponse()
      If there is no active request, a ContextNotActiveException will be thrown
    • setConnection

      void setConnection(ClientConnection clientConnection)
    • setHttpRequest

      void setHttpRequest(HttpRequest httpRequest)
    • setHttpResponse

      void setHttpResponse(HttpResponse httpResponse)
    • getUserSession

      UserSessionModel getUserSession()
    • setUserSession

      void setUserSession(UserSessionModel session)
    • getBearerToken

      Token getBearerToken()
      Returns a Token representing the bearer token used to authenticate and authorize the current request.
      Returns:
      the bearer token
    • setBearerToken

      void setBearerToken(Token token)
    • getUser

      UserModel getUser()
      Returns the UserModel bound to this context. The user is first resolved from the getBearerToken() set to this context, if any. Otherwise, it will be resolved from the getUserSession() set to this context, if any.
      Returns:
      the UserModel bound 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