Class DefaultCartCookieIssuer
- java.lang.Object
-
- com.broadleafcommerce.cartoperation.web.service.DefaultCartCookieIssuer
-
- All Implemented Interfaces:
CartCookieIssuer
public class DefaultCartCookieIssuer extends Object implements CartCookieIssuer
- Author:
- Chris Kittrell (ckittrell)
- See Also:
CartCookieIssuer
-
-
Constructor Summary
Constructors Constructor Description DefaultCartCookieIssuer(CartCookieProperties cookieProps)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddCartCookieClaims(com.nimbusds.jwt.JWTClaimsSet.Builder jwtBuilder, com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)javax.servlet.http.CookiebuildCartCookie(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Build a cookie to hold a reference to a cart.javax.servlet.http.CookiebuildCartExpirationCookie(String applicationId)Build a cookie meant to remove the cart cookie for the provided application.org.springframework.http.ResponseCookiebuildCartResponseCookie(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Build a cookie to hold a reference to a cart.booleancheckContextMatches(Map<String,Object> cartCookieClaims, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Check if the provided cookie claims match the context.protected StringgetApplicationId(com.broadleafcommerce.cart.client.domain.Cart cart)StringgetCartCookieName(String applicationId)Name of the cart cookie.protected DurationgetCartTtl()protected booleanisApplicationIdIncludedInCookieName()Optional<String>resolveCartId(Map<String,Object> cartCookieClaims)Resolve the cart id from the provided cookie claims.protected <T> Optional<T>resolveClaim(Map<String,Object> cartCookieClaims, String name, Class<T> clazz)protected Optional<com.nimbusds.jwt.SignedJWT>verify(javax.servlet.http.Cookie cartCookie)Map<String,Object>verifyAndGetClaims(@NonNull javax.servlet.http.Cookie cartCookie)Verify the provided cart cookie and get its claims.
-
-
-
Constructor Detail
-
DefaultCartCookieIssuer
public DefaultCartCookieIssuer(CartCookieProperties cookieProps)
-
-
Method Detail
-
buildCartCookie
public javax.servlet.http.Cookie buildCartCookie(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Description copied from interface:CartCookieIssuerBuild a cookie to hold a reference to a cart. If the cart is for a logged in user, no cart ID claim will be part of the cookie.- Specified by:
buildCartCookiein interfaceCartCookieIssuer- Parameters:
cart- The cart for which to build a cookie.contextInfo- Context information around sandbox and multitenant state.- Returns:
- The cart cookie to be added to the response.
-
buildCartResponseCookie
public org.springframework.http.ResponseCookie buildCartResponseCookie(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Description copied from interface:CartCookieIssuerBuild a cookie to hold a reference to a cart. If the cart is for a logged in user, no cart ID claim will be part of the cookie.- Specified by:
buildCartResponseCookiein interfaceCartCookieIssuer- Parameters:
cart- The cart for which to build a cookie.contextInfo- Context information around sandbox and multitenant state.- Returns:
- The cart cookie to be added to the response.
-
addCartCookieClaims
protected void addCartCookieClaims(com.nimbusds.jwt.JWTClaimsSet.Builder jwtBuilder, com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
-
getApplicationId
protected String getApplicationId(com.broadleafcommerce.cart.client.domain.Cart cart)
-
buildCartExpirationCookie
public javax.servlet.http.Cookie buildCartExpirationCookie(String applicationId)
Description copied from interface:CartCookieIssuerBuild a cookie meant to remove the cart cookie for the provided application.- Specified by:
buildCartExpirationCookiein interfaceCartCookieIssuer- Parameters:
applicationId- Application id used to identify which cart cookie to remove.- Returns:
- An immediately expiring cookie to be added to the response.
-
verifyAndGetClaims
public Map<String,Object> verifyAndGetClaims(@NonNull @NonNull javax.servlet.http.Cookie cartCookie)
Description copied from interface:CartCookieIssuerVerify the provided cart cookie and get its claims.- Specified by:
verifyAndGetClaimsin interfaceCartCookieIssuer- Parameters:
cartCookie- The cookie to use for retrieving the claims- Returns:
- The claims on the cart cookie
-
resolveCartId
public Optional<String> resolveCartId(Map<String,Object> cartCookieClaims)
Description copied from interface:CartCookieIssuerResolve the cart id from the provided cookie claims. Expect an empty response for registered user cart cookies.- Specified by:
resolveCartIdin interfaceCartCookieIssuer- Parameters:
cartCookieClaims- The cookie claims to use for retrieving the cart id.- Returns:
- Optional cart id for the provided cookie claims.
-
resolveClaim
protected <T> Optional<T> resolveClaim(Map<String,Object> cartCookieClaims, String name, Class<T> clazz)
-
verify
protected Optional<com.nimbusds.jwt.SignedJWT> verify(javax.servlet.http.Cookie cartCookie) throws ParseException, com.nimbusds.jose.JOSEException
- Throws:
ParseExceptioncom.nimbusds.jose.JOSEException
-
getCartCookieName
public String getCartCookieName(@Nullable String applicationId)
Description copied from interface:CartCookieIssuerName of the cart cookie.- Specified by:
getCartCookieNamein interfaceCartCookieIssuer- Parameters:
applicationId- Application id that may be appended to the cookie name.- Returns:
- The name of the cart cookie.
-
checkContextMatches
public boolean checkContextMatches(Map<String,Object> cartCookieClaims, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Description copied from interface:CartCookieIssuerCheck if the provided cookie claims match the context.- Specified by:
checkContextMatchesin interfaceCartCookieIssuer- Parameters:
cartCookieClaims- The cookie claims to use for retrieving the cart id.contextInfo- Context information around sandbox and multitenant state.- Returns:
- Whether the provided cookie claims matches the context
-
isApplicationIdIncludedInCookieName
protected boolean isApplicationIdIncludedInCookieName()
-
getCartTtl
protected Duration getCartTtl()
-
-