use of org.wso2.carbon.identity.oauth.cache.AuthorizationGrantCacheEntry in project identity-inbound-auth-oauth by wso2-extensions.
the class DefaultOIDCClaimsCallbackHandler method isTokenHasCustomUserClaims.
/**
* To check whether a token has custom user claims.
*
* @param refreshTokenValidationDataDO RefreshTokenValidationDataDO.
* @return true if the token user attributes has non OIDC claims.
*/
private boolean isTokenHasCustomUserClaims(RefreshTokenValidationDataDO refreshTokenValidationDataDO) {
AuthorizationGrantCacheKey cacheKey = new AuthorizationGrantCacheKey(refreshTokenValidationDataDO.getAccessToken());
AuthorizationGrantCacheEntry cacheEntry = AuthorizationGrantCache.getInstance().getValueFromCacheByToken(cacheKey);
boolean hasNonOIDCClaims = cacheEntry != null && cacheEntry.isHasNonOIDCClaims();
if (log.isDebugEnabled()) {
log.debug("hasNonOIDCClaims is set to " + hasNonOIDCClaims + " for the access token of the user : " + refreshTokenValidationDataDO.getAuthorizedUser());
}
return cacheEntry != null && cacheEntry.isHasNonOIDCClaims();
}
use of org.wso2.carbon.identity.oauth.cache.AuthorizationGrantCacheEntry in project identity-inbound-auth-oauth by wso2-extensions.
the class DefaultOIDCClaimsCallbackHandler method getUserAttributesFromCacheUsingCode.
/**
* Get user attributes cached against the authorization code.
*
* @param authorizationCode Authorization Code
* @return User attributes cached against the authorization code
*/
private Map<ClaimMapping, String> getUserAttributesFromCacheUsingCode(String authorizationCode) {
if (log.isDebugEnabled()) {
if (IdentityUtil.isTokenLoggable(IdentityConstants.IdentityTokens.AUTHORIZATION_CODE)) {
log.debug("Retrieving user attributes cached against authorization code: " + authorizationCode);
} else {
log.debug("Retrieving user attributes cached against authorization code.");
}
}
AuthorizationGrantCacheKey cacheKey = new AuthorizationGrantCacheKey(authorizationCode);
AuthorizationGrantCacheEntry cacheEntry = AuthorizationGrantCache.getInstance().getValueFromCacheByCode(cacheKey);
return cacheEntry == null ? new HashMap<>() : cacheEntry.getUserAttributes();
}
use of org.wso2.carbon.identity.oauth.cache.AuthorizationGrantCacheEntry in project identity-inbound-auth-oauth by wso2-extensions.
the class TokenResponseTypeHandler method addUserAttributesToCache.
private void addUserAttributesToCache(String accessToken, OAuthAuthzReqMessageContext msgCtx) throws IdentityOAuth2Exception {
OAuth2AuthorizeReqDTO authorizeReqDTO = msgCtx.getAuthorizationReqDTO();
Map<ClaimMapping, String> userAttributes = authorizeReqDTO.getUser().getUserAttributes();
AuthorizationGrantCacheKey authorizationGrantCacheKey = new AuthorizationGrantCacheKey(accessToken);
AuthorizationGrantCacheEntry authorizationGrantCacheEntry = new AuthorizationGrantCacheEntry(userAttributes);
if (StringUtils.isNotBlank(authorizeReqDTO.getEssentialClaims())) {
authorizationGrantCacheEntry.setEssentialClaims(authorizeReqDTO.getEssentialClaims());
}
if (authorizeReqDTO.getRequestObject() != null) {
authorizationGrantCacheEntry.setRequestObject(authorizeReqDTO.getRequestObject());
}
if (authorizeReqDTO.getAuthTime() != 0) {
authorizationGrantCacheEntry.setAuthTime(authorizeReqDTO.getAuthTime());
}
if (authorizeReqDTO.getMaxAge() != 0) {
authorizationGrantCacheEntry.setMaxAge(authorizeReqDTO.getMaxAge());
}
ClaimMapping key = new ClaimMapping();
Claim claimOfKey = new Claim();
claimOfKey.setClaimUri(OAuth2Util.SUB);
key.setRemoteClaim(claimOfKey);
String sub = userAttributes.get(key);
AccessTokenDO accessTokenDO = getAccessTokenDO(accessToken, msgCtx);
if (accessTokenDO != null && StringUtils.isNotBlank(accessTokenDO.getTokenId())) {
authorizationGrantCacheEntry.setTokenId(accessTokenDO.getTokenId());
if (StringUtils.isBlank(sub)) {
sub = authorizeReqDTO.getUser().getAuthenticatedSubjectIdentifier();
}
if (StringUtils.isNotBlank(sub)) {
if (log.isDebugEnabled() && IdentityUtil.isTokenLoggable(IdentityConstants.IdentityTokens.USER_CLAIMS)) {
log.debug("Setting subject: " + sub + " as the sub claim in cache against the access token.");
}
authorizationGrantCacheEntry.setSubjectClaim(sub);
}
authorizationGrantCacheEntry.setValidityPeriod(TimeUnit.MILLISECONDS.toNanos(accessTokenDO.getValidityPeriodInMillis()));
AuthorizationGrantCache.getInstance().addToCacheByToken(authorizationGrantCacheKey, authorizationGrantCacheEntry);
}
}
use of org.wso2.carbon.identity.oauth.cache.AuthorizationGrantCacheEntry in project identity-inbound-auth-oauth by wso2-extensions.
the class ResponseTypeHandlerUtil method addUserAttributesToCache.
private static void addUserAttributesToCache(String accessToken, OAuthAuthzReqMessageContext msgCtx) throws IdentityOAuth2Exception {
OAuth2AuthorizeReqDTO authorizeReqDTO = msgCtx.getAuthorizationReqDTO();
Map<ClaimMapping, String> userAttributes = authorizeReqDTO.getUser().getUserAttributes();
AuthorizationGrantCacheKey authorizationGrantCacheKey = new AuthorizationGrantCacheKey(accessToken);
AuthorizationGrantCacheEntry authorizationGrantCacheEntry = new AuthorizationGrantCacheEntry(userAttributes);
if (StringUtils.isNotBlank(authorizeReqDTO.getEssentialClaims())) {
authorizationGrantCacheEntry.setEssentialClaims(authorizeReqDTO.getEssentialClaims());
}
ClaimMapping key = new ClaimMapping();
Claim claimOfKey = new Claim();
claimOfKey.setClaimUri(OAuth2Util.SUB);
key.setRemoteClaim(claimOfKey);
String sub = null;
try {
sub = authorizeReqDTO.getUser().getUserId();
} catch (UserIdNotFoundException e) {
// Ignoring the unavailability of the user id, since it is handled later.
}
AccessTokenDO accessTokenDO = getAccessTokenDO(accessToken, msgCtx);
if (accessTokenDO != null && StringUtils.isNotBlank(accessTokenDO.getTokenId())) {
authorizationGrantCacheEntry.setTokenId(accessTokenDO.getTokenId());
}
if (StringUtils.isBlank(sub)) {
sub = authorizeReqDTO.getUser().getAuthenticatedSubjectIdentifier();
}
if (StringUtils.isNotBlank(sub)) {
userAttributes.put(key, sub);
}
authorizationGrantCacheEntry.setValidityPeriod(TimeUnit.MILLISECONDS.toNanos(accessTokenDO.getValidityPeriodInMillis()));
AuthorizationGrantCache.getInstance().addToCacheByToken(authorizationGrantCacheKey, authorizationGrantCacheEntry);
}
use of org.wso2.carbon.identity.oauth.cache.AuthorizationGrantCacheEntry in project identity-inbound-auth-oauth by wso2-extensions.
the class ClaimProviderImpl method getAdditionalClaims.
@Override
public Map<String, Object> getAdditionalClaims(OAuthTokenReqMessageContext oAuthTokenReqMessageContext, OAuth2AccessTokenRespDTO oAuth2AccessTokenRespDTO) throws IdentityOAuth2Exception {
Map<String, Object> additionalClaims = new HashMap<>();
String claimValue = null;
String accessCode = oAuthTokenReqMessageContext.getOauth2AccessTokenReqDTO().getAuthorizationCode();
if (StringUtils.isBlank(accessCode)) {
if (log.isDebugEnabled()) {
log.debug("AccessCode is null. Possibly a back end grant");
}
return additionalClaims;
}
AuthorizationGrantCacheEntry authzGrantCacheEntry = getAuthorizationGrantCacheEntryFromCode(accessCode);
if (authzGrantCacheEntry != null) {
claimValue = authzGrantCacheEntry.getOidcSessionId();
}
if (claimValue != null) {
if (log.isDebugEnabled()) {
log.debug("sid claim is found in the session state");
}
additionalClaims.put("sid", claimValue);
}
return additionalClaims;
}
Aggregations