Search in sources :

Example 1 with OAuthScopeBindingCacheKey

use of org.wso2.carbon.identity.oauth.cache.OAuthScopeBindingCacheKey in project identity-inbound-auth-oauth by wso2-extensions.

the class JDBCPermissionBasedInternalScopeValidator method getScopesOfPermissionType.

private Set<Scope> getScopesOfPermissionType(int tenantId) throws IdentityOAuth2ScopeServerException {
    if (Oauth2ScopeUtils.isSystemLevelInternalSystemScopeManagementEnabled()) {
        List<Scope> oauthScopeBinding = OAuth2ServiceComponentHolder.getInstance().getOauthScopeBinding();
        return new HashSet<>(oauthScopeBinding);
    }
    Scope[] scopesFromCache = OAuthScopeBindingCache.getInstance().getValueFromCache(new OAuthScopeBindingCacheKey(PERMISSION_BINDING_TYPE), tenantId);
    Set<Scope> allScopes;
    if (scopesFromCache != null) {
        allScopes = Arrays.stream(scopesFromCache).collect(Collectors.toSet());
    } else {
        allScopes = OAuthTokenPersistenceFactory.getInstance().getOAuthScopeDAO().getScopes(tenantId, PERMISSION_BINDING_TYPE);
        if (CollectionUtils.isNotEmpty(allScopes)) {
            OAuthScopeBindingCache.getInstance().addToCache(new OAuthScopeBindingCacheKey(PERMISSION_BINDING_TYPE), allScopes.toArray(new Scope[0]), tenantId);
        }
    }
    return allScopes;
}
Also used : Scope(org.wso2.carbon.identity.oauth2.bean.Scope) OAuthScopeBindingCacheKey(org.wso2.carbon.identity.oauth.cache.OAuthScopeBindingCacheKey) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 OAuthScopeBindingCacheKey (org.wso2.carbon.identity.oauth.cache.OAuthScopeBindingCacheKey)1 Scope (org.wso2.carbon.identity.oauth2.bean.Scope)1