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 ofAccessTokenService
- Since:
- 4.0
- Author:
- joseross
-
-
Field Summary
Fields Modifier and Type Field Description protected AccessTokenServiceInternal
accessTokenServiceInternal
-
Constructor Summary
Constructors Constructor Description AccessTokenServiceImpl(AccessTokenServiceInternal accessTokenServiceInternal)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PersistentAccessToken
createAccessToken(String label, Instant expiresAt)
Creates a new access token for the current userAccessToken
createTokens(org.springframework.security.core.Authentication auth, javax.servlet.http.HttpServletResponse response)
Creates the access & refresh tokens for the given authenticationvoid
deleteAccessToken(long id)
Deletes an access token for the current uservoid
deleteExpiredRefreshTokens()
Deletes all expired refresh tokensvoid
deleteRefreshToken(org.springframework.security.core.Authentication auth)
Deletes the refresh token for the given authenticationList<PersistentAccessToken>
getAccessTokens()
Get all existing access tokens for the current userString
getUsername(String token)
Returns the username for the given access tokenboolean
hasValidRefreshToken(org.springframework.security.core.Authentication auth, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Checks if the given request contains a valid refresh tokenPersistentAccessToken
updateAccessToken(long id, boolean enabled)
Updates an access token for the current uservoid
updateRefreshToken(org.springframework.security.core.Authentication auth, javax.servlet.http.HttpServletResponse response)
Updates the refresh token for the given responsevoid
updateUserActivity(org.springframework.security.core.Authentication authentication)
Updates the user activity record to extend the timeout
-
-
-
Field Detail
-
accessTokenServiceInternal
protected AccessTokenServiceInternal accessTokenServiceInternal
-
-
Constructor Detail
-
AccessTokenServiceImpl
@ConstructorProperties("accessTokenServiceInternal") public AccessTokenServiceImpl(AccessTokenServiceInternal accessTokenServiceInternal)
-
-
Method Detail
-
hasValidRefreshToken
public boolean hasValidRefreshToken(org.springframework.security.core.Authentication auth, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
Description copied from interface:AccessTokenService
Checks if the given request contains a valid refresh token- Specified by:
hasValidRefreshToken
in interfaceAccessTokenService
- Parameters:
auth
- the current authenticationrequest
- the request to checkresponse
- the response- Returns:
- true if the request contains a valid refresh token
-
updateRefreshToken
public void updateRefreshToken(org.springframework.security.core.Authentication auth, javax.servlet.http.HttpServletResponse response)
Description copied from interface:AccessTokenService
Updates the refresh token for the given response- Specified by:
updateRefreshToken
in interfaceAccessTokenService
- Parameters:
auth
- the current authenticationresponse
- the response
-
createTokens
public AccessToken createTokens(org.springframework.security.core.Authentication auth, javax.servlet.http.HttpServletResponse response) throws ServiceLayerException
Description copied from interface:AccessTokenService
Creates the access & refresh tokens for the given authentication- Specified by:
createTokens
in interfaceAccessTokenService
- Parameters:
auth
- the current authenticationresponse
- the response- Returns:
- the access token
- Throws:
ServiceLayerException
- if there is any error creating the access token
-
deleteRefreshToken
public void deleteRefreshToken(org.springframework.security.core.Authentication auth)
Description copied from interface:AccessTokenService
Deletes the refresh token for the given authentication- Specified by:
deleteRefreshToken
in interfaceAccessTokenService
- Parameters:
auth
- the current authentication
-
deleteExpiredRefreshTokens
public void deleteExpiredRefreshTokens()
Description copied from interface:AccessTokenService
Deletes all expired refresh tokens- Specified by:
deleteExpiredRefreshTokens
in interfaceAccessTokenService
-
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 interfaceAccessTokenService
- Parameters:
label
- the label of the access tokenexpiresAt
- 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 interfaceAccessTokenService
- 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 interfaceAccessTokenService
- Parameters:
id
- the id of the access tokenenabled
- 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 interfaceAccessTokenService
- 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 interfaceAccessTokenService
- 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 interfaceAccessTokenService
- Parameters:
authentication
- the current authentication
-
-