Class AccessTokenServiceImpl

java.lang.Object
org.craftercms.studio.impl.v2.service.security.AccessTokenServiceImpl
All Implemented Interfaces:
AccessTokenService

public class AccessTokenServiceImpl extends Object implements AccessTokenService
Default implementation of AccessTokenService
Since:
4.0
Author:
joseross
  • Field Details

  • Constructor Details

  • Method Details

    • hasValidRefreshToken

      public boolean hasValidRefreshToken(org.springframework.security.core.Authentication auth, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
      Description copied from interface: AccessTokenService
      Checks if the given request contains a valid refresh token
      Specified by:
      hasValidRefreshToken in interface AccessTokenService
      Parameters:
      auth - the current authentication
      request - the request to check
      response - the response
      Returns:
      true if the request contains a valid refresh token
    • updateRefreshToken

      public void updateRefreshToken(org.springframework.security.core.Authentication auth, jakarta.servlet.http.HttpServletResponse response)
      Description copied from interface: AccessTokenService
      Updates the refresh token for the given response
      Specified by:
      updateRefreshToken in interface AccessTokenService
      Parameters:
      auth - the current authentication
      response - the response
    • createTokens

      public AccessToken createTokens(org.springframework.security.core.Authentication auth, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws ServiceLayerException
      Description copied from interface: AccessTokenService
      Creates the access & refresh tokens for the given authentication
      Specified by:
      createTokens in interface AccessTokenService
      Parameters:
      auth - the current authentication
      request - the request
      response - the response
      Returns:
      the access token
      Throws:
      ServiceLayerException - if there is any error creating the access token
    • deleteRefreshToken

      public void deleteRefreshToken(long userId)
      Description copied from interface: AccessTokenService
      Deletes the refresh token for the given user
      Specified by:
      deleteRefreshToken in interface AccessTokenService
      Parameters:
      userId - the id of the user
    • deleteExpiredRefreshTokens

      public void deleteExpiredRefreshTokens()
      Description copied from interface: AccessTokenService
      Deletes all expired refresh tokens
      Specified by:
      deleteExpiredRefreshTokens in interface AccessTokenService
    • createAccessToken

      public PersistentAccessToken createAccessToken(String label, Instant expiresAt) throws ServiceLayerException
      Description copied from interface: AccessTokenService
      Creates a new access token for the current user
      Specified by:
      createAccessToken in interface AccessTokenService
      Parameters:
      label - the label of the access token
      expiresAt - the date of expiration of the access token
      Returns:
      the access token
      Throws:
      ServiceLayerException - if there is any error creating the access token
    • getAccessTokens

      public List<PersistentAccessToken> getAccessTokens()
      Description copied from interface: AccessTokenService
      Get all existing access tokens for the current user
      Specified by:
      getAccessTokens in interface AccessTokenService
      Returns:
      the list of access tokens
    • updateAccessToken

      public PersistentAccessToken updateAccessToken(long id, boolean enabled)
      Description copied from interface: AccessTokenService
      Updates an access token for the current user
      Specified by:
      updateAccessToken in interface AccessTokenService
      Parameters:
      id - the id of the access token
      enabled - indicates if the token is enabled or not
      Returns:
      the updated access token
    • deleteAccessToken

      public void deleteAccessToken(long id)
      Description copied from interface: AccessTokenService
      Deletes an access token for the current user
      Specified by:
      deleteAccessToken in interface AccessTokenService
      Parameters:
      id - the id of the access token
    • getUsername

      public String getUsername(String token)
      Description copied from interface: AccessTokenService
      Returns the username for the given access token
      Specified by:
      getUsername in interface AccessTokenService
      Parameters:
      token - the access token
      Returns:
      the username, null if the access token is invalid
    • updateUserActivity

      public void updateUserActivity(org.springframework.security.core.Authentication authentication)
      Description copied from interface: AccessTokenService
      Updates the user activity record to extend the timeout
      Specified by:
      updateUserActivity in interface AccessTokenService
      Parameters:
      authentication - the current authentication
    • refreshPreviewCookie

      public void refreshPreviewCookie(org.springframework.security.core.Authentication authentication, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, boolean silent) throws ServiceLayerException
      Description copied from interface: AccessTokenService
      Refresh the preview site cookie. This method will either update the cookie (or create it) with the current preview site if the user has access to it, or remove it if they do not.
      Specified by:
      refreshPreviewCookie in interface AccessTokenService
      Parameters:
      authentication - the current authentication
      request - the request
      response - the response
      silent - if false, the method will throw an exception if the user does not have access to the preview site
      Throws:
      ServiceLayerException
    • deletePreviewCookie

      public void deletePreviewCookie(jakarta.servlet.http.HttpServletResponse response)
      Description copied from interface: AccessTokenService
      Deletes the preview cookie
      Specified by:
      deletePreviewCookie in interface AccessTokenService
      Parameters:
      response - the response