Class CurrentUserCacheAccessTokenEnhancer
java.lang.Object
com.broadleafcommerce.auth.user.session.token.enhancer.CurrentUserCacheAccessTokenEnhancer
- All Implemented Interfaces:
JwtAccessTokenEnhancer
,org.springframework.core.Ordered
Many access token enhancers
need to obtain information from the
currently authenticated User
.
To avoid having each of those enhancers read from the database multiple times, this early-ordered
component pre-fetches the User
once and caches it in
JwtTokenEnhancerContext.getAdditionalContext()
. Subsequent enhancers (typically
extensions of AbstractUserAccessTokenEnhancer
) can then obtain the pre-fetched user from
there to get any information they need.
This component does not actually add any claims to the access token.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The key used by this component to store a value inJwtTokenEnhancerContext.getAdditionalContext()
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
ConstructorsConstructorDescriptionCurrentUserCacheAccessTokenEnhancer
(TokenEnhancerUtility tokenEnhancerUtility, UserService<User> userService) -
Method Summary
Modifier and TypeMethodDescriptionvoid
enhance
(JwtTokenEnhancerContext context) Evaluate the authentication and add claims as necessary.int
getOrder()
protected Optional<OAuth2SessionToken>
getSessionToken
(org.springframework.security.core.Authentication userPrincipal) Get thesession token
from theauthentication token
.protected TokenEnhancerUtility
protected String
getUserIdFromSession
(org.springframework.security.core.Authentication userPrincipal) Read theUser
ID from the session token.protected UserService<User>
protected User
readUser
(org.springframework.security.core.Authentication userPrincipal)
-
Field Details
-
CURRENT_USER
The key used by this component to store a value inJwtTokenEnhancerContext.getAdditionalContext()
- See Also:
-
-
Constructor Details
-
CurrentUserCacheAccessTokenEnhancer
public CurrentUserCacheAccessTokenEnhancer(TokenEnhancerUtility tokenEnhancerUtility, UserService<User> userService)
-
-
Method Details
-
enhance
Description copied from interface:JwtAccessTokenEnhancer
Evaluate the authentication and add claims as necessary. AJwtTokenEnhancerContext
contains User and client authentication tokens, authorization tokens, and access token claims.- Specified by:
enhance
in interfaceJwtAccessTokenEnhancer
- Parameters:
context
- TheJwtTokenEnhancerContext
to evaluate.
-
readUser
-
getUserIdFromSession
@Nullable protected String getUserIdFromSession(org.springframework.security.core.Authentication userPrincipal) Read theUser
ID from the session token.- Parameters:
userPrincipal
- The Authentication representing the User.- Returns:
- The User ID from the session token, or null if it is not available.
-
getSessionToken
protected Optional<OAuth2SessionToken> getSessionToken(org.springframework.security.core.Authentication userPrincipal) Get thesession token
from theauthentication token
.- Parameters:
userPrincipal
- TheOAuth2SessionAuthenticationToken
of the User.- Returns:
- An Optional with the
OAuth2SessionToken
if available, or empty.
-
getOrder
public int getOrder()- Specified by:
getOrder
in interfaceJwtAccessTokenEnhancer
- Specified by:
getOrder
in interfaceorg.springframework.core.Ordered
-
getTokenEnhancerUtility
-
getUserService
-