Class AbstractUserTokenEnhancer
java.lang.Object
com.broadleafcommerce.auth.user.session.token.enhancer.AbstractUserTokenEnhancer
- All Implemented Interfaces:
org.springframework.security.oauth2.provider.token.TokenEnhancer
- Direct Known Subclasses:
AccountIdTokenEnhancer,CustomerContextTokenEnhancer,CustomerSegmentsTokenEnhancer,TenantPropertiesTokenEnhancer,UserRestrictionTokenEnhancer,UserTokenEnhancer
public abstract class AbstractUserTokenEnhancer
extends Object
implements org.springframework.security.oauth2.provider.token.TokenEnhancer
Implementation of
TokenEnhancer that has a request scoped UserContext that contains the
current user to avoid repeated database reads. TokenEnhancer implementations that require access
to the User should extend this class and retrieve the user via the
getUser(OAuth2Authentication) method.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetRequestAccountId(org.springframework.security.oauth2.provider.OAuth2Authentication authentication) Looks for an account ID on the request.getUser(org.springframework.security.oauth2.provider.OAuth2Authentication authentication) Retrieve the current authenticatedUser.Return the request scoped user context bean.protected UserService<User>protected booleanisAnonymousCsrImpersonation(org.springframework.security.oauth2.provider.OAuth2Authentication authentication) Check whether or not the current authentication is a CSR impersonation of an anonymous user.voidsetUserContext(UserContext userContext) voidsetUserService(UserService<User> userService) protected booleanshouldEnhance(org.springframework.security.oauth2.common.OAuth2AccessToken accessToken, org.springframework.security.oauth2.provider.OAuth2Authentication authentication) Whether or not the token should be enhanced.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.security.oauth2.provider.token.TokenEnhancer
enhance
-
Constructor Details
-
AbstractUserTokenEnhancer
public AbstractUserTokenEnhancer()
-
-
Method Details
-
getUser
public User getUser(org.springframework.security.oauth2.provider.OAuth2Authentication authentication) Retrieve the current authenticatedUser. This method assumes that the user is logged in and exists. In other words,OAuth2Authentication.isClientOnly()should return false if this method is to be called.Note that the user is cached at the request scope. Any calls after the first call to this method during the same request will return the same user, regardless of the argument passed.
- Parameters:
authentication- TheOAuth2Authenticationobject passed toTokenEnhancer.enhance(OAuth2AccessToken, OAuth2Authentication)- Returns:
- The currently authenticated user.
- Throws:
com.broadleafcommerce.data.tracking.core.exception.EntityMissingException- ifUseris not found.- See Also:
-
isAnonymousCsrImpersonation
protected boolean isAnonymousCsrImpersonation(org.springframework.security.oauth2.provider.OAuth2Authentication authentication) Check whether or not the current authentication is a CSR impersonation of an anonymous user.- Parameters:
authentication- TheOAuth2Authenticationobject passed toTokenEnhancer.enhance(OAuth2AccessToken, OAuth2Authentication)- Returns:
- Whether the current authentication is a CSR impersonation of an anonymous user
-
shouldEnhance
protected boolean shouldEnhance(org.springframework.security.oauth2.common.OAuth2AccessToken accessToken, org.springframework.security.oauth2.provider.OAuth2Authentication authentication) Whether or not the token should be enhanced.- Parameters:
accessToken- the current access token with its expiration and refresh tokenauthentication- TheOAuth2Authenticationobject passed toTokenEnhancer.enhance(OAuth2AccessToken, OAuth2Authentication)- Returns:
- Whether or not the token should be enhanced.
-
setUserService
-
setUserContext
-
getUserContext
Return the request scoped user context bean. If not in a request scope, null is returned.- Returns:
- The
userContextif in scope.
-
getRequestAccountId
public Optional<String> getRequestAccountId(org.springframework.security.oauth2.provider.OAuth2Authentication authentication) Looks for an account ID on the request. If it exists, it is returned. Otherwise, if the user has adefault account ID, that is returned.- Parameters:
authentication- The OAuth authentication token. This holds the original request to get a token.- Returns:
- The accountId requested or
Optional.empty().
-
getUserService
-