Class AccessTokenServiceInternalImpl
java.lang.Object
org.craftercms.studio.impl.v2.service.security.internal.AccessTokenServiceInternalImpl
- All Implemented Interfaces:
AccessTokenServiceInternal,org.springframework.beans.factory.InitializingBean
public class AccessTokenServiceInternalImpl
extends Object
implements AccessTokenServiceInternal, org.springframework.beans.factory.InitializingBean
Default implementation of
AccessTokenServiceInternal- Since:
- 4.0
- Author:
- joseross
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final intThe time in minutes for the expiration of the generated access tokensstatic final Stringprotected StringThe audience for generation and validation of access tokensprotected final AuditServiceInternalprotected final StringThe password for encrypting the access tokensprotected final intTime in minutes after which inactive users will be required to login againprotected final InstanceServiceprotected final StringThe issuer for generation access tokensprotected Keyprotected Keyprotected final org.craftercms.commons.crypto.TextEncryptorprotected final RetryingDatabaseOperationFacadeprotected final SecurityDAOprotected final SecurityServiceprotected final intTime in minutes after which active users will be required to login againprotected final StringThe password for signing the access tokensprotected final SiteServiceprotected final StudioConfigurationprotected final SystemStatusProviderCache used to track the activity of the usersprotected final String[]List of accepted issuers for validation of access tokens -
Constructor Summary
ConstructorsConstructorDescriptionAccessTokenServiceInternalImpl(String issuer, String[] validIssuers, int accessTokenExpiration, String signPassword, String encryptPassword, int sessionTimeout, int inactivityTimeout, SecurityDAO securityDao, InstanceService instanceService, AuditServiceInternal auditService, StudioConfiguration studioConfiguration, SiteService siteService, RetryingDatabaseOperationFacade retryingDatabaseOperationFacade, SystemStatusProvider systemStatusProvider, org.craftercms.commons.crypto.TextEncryptor previewTokenEncryptor, SecurityService securityService) -
Method Summary
Modifier and TypeMethodDescriptionvoidcreateAccessToken(String label, Instant expiresAt) Creates a new access token for the current userprotected voidcreateAuditLog(String actor, long tokenId, String type, String operation) protected voidcreateAuditLog(String actor, long tokenId, String type, String value, String operation) protected voidcreateAuditLog(org.springframework.security.core.Authentication auth, long tokenId, String type, String operation) protected StringcreateToken(Instant issuedAt, Instant expiresAt, String username, Long id) createTokens(org.springframework.security.core.Authentication auth, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Creates the access & refresh tokens for the given authenticationvoiddeleteAccessToken(long tokenId) Deletes an access token for the current uservoidDeletes all expired refresh tokensvoiddeletePreviewCookie(jakarta.servlet.http.HttpServletResponse response) Deletes the preview cookievoiddeleteRefreshToken(long userId) Deletes the refresh token for the given uservoiddeleteUsersTokens(List<Long> userIds) Deletes all the tokens for the given usersGet all existing access tokens for the current userprotected Stringprotected longgetUserId(org.springframework.security.core.Authentication auth) getUsername(String token) Returns the username for the given access tokenbooleanhasValidRefreshToken(org.springframework.security.core.Authentication auth, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Checks if the given request contains a valid refresh tokenvoidrefreshPreviewCookie(org.springframework.security.core.Authentication auth, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, boolean silent) Refresh the preview site cookie.voidsetAudience(String audience) voidsetPreviewCookieGenerator(org.springframework.web.util.CookieGenerator previewCookieGenerator) voidsetRefreshTokenCookieGenerator(org.springframework.web.util.CookieGenerator refreshTokenCookieGenerator) updateAccessToken(long tokenId, boolean enabled) Updates an access token for the current uservoidupdateRefreshToken(org.springframework.security.core.Authentication auth, jakarta.servlet.http.HttpServletResponse response) Updates the refresh token for the given responsevoidupdateUserActivity(org.springframework.security.core.Authentication authentication) Updates the user activity record to extend the timeout
-
Field Details
-
ACTIVITY_CACHE_CONFIG_KEY
- See Also:
-
issuer
The issuer for generation access tokens -
validIssuers
List of accepted issuers for validation of access tokens -
audience
The audience for generation and validation of access tokens -
accessTokenExpiration
protected final int accessTokenExpirationThe time in minutes for the expiration of the generated access tokens -
signPassword
The password for signing the access tokens -
encryptPassword
The password for encrypting the access tokens -
sessionTimeout
protected final int sessionTimeoutTime in minutes after which active users will be required to login again -
inactivityTimeout
protected final int inactivityTimeoutTime in minutes after which inactive users will be required to login again -
userActivity
Cache used to track the activity of the users -
jwtSignKey
-
jwtEncryptKey
-
securityDao
-
securityService
-
instanceService
-
auditService
-
studioConfiguration
-
siteService
-
retryingDatabaseOperationFacade
-
systemStatusProvider
-
previewTokenEncryptor
protected final org.craftercms.commons.crypto.TextEncryptor previewTokenEncryptor
-
-
Constructor Details
-
AccessTokenServiceInternalImpl
@ConstructorProperties({"issuer","validIssuers","accessTokenExpiration","signPassword","encryptPassword","sessionTimeout","inactivityTimeout","securityDao","instanceService","auditService","studioConfiguration","siteService","retryingDatabaseOperationFacade","systemStatusProvider","previewTokenEncryptor","securityService"}) public AccessTokenServiceInternalImpl(String issuer, String[] validIssuers, int accessTokenExpiration, String signPassword, String encryptPassword, int sessionTimeout, int inactivityTimeout, SecurityDAO securityDao, InstanceService instanceService, AuditServiceInternal auditService, StudioConfiguration studioConfiguration, SiteService siteService, RetryingDatabaseOperationFacade retryingDatabaseOperationFacade, SystemStatusProvider systemStatusProvider, org.craftercms.commons.crypto.TextEncryptor previewTokenEncryptor, SecurityService securityService)
-
-
Method Details
-
setAudience
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
hasValidRefreshToken
public boolean hasValidRefreshToken(org.springframework.security.core.Authentication auth, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Description copied from interface:AccessTokenServiceInternalChecks if the given request contains a valid refresh token- Specified by:
hasValidRefreshTokenin interfaceAccessTokenServiceInternal- 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, jakarta.servlet.http.HttpServletResponse response) Description copied from interface:AccessTokenServiceInternalUpdates the refresh token for the given response- Specified by:
updateRefreshTokenin interfaceAccessTokenServiceInternal- Parameters:
auth- the current authenticationresponse- the response
-
refreshPreviewCookie
public void refreshPreviewCookie(org.springframework.security.core.Authentication auth, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, boolean silent) throws ServiceLayerException Description copied from interface:AccessTokenServiceInternalRefresh 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:
refreshPreviewCookiein interfaceAccessTokenServiceInternal- Parameters:
auth- the current authenticationrequest- the requestresponse- the responsesilent- 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:AccessTokenServiceInternalDeletes the preview cookie- Specified by:
deletePreviewCookiein interfaceAccessTokenServiceInternal- Parameters:
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:AccessTokenServiceInternalCreates the access & refresh tokens for the given authentication- Specified by:
createTokensin interfaceAccessTokenServiceInternal- Parameters:
auth- the current authenticationrequest- the requestresponse- 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:AccessTokenServiceInternalDeletes the refresh token for the given user- Specified by:
deleteRefreshTokenin interfaceAccessTokenServiceInternal- Parameters:
userId- the id of the user
-
deleteExpiredRefreshTokens
public void deleteExpiredRefreshTokens()Description copied from interface:AccessTokenServiceInternalDeletes all expired refresh tokens- Specified by:
deleteExpiredRefreshTokensin interfaceAccessTokenServiceInternal
-
createAccessToken
public PersistentAccessToken createAccessToken(String label, Instant expiresAt) throws ServiceLayerException Description copied from interface:AccessTokenServiceInternalCreates a new access token for the current user- Specified by:
createAccessTokenin interfaceAccessTokenServiceInternal- 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
Description copied from interface:AccessTokenServiceInternalGet all existing access tokens for the current user- Specified by:
getAccessTokensin interfaceAccessTokenServiceInternal- Returns:
- the list of access tokens
-
updateAccessToken
Description copied from interface:AccessTokenServiceInternalUpdates an access token for the current user- Specified by:
updateAccessTokenin interfaceAccessTokenServiceInternal- Parameters:
tokenId- the id of the access tokenenabled- indicates if the token is enabled or not- Returns:
- the updated access token
-
deleteAccessToken
public void deleteAccessToken(long tokenId) Description copied from interface:AccessTokenServiceInternalDeletes an access token for the current user- Specified by:
deleteAccessTokenin interfaceAccessTokenServiceInternal- Parameters:
tokenId- the id of the access token
-
deleteUsersTokens
Description copied from interface:AccessTokenServiceInternalDeletes all the tokens for the given users- Specified by:
deleteUsersTokensin interfaceAccessTokenServiceInternal- Parameters:
userIds- the user ids list
-
getActualAudience
-
getUsername
Description copied from interface:AccessTokenServiceInternalReturns the username for the given access token- Specified by:
getUsernamein interfaceAccessTokenServiceInternal- Parameters:
token- the access token- Returns:
- the username, null if the access token is invalid
-
getUserId
protected long getUserId(org.springframework.security.core.Authentication auth) -
createToken
protected String createToken(Instant issuedAt, Instant expiresAt, String username, Long id) throws ServiceLayerException - Throws:
ServiceLayerException
-
createAuditLog
-
createAuditLog
-
createAuditLog
-
updateUserActivity
public void updateUserActivity(org.springframework.security.core.Authentication authentication) Description copied from interface:AccessTokenServiceInternalUpdates the user activity record to extend the timeout- Specified by:
updateUserActivityin interfaceAccessTokenServiceInternal- Parameters:
authentication- the current authentication
-
setRefreshTokenCookieGenerator
public void setRefreshTokenCookieGenerator(org.springframework.web.util.CookieGenerator refreshTokenCookieGenerator) -
setPreviewCookieGenerator
public void setPreviewCookieGenerator(org.springframework.web.util.CookieGenerator previewCookieGenerator)
-