Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push pwd grant authenticated user attributes to sessionStore #2216

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,10 @@ public OAuth2AccessTokenRespDTO issue(OAuth2AccessTokenReqDTO tokenReqDTO)
cacheUserAttributesAgainstAccessToken(authorizationGrantCacheEntry.get(), tokenRespDTO);
}

if (GrantType.PASSWORD.toString().equals(grantType)) {
addUserAttributesAgainstAccessTokenForPasswordGrant(tokenRespDTO, tokReqMsgCtx);
}

if (GrantType.AUTHORIZATION_CODE.toString().equals(grantType)) {
// Cache entry against the authorization code has no value beyond the token request.
clearCacheEntryAgainstAuthorizationCode(getAuthorizationCode(tokenReqDTO));
Expand Down Expand Up @@ -1094,6 +1098,21 @@ private void cacheUserAttributesAgainstAccessToken(AuthorizationGrantCacheEntry
AuthorizationGrantCache.getInstance().addToCacheByToken(newCacheKey, authorizationGrantCacheEntry);
}

private void addUserAttributesAgainstAccessTokenForPasswordGrant(OAuth2AccessTokenRespDTO tokenRespDTO,
OAuthTokenReqMessageContext tokReqMsgCtx) {

if (tokReqMsgCtx.getAuthorizedUser() != null) {
AuthorizationGrantCacheKey newCacheKey = new AuthorizationGrantCacheKey(tokenRespDTO.getAccessToken());
AuthorizationGrantCacheEntry authorizationGrantCacheEntry =
new AuthorizationGrantCacheEntry(tokReqMsgCtx.getAuthorizedUser().getUserAttributes());
authorizationGrantCacheEntry.setTokenId(tokenRespDTO.getTokenId());

authorizationGrantCacheEntry.setValidityPeriod(
TimeUnit.MILLISECONDS.toNanos(tokenRespDTO.getExpiresInMillis()));
AuthorizationGrantCache.getInstance().addToCacheByToken(newCacheKey, authorizationGrantCacheEntry);
}
}

private void clearCacheEntryAgainstAuthorizationCode(String authorizationCode) {

AuthorizationGrantCacheKey oldCacheKey = new AuthorizationGrantCacheKey(authorizationCode);
Expand Down