public class StatelessUtilImpl extends Object implements StatelessUtil
StatelessUtil| Constructor and Description |
|---|
StatelessUtilImpl(AuthorizedClientService<AuthorizedClient> clientService,
AuthorizationServerService<AuthorizationServer> serverService,
String encodedPrivateKey,
String encodedPublicKey,
String issuer) |
| Modifier and Type | Method and Description |
|---|---|
org.springframework.http.ResponseCookie |
createSavedRequestCookie(String requestUrl,
String redirectUrl)
Create a cookie containing a JWT token identifying an originating request url and a redirect
url.
|
org.springframework.http.ResponseCookie |
createSavedRequestRemovalCookie()
Create a cookie that can be passed to the response to clear any existing saved request cookie
in the browser.
|
javax.servlet.http.Cookie |
createSessionCookie(OAuth2SessionToken sessionToken)
Creates a cookie for the
OAuth2SessionToken. |
protected Supplier<? extends com.broadleafcommerce.data.tracking.core.exception.EntityMissingException> |
entityMissing(String msg) |
protected AuthorizedClient |
findClient(String clientId) |
protected AuthorizationServer |
findServer(AuthorizedClient client) |
com.nimbusds.jwt.SignedJWT |
generateSignedJwt(String subject,
Map<String,Object> claims,
Long expiresInSeconds)
Generate a signed JWT with issuer and audience values as well as optional additional claims.
|
String |
getClientId(String savedRequestToken) |
Map<String,Object> |
getCookieClaims(String cookieValue)
Get a Map of the claims from a SignedJWT cookie.
|
protected String |
getDecodedClaim(javax.servlet.http.Cookie savedRequestCookie,
String claim,
String errorMessage) |
protected String |
getDecodedClaim(String token,
String claim,
String errorMessage) |
String |
getIssuer() |
protected StatelessUtilProperties |
getProperties() |
String |
getRedirectUrl(javax.servlet.http.Cookie savedRequestCookie)
Verify the JWT token contained in the cookie and then return the redirect url contained
therein.
|
org.springframework.http.ResponseCookie |
getRemovalCookie(javax.servlet.http.Cookie cookieToRemove)
Returns a removal cookie for any arbitrary cookie.
|
javax.servlet.http.Cookie |
getRemoveSavedRequestCookie()
Create a cookie that can be passed to the response to clear any existing saved request cookie
in the browser.
|
javax.servlet.http.Cookie |
getRemoveSessionCookie(String clientId)
Create a cookie that can be passed to the response to clear any existing session cookie in
the browser.
|
String |
getRequestUrl(javax.servlet.http.Cookie savedRequestCookie)
Verify the JWT token contained in the cookie and then return the original request url
contained therein.
|
protected String |
getSameSiteAttributeForSavedRequestCookie()
Gets the SameSite attribute value to use for the saved request cookies
(
createSavedRequestCookie(String, String) and
createSavedRequestRemovalCookie()). |
javax.servlet.http.Cookie |
getSavedRequestCookie(String requestUrl,
String redirectUrl)
Create a cookie containing a JWT token identifying an originating request url and a redirect
url.
|
String |
getSavedRequestCookieName()
Get the standard name for a saved request cookie
|
String |
getSavedRequestJwt(String requestUrl,
String redirectUrl) |
org.springframework.http.ResponseCookie |
getSessionCookie(OAuth2SessionToken sessionToken)
Gets a
ResponseCookie for the OAuth2SessionToken. |
String |
getSessionCookieName(AuthorizedClient client,
AuthorizationServer server) |
String |
getSessionCookieName(String clientId)
Get the standard name for a session cookie
|
org.springframework.http.ResponseCookie |
getSessionRemovalCookie(String clientId)
Gets a
ResponseCookie for the removal of the session cookie. |
protected String |
getSessionSameSiteAttribute(AuthorizationServer authorizationServer)
Gets the SameSite attribute value for the session cookie.
|
OAuth2SessionToken |
getSessionToken(String clientId,
String userId,
String subject,
Map<String,Object> additionalClaims)
Creates a
OAuth2SessionToken for the provided client ID and subject with the set of
additional claims. |
protected com.nimbusds.jwt.JWTClaimsSet |
getSessionTokenClaims(String clientId,
String userId,
String subject,
Map<String,Object> additionalClaims) |
OAuth2SessionToken |
refreshSessionToken(OAuth2SessionToken sessionToken)
Returns a
OAuth2SessionToken with a refreshed expiration time. |
void |
setProperties(StatelessUtilProperties properties) |
com.nimbusds.jwt.SignedJWT |
verify(String token)
Verify the signature of a signed JWT inside a cookie
|
public StatelessUtilImpl(AuthorizedClientService<AuthorizedClient> clientService, AuthorizationServerService<AuthorizationServer> serverService, @NonNull String encodedPrivateKey, @NonNull String encodedPublicKey, String issuer)
public OAuth2SessionToken getSessionToken(String clientId, String userId, String subject, Map<String,Object> additionalClaims)
StatelessUtilOAuth2SessionToken for the provided client ID and subject with the set of
additional claims.getSessionToken in interface StatelessUtilclientId - the client IDsubject - the user subjectadditionalClaims - the additional session claimsprotected com.nimbusds.jwt.JWTClaimsSet getSessionTokenClaims(String clientId, String userId, String subject, @NonNull Map<String,Object> additionalClaims)
public OAuth2SessionToken refreshSessionToken(OAuth2SessionToken sessionToken)
StatelessUtilOAuth2SessionToken with a refreshed expiration time.refreshSessionToken in interface StatelessUtilsessionToken - the session tokenpublic com.nimbusds.jwt.SignedJWT generateSignedJwt(@Nullable
String subject,
@Nullable
Map<String,Object> claims,
@Nullable
Long expiresInSeconds)
StatelessUtilgenerateSignedJwt in interface StatelessUtilsubject - The subject of the JWTclaims - Additional claims to add to the JWTpublic String getRedirectUrl(javax.servlet.http.Cookie savedRequestCookie)
StatelessUtilgetRedirectUrl in interface StatelessUtilsavedRequestCookie - see StatelessUtil.createSavedRequestCookie(String, String)StatelessUtil.createSavedRequestCookie(String, String)public String getRequestUrl(javax.servlet.http.Cookie savedRequestCookie)
StatelessUtilgetRequestUrl in interface StatelessUtilsavedRequestCookie - see StatelessUtil.createSavedRequestCookie(String, String)StatelessUtil.createSavedRequestCookie(String, String)public String getClientId(String savedRequestToken)
getClientId in interface StatelessUtilprotected String getDecodedClaim(javax.servlet.http.Cookie savedRequestCookie, String claim, String errorMessage)
public Map<String,Object> getCookieClaims(String cookieValue)
StatelessUtilgetCookieClaims in interface StatelessUtilpublic javax.servlet.http.Cookie createSessionCookie(OAuth2SessionToken sessionToken)
StatelessUtilOAuth2SessionToken.createSessionCookie in interface StatelessUtilsessionToken - the session tokenpublic javax.servlet.http.Cookie getRemoveSessionCookie(String clientId)
StatelessUtilgetRemoveSessionCookie in interface StatelessUtilpublic org.springframework.http.ResponseCookie getSessionCookie(OAuth2SessionToken sessionToken)
StatelessUtilResponseCookie for the OAuth2SessionToken.getSessionCookie in interface StatelessUtilsessionToken - the session tokenpublic org.springframework.http.ResponseCookie getSessionRemovalCookie(String clientId)
StatelessUtilResponseCookie for the removal of the session cookie.getSessionRemovalCookie in interface StatelessUtilclientId - the client IDprotected String getSessionSameSiteAttribute(AuthorizationServer authorizationServer)
Learn more about the SameSite attribute at: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite
authorizationServer - the authorization serverpublic javax.servlet.http.Cookie getSavedRequestCookie(String requestUrl, String redirectUrl)
StatelessUtilgetSavedRequestCookie in interface StatelessUtilrequestUrl - the original request (e.g. /oauth/authorize)redirectUrl - the uri to redirect to for authentication (e.g. /login)public org.springframework.http.ResponseCookie createSavedRequestCookie(String requestUrl, String redirectUrl)
StatelessUtilcreateSavedRequestCookie in interface StatelessUtilrequestUrl - the original request (e.g. /oauth/authorize)redirectUrl - the uri to redirect to for authentication (e.g. /login)protected String getSameSiteAttributeForSavedRequestCookie()
createSavedRequestCookie(String, String) and
createSavedRequestRemovalCookie()). This method should return one of the following
values: "None", "Lax", or "Strict".
Learn more about the SameSite attribute at: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite
public String getSavedRequestJwt(String requestUrl, String redirectUrl)
getSavedRequestJwt in interface StatelessUtilpublic javax.servlet.http.Cookie getRemoveSavedRequestCookie()
StatelessUtilgetRemoveSavedRequestCookie in interface StatelessUtilpublic org.springframework.http.ResponseCookie createSavedRequestRemovalCookie()
StatelessUtilcreateSavedRequestRemovalCookie in interface StatelessUtilStatelessUtil.createSavedRequestCookie(String, String)public com.nimbusds.jwt.SignedJWT verify(String token)
StatelessUtilverify in interface StatelessUtiltoken - the cookie to verifypublic String getSessionCookieName(String clientId)
StatelessUtilgetSessionCookieName in interface StatelessUtil#getSessionCookie(String, String)public String getSessionCookieName(AuthorizedClient client, AuthorizationServer server)
getSessionCookieName in interface StatelessUtilpublic String getIssuer()
getIssuer in interface StatelessUtilpublic String getSavedRequestCookieName()
StatelessUtilgetSavedRequestCookieName in interface StatelessUtilStatelessUtil.createSavedRequestCookie(String, String)public org.springframework.http.ResponseCookie getRemovalCookie(javax.servlet.http.Cookie cookieToRemove)
StatelessUtilgetRemovalCookie in interface StatelessUtilcookieToRemove - The cookie to target for removalHttpServletResponse to
remove the supplied cookie.protected AuthorizedClient findClient(String clientId)
protected AuthorizationServer findServer(AuthorizedClient client)
protected Supplier<? extends com.broadleafcommerce.data.tracking.core.exception.EntityMissingException> entityMissing(String msg)
protected StatelessUtilProperties getProperties()
@Autowired public void setProperties(StatelessUtilProperties properties)
Copyright © 2021. All rights reserved.