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)
StatelessUtil
OAuth2SessionToken
for the provided client ID and subject with the set of
additional claims.getSessionToken
in interface StatelessUtil
clientId
- 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)
StatelessUtil
OAuth2SessionToken
with a refreshed expiration time.refreshSessionToken
in interface StatelessUtil
sessionToken
- the session tokenpublic com.nimbusds.jwt.SignedJWT generateSignedJwt(@Nullable String subject, @Nullable Map<String,Object> claims, @Nullable Long expiresInSeconds)
StatelessUtil
generateSignedJwt
in interface StatelessUtil
subject
- The subject of the JWTclaims
- Additional claims to add to the JWTpublic String getRedirectUrl(javax.servlet.http.Cookie savedRequestCookie)
StatelessUtil
getRedirectUrl
in interface StatelessUtil
savedRequestCookie
- see StatelessUtil.createSavedRequestCookie(String, String)
StatelessUtil.createSavedRequestCookie(String, String)
public String getRequestUrl(javax.servlet.http.Cookie savedRequestCookie)
StatelessUtil
getRequestUrl
in interface StatelessUtil
savedRequestCookie
- see StatelessUtil.createSavedRequestCookie(String, String)
StatelessUtil.createSavedRequestCookie(String, String)
public String getClientId(String savedRequestToken)
getClientId
in interface StatelessUtil
protected String getDecodedClaim(javax.servlet.http.Cookie savedRequestCookie, String claim, String errorMessage)
public Map<String,Object> getCookieClaims(String cookieValue)
StatelessUtil
getCookieClaims
in interface StatelessUtil
public javax.servlet.http.Cookie createSessionCookie(OAuth2SessionToken sessionToken)
StatelessUtil
OAuth2SessionToken
.createSessionCookie
in interface StatelessUtil
sessionToken
- the session tokenpublic javax.servlet.http.Cookie getRemoveSessionCookie(String clientId)
StatelessUtil
getRemoveSessionCookie
in interface StatelessUtil
public org.springframework.http.ResponseCookie getSessionCookie(OAuth2SessionToken sessionToken)
StatelessUtil
ResponseCookie
for the OAuth2SessionToken
.getSessionCookie
in interface StatelessUtil
sessionToken
- the session tokenpublic org.springframework.http.ResponseCookie getSessionRemovalCookie(String clientId)
StatelessUtil
ResponseCookie
for the removal of the session cookie.getSessionRemovalCookie
in interface StatelessUtil
clientId
- 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)
StatelessUtil
getSavedRequestCookie
in interface StatelessUtil
requestUrl
- 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)
StatelessUtil
createSavedRequestCookie
in interface StatelessUtil
requestUrl
- 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 StatelessUtil
public javax.servlet.http.Cookie getRemoveSavedRequestCookie()
StatelessUtil
getRemoveSavedRequestCookie
in interface StatelessUtil
public org.springframework.http.ResponseCookie createSavedRequestRemovalCookie()
StatelessUtil
createSavedRequestRemovalCookie
in interface StatelessUtil
StatelessUtil.createSavedRequestCookie(String, String)
public com.nimbusds.jwt.SignedJWT verify(String token)
StatelessUtil
verify
in interface StatelessUtil
token
- the cookie to verifypublic String getSessionCookieName(String clientId)
StatelessUtil
getSessionCookieName
in interface StatelessUtil
#getSessionCookie(String, String)
public String getSessionCookieName(AuthorizedClient client, AuthorizationServer server)
getSessionCookieName
in interface StatelessUtil
public String getIssuer()
getIssuer
in interface StatelessUtil
public String getSavedRequestCookieName()
StatelessUtil
getSavedRequestCookieName
in interface StatelessUtil
StatelessUtil.createSavedRequestCookie(String, String)
public org.springframework.http.ResponseCookie getRemovalCookie(javax.servlet.http.Cookie cookieToRemove)
StatelessUtil
getRemovalCookie
in interface StatelessUtil
cookieToRemove
- 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.