use of org.wso2.carbon.identity.oauth.cache.OAuthCache in project identity-inbound-auth-oauth by wso2-extensions.
the class ResponseTypeHandlerUtil method addTokenToCache.
private static void addTokenToCache(OAuthCacheKey cacheKey, AccessTokenDO tokenBean) {
OAuthCache.getInstance().addToCache(cacheKey, tokenBean);
// Adding AccessTokenDO to improve validation performance
OAuthCacheKey accessTokenCacheKey = new OAuthCacheKey(tokenBean.getAccessToken());
OAuthCache.getInstance().addToCache(accessTokenCacheKey, tokenBean);
if (log.isDebugEnabled()) {
log.debug("Access token info was added to the cache for cache key : " + cacheKey.getCacheKeyString());
if (IdentityUtil.isTokenLoggable(IdentityConstants.IdentityTokens.ACCESS_TOKEN)) {
log.debug("Access token was added to OAuthCache for cache key : " + accessTokenCacheKey.getCacheKeyString());
}
}
}
use of org.wso2.carbon.identity.oauth.cache.OAuthCache in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuthAdminServiceImpl method updateAndRetrieveOauthSecretKey.
/**
* Regenerate consumer secret for the application and retrieve application details.
*
* @param consumerKey Consumer key for the application.
* @return OAuthConsumerAppDTO OAuth application details.
* @throws IdentityOAuthAdminException Error while regenerating the consumer secret.
*/
public OAuthConsumerAppDTO updateAndRetrieveOauthSecretKey(String consumerKey) throws IdentityOAuthAdminException {
Properties properties = new Properties();
String newSecret = OAuthUtil.getRandomNumber();
properties.setProperty(OAuthConstants.OAUTH_APP_NEW_SECRET_KEY, newSecret);
properties.setProperty(OAuthConstants.ACTION_PROPERTY_KEY, OAuthConstants.ACTION_REGENERATE);
properties.setProperty(OAuthConstants.OAUTH_APP_NEW_STATE, APP_STATE_ACTIVE);
AppInfoCache.getInstance().clearCacheEntry(consumerKey);
updateAppAndRevokeTokensAndAuthzCodes(consumerKey, properties);
if (LOG.isDebugEnabled()) {
LOG.debug("Client Secret for OAuth app with consumerKey: " + consumerKey + " updated in OAuthCache.");
}
OAuthConsumerAppDTO updatedApplication = getOAuthApplicationData(consumerKey);
updatedApplication.setOauthConsumerSecret(newSecret);
return updatedApplication;
}
use of org.wso2.carbon.identity.oauth.cache.OAuthCache 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.OAuthCache 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.OAuthCache in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2Util method addTokenDOtoCache.
/**
* There are cases where we store an 'alias' of the token returned to the client as the token inside IS.
* For example, in the case of JWT access tokens we store the 'jti' claim in the database instead of the
* actual JWT. Therefore we need to cache an AccessTokenDO with the stored token identifier.
*
* @param newTokenBean token DO to be added to the cache.
*/
public static void addTokenDOtoCache(AccessTokenDO newTokenBean) throws IdentityOAuth2Exception {
OauthTokenIssuer tokenIssuer = null;
try {
tokenIssuer = OAuth2Util.getOAuthTokenIssuerForOAuthApp(newTokenBean.getConsumerKey());
String tokenAlias = tokenIssuer.getAccessTokenHash(newTokenBean.getAccessToken());
OAuthCacheKey accessTokenCacheKey = new OAuthCacheKey(tokenAlias);
AccessTokenDO tokenDO = AccessTokenDO.clone(newTokenBean);
tokenDO.setAccessToken(tokenAlias);
OAuthCache.getInstance().addToCache(accessTokenCacheKey, tokenDO);
if (log.isDebugEnabled()) {
if (IdentityUtil.isTokenLoggable(IdentityConstants.IdentityTokens.ACCESS_TOKEN)) {
log.debug("Access token DO was added to OAuthCache with cache key: " + accessTokenCacheKey.getCacheKeyString());
} else {
log.debug("Access token DO was added to OAuthCache");
}
}
} catch (OAuthSystemException e) {
if (IdentityUtil.isTokenLoggable(IdentityConstants.IdentityTokens.ACCESS_TOKEN)) {
throw new IdentityOAuth2Exception("Error while getting the token alias from token issuer: " + tokenIssuer.toString() + " for the token: " + newTokenBean.getAccessToken(), e);
} else {
throw new IdentityOAuth2Exception("Error while getting the token alias from token issuer: " + tokenIssuer.toString(), e);
}
} catch (InvalidOAuthClientException e) {
if (IdentityUtil.isTokenLoggable(IdentityConstants.IdentityTokens.ACCESS_TOKEN)) {
throw new IdentityOAuth2Exception("Error while getting the token issuer for the token: " + newTokenBean.getAccessToken(), e);
} else {
throw new IdentityOAuth2Exception("Error while getting the token issuer", e);
}
}
}
Aggregations