java.lang.Object
net.datenwerke.oidc.client.provider.keycloak.Keycloak
All Implemented Interfaces:
OidcService, OidcProvider
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

public class Keycloak extends Object implements OidcService
The class used when interacting with the keycloak javascript library.
  • Field Details

  • Constructor Details

    • Keycloak

      public Keycloak()
  • Method Details

    • isAuthenticated

      public boolean isAuthenticated()
      Is true if the user is authenticated, false otherwise.
    • getToken

      public String getToken()
      The base64 encoded access token that can be sent in the Authorization header in requests to services.
      Specified by:
      getToken in interface OidcProvider
      Returns:
      The jwt access token or null if no session.
    • getParsedToken

      public <T> T getParsedToken()
      The parsed access token as a JavaScript object.
    • getSubject

      public String getSubject()
      The user id.
    • getIdToken

      public String getIdToken()
      The base64 encoded ID token.
      Specified by:
      getIdToken in interface OidcProvider
      Returns:
      the ID token or null if no ID token is available
    • getParsedIdToken

      public <T> T getParsedIdToken()
      The parsed id token as a JavaScript object.
    • getRefreshToken

      public String getRefreshToken()
      The base64 encoded refresh token.
    • getParsedRefreshToken

      public <T> T getParsedRefreshToken()
      The parsed refresh token as a JavaScript object.
    • login

      public void login(String locale)
      Redirects to the login form on (options is an optional object with redirectUri and/or prompt fields).
      Specified by:
      login in interface OidcProvider
      Parameters:
      locale - The locale to be used on oidc provider login page.
    • login

      public void login(LoginOptions options)
    • getLogoutUrl

      public String getLogoutUrl(String redirectUri)
      Description copied from interface: OidcProvider
      Returns the url that needs to be called to terminate the session of the implementing oidc provider containing the redirect uri where the user is redirected to after logout.
      Specified by:
      getLogoutUrl in interface OidcProvider
      Parameters:
      redirectUri - The redirect uri to be included in the logout url.
      Returns:
      The oidc logout url including the redirect uri.
    • logout

      public void logout()
      Redirects to the logout url.
    • logout

      public void logout(LogoutOptions options)
    • updateToken

      public void updateToken(int minValiditySeconds, Runnable successCallback, Runnable failureCallback)
      If the token expires within minValidity seconds the token is refreshed. If the session status iframe is enabled, the session status is also checked. On failure the tokens are cleared.
    • updateToken

      public void updateToken(int minValiditySeconds, Runnable successCallback)
      Invokes updateToken(int, Runnable, Runnable) with null failureCallback.
    • updateToken

      public void updateToken(Runnable successCallback)
      Invokes updateToken(int, Runnable) with MIN_TOKEN_VALIDITY_SECONDS for minValiditySeconds.
    • updateTokenAndExecute

      public void updateTokenAndExecute(int minValiditySeconds, Runnable action)
      Ensure that the token does not expire in next minValiditySeconds or update token and execute action. Actions are queued until valid tokens are received and then executed.
      Parameters:
      minValiditySeconds - the minimum token validity.
      action - the action to perform once a valid token is present.
    • updateTokenAndExecute

      public void updateTokenAndExecute(Runnable action)
      Invokes updateTokenAndExecute(int, Runnable) with MIN_TOKEN_VALIDITY_SECONDS for minValiditySeconds.
      Parameters:
      action - the action to perform once a valid token is present.
    • isTokenExpired

      public boolean isTokenExpired(int minValiditySeconds)
      Returns true if the token has less than minValiditySeconds seconds left before it expires.
    • isTokenExpired

      public boolean isTokenExpired()
      Returns true if the token is expired.
    • registerCallback

      public void registerCallback(OidcCallback callback)
      Description copied from interface: OidcProvider
      Register any OidcCallback at the implementing oidc provider.
      Specified by:
      registerCallback in interface OidcProvider
      Parameters:
      callback - The callback to register.
    • addHiddenAuthField

      public void addHiddenAuthField(Container container)
    • tryUpdateToken

      public void tryUpdateToken(Runnable runnable)