use of org.wso2.carbon.identity.oauth2.model.UserApplicationScopeConsentDO in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuthUserConsentedScopesDAOImpl method getUserConsentForApplication.
@Override
public UserApplicationScopeConsentDO getUserConsentForApplication(String userId, String appId, int tenantId) throws IdentityOAuth2ScopeConsentException {
if (log.isDebugEnabled()) {
log.debug("Get user consented scopes for userId :" + userId + " and appId : " + appId + " and " + "tenantId : " + tenantId);
}
UserApplicationScopeConsentDO userScopeConsent = new UserApplicationScopeConsentDO(appId);
List<String> approvedScopes = new ArrayList<>();
List<String> disapprovedScopes = new ArrayList<>();
try (Connection conn = IdentityDatabaseUtil.getDBConnection(false)) {
try (PreparedStatement ps = conn.prepareStatement(SQLQueries.GET_OAUTH2_USER_CONSENT_FOR_APP)) {
ps.setString(1, userId);
ps.setString(2, appId);
ps.setInt(3, tenantId);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
String scope = rs.getString(1);
boolean consent = rs.getBoolean(2);
if (consent) {
approvedScopes.add(scope);
} else {
disapprovedScopes.add(scope);
}
}
}
}
userScopeConsent.setApprovedScopes(approvedScopes);
userScopeConsent.setDeniedScopes(disapprovedScopes);
return userScopeConsent;
} catch (SQLException e) {
String msg = "Error occurred while retrieving scope consents for userId : " + userId + " and appId : " + appId + " and tenantId : " + tenantId;
throw new IdentityOAuth2ScopeConsentException(msg, e);
}
}
use of org.wso2.carbon.identity.oauth2.model.UserApplicationScopeConsentDO in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2ScopeService method updateUserConsentForApplication.
/**
* Update consent given for OAuth scopes by a user for a given application.
*
* @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 updateUserConsentForApplication(String userId, String appId, int userTenantId, List<String> approvedScopes, List<String> deniedScopes) throws IdentityOAuth2ScopeException {
validateUserId(userId);
validateAppId(appId);
try {
UserApplicationScopeConsentDO updatedUserApplicationScopeConsents = new UserApplicationScopeConsentDO(appId, approvedScopes, deniedScopes);
UserApplicationScopeConsentDO existingConsent = OAuthTokenPersistenceFactory.getInstance().getOAuthUserConsentedScopesDAO().getUserConsentForApplication(userId, updatedUserApplicationScopeConsents.getAppId(), userTenantId);
UserApplicationScopeConsentDO consentsToBeUpdated = getConsentsToBeUpdated(existingConsent, updatedUserApplicationScopeConsents);
UserApplicationScopeConsentDO consentsToBeAdded = getConsentsToBeAdded(consentsToBeUpdated, updatedUserApplicationScopeConsents);
OAuthTokenPersistenceFactory.getInstance().getOAuthUserConsentedScopesDAO().updateExistingConsentForApplication(userId, appId, userTenantId, consentsToBeAdded, consentsToBeUpdated);
if (log.isDebugEnabled()) {
log.debug("Successfully updated the user consent for OAuth scopes for user : " + userId + " and application : " + appId + " in tenant with Id : " + userTenantId);
}
} catch (IdentityOAuth2ScopeConsentException e) {
Oauth2ScopeConstants.ErrorMessages error = Oauth2ScopeConstants.ErrorMessages.ERROR_CODE_FAILED_TO_UPDATE_USER_CONSENT_FOR_APP;
String msg = String.format(error.getMessage(), userId, appId, userTenantId);
throw new IdentityOAuth2ScopeServerException(error.getCode(), msg, e);
}
}
Aggregations