Class DefaultImpersonationService
- java.lang.Object
-
- com.broadleafcommerce.auth.user.service.DefaultImpersonationService
-
- All Implemented Interfaces:
ImpersonationService
public class DefaultImpersonationService extends Object implements ImpersonationService
- Author:
- Nick Crum (ncrum)
-
-
Field Summary
Fields Modifier and Type Field Description static String
CSR_CLIENT_ID
static String
CSR_ID
static String
IMPERSONATED_CLIENT_ID
static String
IMPERSONATED_SUB
protected static long
IMPERSONATION_TOKEN_EXP_TIME_SEC
static String
REDIRECT_URI
-
Constructor Summary
Constructors Constructor Description DefaultImpersonationService(ImpersonationClaimsEnhancer claimsEnhancer, StatelessUtil statelessUtil)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Map<String,Object>
buildImpersonationClaims(ImpersonationRequest request, org.springframework.security.core.Authentication authentication)
ImpersonationRequestToken
consumeImpersonationToken(String token)
Validates tokens generated byImpersonationService.generateImpersonationToken(ImpersonationRequest, Authentication)
and converts them into the originalImpersonationRequest
supplied before redirect.String
generateImpersonationRedirectUrl(String redirectUrl, com.nimbusds.jwt.SignedJWT token, String contextPath)
Generates a URL String containing a serialized signed JWT that should be redirected to in order to consume an impersonation token.com.nimbusds.jwt.SignedJWT
generateImpersonationToken(ImpersonationRequest request, org.springframework.security.core.Authentication authentication)
Generates a JWT to be used during redirects when impersonating a user.protected ImpersonationClaimsEnhancer
getClaimsEnhancer()
protected Object
getDetail(Map<String,Object> details, String key)
OAuth2SessionToken
getImpersonationSessionToken(ImpersonationRequestToken token, OAuth2UserDetails impersonatedUser)
Creates anOAuth2SessionToken
for the validatedImpersonationRequest
.protected StatelessUtil
getStatelessUtil()
-
-
-
Field Detail
-
IMPERSONATION_TOKEN_EXP_TIME_SEC
protected static final long IMPERSONATION_TOKEN_EXP_TIME_SEC
- See Also:
- Constant Field Values
-
REDIRECT_URI
public static final String REDIRECT_URI
- See Also:
- Constant Field Values
-
CSR_ID
public static final String CSR_ID
- See Also:
- Constant Field Values
-
CSR_CLIENT_ID
public static final String CSR_CLIENT_ID
- See Also:
- Constant Field Values
-
IMPERSONATED_SUB
public static final String IMPERSONATED_SUB
- See Also:
- Constant Field Values
-
IMPERSONATED_CLIENT_ID
public static final String IMPERSONATED_CLIENT_ID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DefaultImpersonationService
public DefaultImpersonationService(ImpersonationClaimsEnhancer claimsEnhancer, StatelessUtil statelessUtil)
-
-
Method Detail
-
getImpersonationSessionToken
public OAuth2SessionToken getImpersonationSessionToken(ImpersonationRequestToken token, OAuth2UserDetails impersonatedUser)
Description copied from interface:ImpersonationService
Creates anOAuth2SessionToken
for the validatedImpersonationRequest
.- Specified by:
getImpersonationSessionToken
in interfaceImpersonationService
- Parameters:
token
- The impersonation requestimpersonatedUser
- The user to be impersonated- Returns:
- A valid
OAuth2SessionToken
for the impersonated user with additional CSR claims.
-
generateImpersonationToken
public com.nimbusds.jwt.SignedJWT generateImpersonationToken(ImpersonationRequest request, org.springframework.security.core.Authentication authentication)
Description copied from interface:ImpersonationService
Generates a JWT to be used during redirects when impersonating a user. This allows impersonation across domains.- Specified by:
generateImpersonationToken
in interfaceImpersonationService
- Parameters:
request
- The impersonation request.authentication
- The current user's authentication- Returns:
- A signed JWT to be used during a redirect to the targeted domain.
-
generateImpersonationRedirectUrl
public String generateImpersonationRedirectUrl(String redirectUrl, com.nimbusds.jwt.SignedJWT token, String contextPath)
Description copied from interface:ImpersonationService
Generates a URL String containing a serialized signed JWT that should be redirected to in order to consume an impersonation token.- Specified by:
generateImpersonationRedirectUrl
in interfaceImpersonationService
- Parameters:
redirectUrl
- The redirect URL, typicallyImpersonationRequest.getRedirect_uri()
token
- The signed JWT, generated fromImpersonationService.generateImpersonationToken(ImpersonationRequest, Authentication)
contextPath
- The context path of the impersonation request- Returns:
- A URL to consume the impersonation token.
-
consumeImpersonationToken
public ImpersonationRequestToken consumeImpersonationToken(String token)
Description copied from interface:ImpersonationService
Validates tokens generated byImpersonationService.generateImpersonationToken(ImpersonationRequest, Authentication)
and converts them into the originalImpersonationRequest
supplied before redirect.- Specified by:
consumeImpersonationToken
in interfaceImpersonationService
- Parameters:
token
- The serialized signed JWT.- Returns:
- An impersonation request.
-
buildImpersonationClaims
protected Map<String,Object> buildImpersonationClaims(ImpersonationRequest request, org.springframework.security.core.Authentication authentication)
-
getClaimsEnhancer
@NonNull protected ImpersonationClaimsEnhancer getClaimsEnhancer()
-
getStatelessUtil
@NonNull protected StatelessUtil getStatelessUtil()
-
-