use of org.wso2.carbon.identity.oauth2.IdentityOAuth2ScopeServerException 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.oauth2.IdentityOAuth2ScopeServerException in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2ScopeService method addUserConsentForApplication.
/**
* Add an OAuth scope consent given for an application by an user.
*
* @param userId User Id.
* @param appId Application Id.
* @param userTenantId Tenant Id.
* @param approvedScopes List of approved scopes.
* @param deniedScopes List of denied scopes.
* @throws IdentityOAuth2ScopeException
*/
public void addUserConsentForApplication(String userId, String appId, int userTenantId, List<String> approvedScopes, List<String> deniedScopes) throws IdentityOAuth2ScopeException {
validateUserId(userId);
validateAppId(appId);
try {
UserApplicationScopeConsentDO userApplicationScopeConsents = new UserApplicationScopeConsentDO(appId, approvedScopes, deniedScopes);
OAuthTokenPersistenceFactory.getInstance().getOAuthUserConsentedScopesDAO().addUserConsentForApplication(userId, userTenantId, userApplicationScopeConsents);
if (log.isDebugEnabled()) {
log.debug("Successfully added the user consent for OAuth scopes for user : " + userId + " and application name : " + appId + " in tenant with id : " + userTenantId);
}
} catch (IdentityOAuth2ScopeConsentException e) {
Oauth2ScopeConstants.ErrorMessages error = Oauth2ScopeConstants.ErrorMessages.ERROR_CODE_FAILED_TO_ADD_USER_CONSENT_FOR_APP;
String msg = String.format(error.getMessage(), userId, appId, userTenantId);
throw new IdentityOAuth2ScopeServerException(error.getCode(), msg, e);
}
}
use of org.wso2.carbon.identity.oauth2.IdentityOAuth2ScopeServerException in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2ScopeService method getUserConsentForApp.
/**
* Get OAuth scope consent given for an application by the user.
*
* @param userId User Id.
* @param appId Application Id.
* @param userTenantId Tenant Id.
* @return {@link OAuth2ScopeConsentResponse}.
* @throws IdentityOAuth2ScopeException
*/
public OAuth2ScopeConsentResponse getUserConsentForApp(String userId, String appId, int userTenantId) throws IdentityOAuth2ScopeException {
validateUserId(userId);
validateAppId(appId);
try {
UserApplicationScopeConsentDO userConsent = OAuthTokenPersistenceFactory.getInstance().getOAuthUserConsentedScopesDAO().getUserConsentForApplication(userId, appId, userTenantId);
OAuth2ScopeConsentResponse consentResponse = new OAuth2ScopeConsentResponse(userId, appId, userTenantId, userConsent.getApprovedScopes(), userConsent.getDeniedScopes());
if (log.isDebugEnabled()) {
log.debug("Successfully retrieved the user consent for userId : " + userId + " and appId: " + appId + " as approved scopes : " + userConsent.getApprovedScopes().stream().collect(Collectors.joining(" ")) + " and denied scopes : " + userConsent.getDeniedScopes().stream().collect(Collectors.joining(" ")));
}
return consentResponse;
} catch (IdentityOAuth2ScopeConsentException e) {
Oauth2ScopeConstants.ErrorMessages error = Oauth2ScopeConstants.ErrorMessages.ERROR_CODE_FAILED_TO_RETRIEVE_USER_CONSENTS_FOR_APP;
String msg = String.format(error.getMessage(), userId, appId, userTenantId);
throw new IdentityOAuth2ScopeServerException(error.getCode(), msg, e);
}
}
use of org.wso2.carbon.identity.oauth2.IdentityOAuth2ScopeServerException in project identity-inbound-auth-oauth by wso2-extensions.
the class EndpointUtil method getRegisteredScopes.
private static Set<String> getRegisteredScopes(Set<String> requestedScopes) throws OAuthSystemException {
try {
String requestedScopesStr = StringUtils.join(requestedScopes, " ");
Set<String> registeredScopes = new HashSet<>();
Set<Scope> registeredScopeSet = oAuth2ScopeService.getScopes(null, null, true, requestedScopesStr);
registeredScopeSet.forEach(scope -> registeredScopes.add(scope.getName()));
return registeredScopes;
} catch (IdentityOAuth2ScopeServerException e) {
throw new OAuthSystemException("Error occurred while retrieving registered scopes.", e);
}
}
use of org.wso2.carbon.identity.oauth2.IdentityOAuth2ScopeServerException in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuthScopeDAOImpl method updateScopeByName.
/**
* Update a scope of the provided scope name
*
* @param updatedScope details of the updated scope
* @param tenantID tenant ID
* @throws IdentityOAuth2ScopeServerException IdentityOAuth2ScopeServerException
*/
@Override
public void updateScopeByName(Scope updatedScope, int tenantID) throws IdentityOAuth2ScopeServerException {
if (log.isDebugEnabled()) {
log.debug("Update scope by name for scope name:" + updatedScope.getName());
}
try (Connection conn = IdentityDatabaseUtil.getDBConnection()) {
try {
int scopeId = getScopeId(updatedScope.getName(), tenantID, conn);
if (scopeId != Oauth2ScopeConstants.INVALID_SCOPE_ID) {
updateScopeDetails(updatedScope, conn, scopeId);
deleteBindings(scopeId, conn);
addScopeBinding(updatedScope, conn, scopeId);
IdentityDatabaseUtil.commitTransaction(conn);
}
} catch (SQLException e1) {
IdentityDatabaseUtil.rollbackTransaction(conn);
String msg = "Error occurred while updating scope by ID ";
throw new IdentityOAuth2ScopeServerException(msg, e1);
}
} catch (SQLException e) {
String msg = "Error occurred while updating scope by ID ";
throw new IdentityOAuth2ScopeServerException(msg, e);
}
}
Aggregations