Search in sources :

Example 6 with OAuthScopeCacheKey

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

the class OAuth2ScopeService method isScopeExists.

/**
 * Check the existence of a scope
 *
 * @param name Name of the scope
 * @return true if scope with the given scope name exists
 * @throws IdentityOAuth2ScopeException
 */
public boolean isScopeExists(String name) throws IdentityOAuth2ScopeException {
    boolean isScopeExists;
    int tenantID = Oauth2ScopeUtils.getTenantID();
    if (name == null) {
        throw Oauth2ScopeUtils.generateClientException(Oauth2ScopeConstants.ErrorMessages.ERROR_CODE_BAD_REQUEST_SCOPE_NAME_NOT_SPECIFIED, null);
    }
    Scope scopeFromCache = OAuthScopeCache.getInstance().getValueFromCache(new OAuthScopeCacheKey(name), tenantID);
    if (scopeFromCache != null) {
        isScopeExists = true;
    } else {
        try {
            isScopeExists = OAuthTokenPersistenceFactory.getInstance().getOAuthScopeDAO().isScopeExists(name, tenantID);
        } catch (IdentityOAuth2ScopeServerException e) {
            throw Oauth2ScopeUtils.generateServerException(Oauth2ScopeConstants.ErrorMessages.ERROR_CODE_FAILED_TO_GET_SCOPE_BY_NAME, name, e);
        }
    }
    return isScopeExists;
}
Also used : Scope(org.wso2.carbon.identity.oauth2.bean.Scope) OAuthScopeCacheKey(org.wso2.carbon.identity.oauth.cache.OAuthScopeCacheKey)

Example 7 with OAuthScopeCacheKey

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

the class OAuth2ScopeServiceTest method testGetScope.

@Test(dataProvider = "ProvideCacheConfigurations")
public void testGetScope(boolean existWithinCache) throws Exception {
    String scopeName = "dummyName2";
    Scope dummyScope = new Scope(scopeName, SCOPE_DESCRIPTION, SCOPE_NAME);
    oAuth2ScopeService.registerScope(dummyScope);
    if (!existWithinCache) {
        OAuthScopeCache.getInstance().clearCacheEntry(new OAuthScopeCacheKey(scopeName), Integer.toString(Oauth2ScopeUtils.getTenantID()));
    }
    assertEquals(oAuth2ScopeService.getScope(scopeName).getName(), scopeName, "Retrieving registered scope is " + "failed");
    oAuth2ScopeService.deleteScope(scopeName);
}
Also used : Scope(org.wso2.carbon.identity.oauth2.bean.Scope) OAuthScopeCacheKey(org.wso2.carbon.identity.oauth.cache.OAuthScopeCacheKey) Test(org.testng.annotations.Test)

Aggregations

OAuthScopeCacheKey (org.wso2.carbon.identity.oauth.cache.OAuthScopeCacheKey)7 Scope (org.wso2.carbon.identity.oauth2.bean.Scope)4 Test (org.testng.annotations.Test)1