use of org.wso2.carbon.identity.oauth.cache.AuthorizationGrantCache in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuthApplicationMgtListener method clearCacheEntriesAgainstToken.
private void clearCacheEntriesAgainstToken(Set<AccessTokenDO> accessTokenDOSet) {
for (AccessTokenDO accessTokenDo : accessTokenDOSet) {
// Remove access token from AuthorizationGrantCache
AuthorizationGrantCacheKey grantCacheKey = new AuthorizationGrantCacheKey(accessTokenDo.getAccessToken());
AuthorizationGrantCache.getInstance().clearCacheEntryByTokenId(grantCacheKey, accessTokenDo.getTokenId());
// Remove access token from OAuthCache
OAuthCacheKey oauthCacheKey = new OAuthCacheKey(accessTokenDo.getAccessToken());
CacheEntry oauthCacheEntry = OAuthCache.getInstance().getValueFromCache(oauthCacheKey);
if (oauthCacheEntry != null) {
OAuthCache.getInstance().clearCacheEntry(oauthCacheKey);
}
}
}
use of org.wso2.carbon.identity.oauth.cache.AuthorizationGrantCache in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuthApplicationMgtListener method clearCacheEntriesAgainstAuthzCode.
private void clearCacheEntriesAgainstAuthzCode(Set<AuthzCodeDO> authzCodeDOSet) {
for (AuthzCodeDO authzCodeDO : authzCodeDOSet) {
// Remove authorization code from AuthorizationGrantCache
AuthorizationGrantCacheKey grantCacheKey = new AuthorizationGrantCacheKey(authzCodeDO.getAuthorizationCode());
AuthorizationGrantCache.getInstance().clearCacheEntryByCodeId(grantCacheKey, authzCodeDO.getAuthzCodeId());
// Remove authorization code from OAuthCache
OAuthCacheKey oauthCacheKey = new OAuthCacheKey(authzCodeDO.getAuthorizationCode());
CacheEntry oauthCacheEntry = OAuthCache.getInstance().getValueFromCache(oauthCacheKey);
if (oauthCacheEntry != null) {
OAuthCache.getInstance().clearCacheEntry(oauthCacheKey);
}
}
}
use of org.wso2.carbon.identity.oauth.cache.AuthorizationGrantCache in project identity-inbound-auth-oauth by wso2-extensions.
the class AccessTokenIssuer method addUserAttributesAgainstAccessToken.
/**
* Copies the cache entry against the authorization code and adds an entry against the access token. This is done to
* reuse the calculated user claims for subsequent usages such as user info calls.
*
* @param tokenReqDTO
* @param tokenRespDTO
*/
private void addUserAttributesAgainstAccessToken(OAuth2AccessTokenReqDTO tokenReqDTO, OAuth2AccessTokenRespDTO tokenRespDTO) {
AuthorizationGrantCacheKey oldCacheKey = new AuthorizationGrantCacheKey(getAuthorizationCode(tokenReqDTO));
// checking getUserAttributesId value of cacheKey before retrieve entry from cache as it causes to NPE
if (oldCacheKey.getUserAttributesId() != null) {
AuthorizationGrantCacheEntry authorizationGrantCacheEntry = AuthorizationGrantCache.getInstance().getValueFromCacheByCode(oldCacheKey);
AuthorizationGrantCacheKey newCacheKey = new AuthorizationGrantCacheKey(tokenRespDTO.getAccessToken());
if (authorizationGrantCacheEntry != null) {
authorizationGrantCacheEntry.setTokenId(tokenRespDTO.getTokenId());
if (log.isDebugEnabled()) {
if (IdentityUtil.isTokenLoggable(IdentityConstants.IdentityTokens.ACCESS_TOKEN)) {
log.debug("Adding AuthorizationGrantCache entry for the access token(hashed):" + DigestUtils.sha256Hex(newCacheKey.getUserAttributesId()));
} else {
log.debug("Adding AuthorizationGrantCache entry for the access token");
}
}
authorizationGrantCacheEntry.setValidityPeriod(TimeUnit.MILLISECONDS.toNanos(tokenRespDTO.getExpiresInMillis()));
AuthorizationGrantCache.getInstance().addToCacheByToken(newCacheKey, authorizationGrantCacheEntry);
}
}
}
use of org.wso2.carbon.identity.oauth.cache.AuthorizationGrantCache in project identity-inbound-auth-oauth by wso2-extensions.
the class IdentityOathEventListenerTest method testDoPreSetUserClaimValueWithAuthorizationCode.
@Test
public void testDoPreSetUserClaimValueWithAuthorizationCode() throws Exception {
Set<String> accessToken = new HashSet<>();
accessToken.add("kljdslfjljdsfjldsflkdsjkfjdsjlkj");
Set<String> authorizationCodes = new HashSet<String>();
authorizationCodes.add("AUTHORIZATION_CODE");
AuthorizationGrantCache authorizationGrantCache = mock(AuthorizationGrantCache.class);
when(UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration())).thenReturn("DOMAIN_NAME");
when(IdentityTenantUtil.getTenantDomain(anyInt())).thenReturn("TENANT_DOMAIN_NAME");
whenNew(AuthenticatedUser.class).withNoArguments().thenReturn(authenticatedUser);
when(AuthorizationGrantCache.getInstance()).thenReturn(authorizationGrantCache);
IdentityOathEventListener identityOathEventListener = new IdentityOathEventListener();
assertTrue(identityOathEventListener.doPreSetUserClaimValue(username, claimUri, claimValue, profileName, userStoreManager));
}
use of org.wso2.carbon.identity.oauth.cache.AuthorizationGrantCache in project identity-inbound-auth-oauth by wso2-extensions.
the class IdentityOathEventListenerTest method testDoPreSetUserClaimValue.
@Test
public void testDoPreSetUserClaimValue() throws Exception {
Set<String> accessToken = new HashSet<>();
accessToken.add("kljdslfjljdsfjldsflkdsjkfjdsjlkj");
AuthorizationGrantCache authorizationGrantCache = mock(AuthorizationGrantCache.class);
when(UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration())).thenReturn("DOMAIN_NAME");
when(IdentityTenantUtil.getTenantDomain(anyInt())).thenReturn("TENANT_DOMAIN_NAME");
whenNew(AuthenticatedUser.class).withNoArguments().thenReturn(authenticatedUser);
when(AuthorizationGrantCache.getInstance()).thenReturn(authorizationGrantCache);
IdentityOathEventListener identityOathEventListener = new IdentityOathEventListener();
assertTrue(identityOathEventListener.doPreSetUserClaimValue(username, claimUri, claimValue, profileName, userStoreManager));
}
Aggregations