Class AccessTokenServiceInternalImpl
java.lang.Object
org.springframework.web.util.CookieGenerator
org.craftercms.studio.impl.v2.service.security.internal.AccessTokenServiceInternalImpl
- All Implemented Interfaces:
AccessTokenServiceInternal,org.springframework.beans.factory.InitializingBean
public class AccessTokenServiceInternalImpl
extends org.springframework.web.util.CookieGenerator
implements AccessTokenServiceInternal, org.springframework.beans.factory.InitializingBean
Default implementation of
AccessTokenServiceInternal- Since:
- 4.0
- Author:
- joseross
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intThe time in minutes for the expiration of the generated access tokensstatic final Stringprotected StringThe audience for generation and validation of access tokensprotected AuditServiceInternalprotected StringThe password for encrypting the access tokensprotected intTime in minutes after which inactive users will be required to login againprotected InstanceServiceprotected StringThe issuer for generation access tokensprotected Keyprotected Keyprotected RetryingDatabaseOperationFacadeprotected SecurityDAOprotected intTime in minutes after which active users will be required to login againprotected StringThe password for signing the access tokensprotected SiteServiceprotected StudioConfigurationprotected SystemStatusProviderCache used to track the activity of the usersprotected String[]List of accepted issuers for validation of access tokensFields inherited from class org.springframework.web.util.CookieGenerator
DEFAULT_COOKIE_PATH -
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) -
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, javax.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 tokensvoiddeleteRefreshToken(User user) Deletes the refresh token for the given uservoiddeleteRefreshToken(org.springframework.security.core.Authentication auth) Deletes the refresh token for the given authenticationvoiddeleteUsersTokens(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, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Checks if the given request contains a valid refresh tokenvoidsetAudience(String audience) updateAccessToken(long tokenId, boolean enabled) Updates an access token for the current uservoidupdateRefreshToken(org.springframework.security.core.Authentication auth, javax.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 timeoutMethods inherited from class org.springframework.web.util.CookieGenerator
addCookie, createCookie, getCookieDomain, getCookieMaxAge, getCookieName, getCookiePath, isCookieHttpOnly, isCookieSecure, removeCookie, setCookieDomain, setCookieHttpOnly, setCookieMaxAge, setCookieName, setCookiePath, setCookieSecure
-
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 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 int sessionTimeoutTime in minutes after which active users will be required to login again -
inactivityTimeout
protected 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
-
instanceService
-
auditService
-
studioConfiguration
-
siteService
-
retryingDatabaseOperationFacade
-
systemStatusProvider
-
-
Constructor Details
-
AccessTokenServiceInternalImpl
@ConstructorProperties({"issuer","validIssuers","accessTokenExpiration","signPassword","encryptPassword","sessionTimeout","inactivityTimeout","securityDao","instanceService","auditService","studioConfiguration","siteService","retryingDatabaseOperationFacade","systemStatusProvider"}) 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)
-
-
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, javax.servlet.http.HttpServletRequest request, javax.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, javax.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
-
createTokens
public AccessToken createTokens(org.springframework.security.core.Authentication auth, javax.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 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:AccessTokenServiceInternalDeletes the refresh token for the given authentication- Specified by:
deleteRefreshTokenin interfaceAccessTokenServiceInternal- Parameters:
auth- the current authentication
-
deleteRefreshToken
Description copied from interface:AccessTokenServiceInternalDeletes the refresh token for the given user- Specified by:
deleteRefreshTokenin interfaceAccessTokenServiceInternal- Parameters:
user- 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
-