use of org.wso2.carbon.identity.oauth.cache.OAuthScopeCacheKey in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2ScopeService method getScope.
/**
* @param name Name of the scope which need to get retrieved
* @return Retrieved Scope
* @throws IdentityOAuth2ScopeException
*/
public Scope getScope(String name) throws IdentityOAuth2ScopeException {
Scope scope;
int tenantID = Oauth2ScopeUtils.getTenantID();
validateScopeName(name);
scope = OAuthScopeCache.getInstance().getValueFromCache(new OAuthScopeCacheKey(name), tenantID);
if (scope == null) {
try {
scope = OAuthTokenPersistenceFactory.getInstance().getOAuthScopeDAO().getScopeByName(name, tenantID);
if (scope != null) {
if (log.isDebugEnabled()) {
log.debug("Scope is getting from the database. \n" + scope.toString());
}
OAuthScopeCache.getInstance().addToCache(new OAuthScopeCacheKey(name), scope, tenantID);
}
} catch (IdentityOAuth2ScopeServerException e) {
throw Oauth2ScopeUtils.generateServerException(Oauth2ScopeConstants.ErrorMessages.ERROR_CODE_FAILED_TO_GET_SCOPE_BY_NAME, name, e);
}
}
if (scope == null) {
throw Oauth2ScopeUtils.generateClientException(Oauth2ScopeConstants.ErrorMessages.ERROR_CODE_NOT_FOUND_SCOPE, name);
}
return scope;
}
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 depends on scope type. Type can be OAUTH2 scopes or OIDC scopes.
*
* @param name Name of the scope.
* @param includeOIDCScopes Include OIDC scopes as well.
* @return True if scope with the given scope name exists.
* @throws IdentityOAuth2ScopeException
*/
public boolean isScopeExists(String name, boolean includeOIDCScopes) 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, includeOIDCScopes);
} catch (IdentityOAuth2ScopeServerException e) {
throw Oauth2ScopeUtils.generateServerException(Oauth2ScopeConstants.ErrorMessages.ERROR_CODE_FAILED_TO_GET_SCOPE_BY_NAME, name, e);
}
}
return isScopeExists;
}
use of org.wso2.carbon.identity.oauth.cache.OAuthScopeCacheKey in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2ScopeService method registerScope.
/**
* Register a scope with the bindings
*
* @param scope details of the scope to be registered
* @throws IdentityOAuth2ScopeServerException
*/
public Scope registerScope(Scope scope) throws IdentityOAuth2ScopeException {
addScopePreValidation(scope);
// Check whether a scope exists with the provided scope name or not regardless of scope type. We don't allow
// to register same scope name across OAuth2 and OIDC scope endpoints. We keep the scope name as unique.
boolean isScopeExists = isScopeExists(scope.getName(), true);
if (isScopeExists) {
// Rechecking to see if the existing scope is an OIDC scope to improve error response.
if (isScopeExists(scope.getName(), false)) {
throw Oauth2ScopeUtils.generateClientException(Oauth2ScopeConstants.ErrorMessages.ERROR_CODE_CONFLICT_REQUEST_EXISTING_SCOPE, scope.getName());
} else {
throw Oauth2ScopeUtils.generateClientException(Oauth2ScopeConstants.ErrorMessages.ERROR_CODE_CONFLICT_REQUEST_EXISTING_SCOPE_OIDC, scope.getName());
}
}
int tenantID = Oauth2ScopeUtils.getTenantID();
try {
OAuthTokenPersistenceFactory.getInstance().getOAuthScopeDAO().addScope(scope, tenantID);
if (log.isDebugEnabled()) {
log.debug("Scope is added to the database. \n" + scope.toString());
}
} catch (IdentityOAuth2ScopeServerException e) {
throw Oauth2ScopeUtils.generateServerException(Oauth2ScopeConstants.ErrorMessages.ERROR_CODE_FAILED_TO_REGISTER_SCOPE, scope.toString(), e);
}
OAuthScopeCache.getInstance().addToCache(new OAuthScopeCacheKey(scope.getName()), scope, tenantID);
return scope;
}
use of org.wso2.carbon.identity.oauth.cache.OAuthScopeCacheKey in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2ScopeService method updateScope.
/**
* Update the scope of the given scope ID
*
* @param updatedScope details of updated scope
* @return updated scope
* @throws IdentityOAuth2ScopeException
*/
public Scope updateScope(Scope updatedScope) throws IdentityOAuth2ScopeException {
updateScopePreValidation(updatedScope);
// Check whether a scope exists with the provided scope name which to be deleted.
validateScopeExistence(updatedScope.getName());
int tenantID = Oauth2ScopeUtils.getTenantID();
try {
OAuthTokenPersistenceFactory.getInstance().getOAuthScopeDAO().updateScopeByName(updatedScope, tenantID);
} catch (IdentityOAuth2ScopeServerException e) {
throw Oauth2ScopeUtils.generateServerException(Oauth2ScopeConstants.ErrorMessages.ERROR_CODE_FAILED_TO_UPDATE_SCOPE_BY_NAME, updatedScope.getName(), e);
}
OAuthScopeCache.getInstance().addToCache(new OAuthScopeCacheKey(updatedScope.getName()), updatedScope, tenantID);
OIDCScopeClaimCache.getInstance().clearScopeClaimMap(tenantID);
return updatedScope;
}
use of org.wso2.carbon.identity.oauth.cache.OAuthScopeCacheKey in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2ScopeService method deleteScope.
/**
* Delete the scope for the given scope ID
*
* @param name Scope ID of the scope which need to get deleted
* @throws IdentityOAuth2ScopeException
*/
public void deleteScope(String name) throws IdentityOAuth2ScopeException {
validateScopeName(name);
// Check whether a scope exists with the provided scope name which to be deleted.
validateScopeExistence(name);
int tenantID = Oauth2ScopeUtils.getTenantID();
OAuthScopeCache.getInstance().clearCacheEntry(new OAuthScopeCacheKey(name), tenantID);
try {
OAuthTokenPersistenceFactory.getInstance().getOAuthScopeDAO().deleteScopeByName(name, tenantID);
if (log.isDebugEnabled()) {
log.debug("Scope: " + name + " is deleted from the database.");
}
} catch (IdentityOAuth2ScopeServerException e) {
throw Oauth2ScopeUtils.generateServerException(Oauth2ScopeConstants.ErrorMessages.ERROR_CODE_FAILED_TO_DELETE_SCOPE_BY_NAME, name, e);
}
}
Aggregations