use of org.wso2.carbon.identity.oauth2.model.OAuth2ScopeConsentResponse in project identity-inbound-auth-oauth by wso2-extensions.
the class EndpointUtilTest method setUp.
@BeforeTest
public void setUp() {
username = "myUsername";
password = "myPassword";
sessionDataKey = "1234567890";
clientId = "myClientId";
user = new AuthenticatedUser();
user.setFederatedUser(false);
user.setUserId("4b4414e1-916b-4475-aaee-6b0751c29ff6");
oAuth2ScopeConsentResponse = new OAuth2ScopeConsentResponse("sampleUser", "sampleApp", -1234, new ArrayList<>(), new ArrayList<>());
}
use of org.wso2.carbon.identity.oauth2.model.OAuth2ScopeConsentResponse 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.model.OAuth2ScopeConsentResponse in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2ScopeServiceTest method testRevokeUserConsentForApplication.
@Test
public void testRevokeUserConsentForApplication() throws Exception {
List<String> approvedScopes = new ArrayList<>(Arrays.asList("read", "write"));
List<String> deniedScopes = new ArrayList<>(Arrays.asList("delete"));
String uuid = UUID.randomUUID().toString();
insertAppId(uuid);
oAuth2ScopeService.addUserConsentForApplication("user_id", uuid, 1, approvedScopes, deniedScopes);
oAuth2ScopeService.revokeUserConsentForApplication("user_id", uuid, 1);
OAuth2ScopeConsentResponse oAuth2ScopeConsentResponse = oAuth2ScopeService.getUserConsentForApp("user_id", uuid, 1);
assertEquals(oAuth2ScopeConsentResponse.getApprovedScopes().size(), 0);
}
use of org.wso2.carbon.identity.oauth2.model.OAuth2ScopeConsentResponse in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2ScopeServiceTest method testAddUserConsentForApplication.
@Test
public void testAddUserConsentForApplication() throws Exception {
List<String> approvedScopes = new ArrayList<>(Arrays.asList("read", "write"));
List<String> deniedScopes = new ArrayList<>(Arrays.asList("delete"));
String appId = UUID.randomUUID().toString();
insertAppId(appId);
oAuth2ScopeService.addUserConsentForApplication("user_id", appId, 1, approvedScopes, deniedScopes);
OAuth2ScopeConsentResponse oAuth2ScopeConsentResponse = oAuth2ScopeService.getUserConsentForApp("user_id", appId, 1);
assertEquals(oAuth2ScopeConsentResponse.getApprovedScopes().get(0), approvedScopes.get(0));
assertEquals(oAuth2ScopeConsentResponse.getDeniedScopes().get(0), deniedScopes.get(0));
}
use of org.wso2.carbon.identity.oauth2.model.OAuth2ScopeConsentResponse in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2AuthzEndpointTest method setUp.
@BeforeTest
public void setUp() throws Exception {
System.setProperty(CarbonBaseConstants.CARBON_HOME, Paths.get(System.getProperty("user.dir"), "src", "test", "resources").toString());
oAuth2AuthzEndpoint = new OAuth2AuthzEndpoint();
initiateInMemoryH2();
createOAuthApp(CLIENT_ID_VALUE, SECRET, USERNAME, APP_NAME, "ACTIVE");
createOAuthApp(INACTIVE_CLIENT_ID_VALUE, "dummySecret", USERNAME, INACTIVE_APP_NAME, "INACTIVE");
Class<?> clazz = OAuth2AuthzEndpoint.class;
authzEndpointObject = clazz.newInstance();
oAuth2ScopeConsentResponse = new OAuth2ScopeConsentResponse("sampleUser", "sampleApp", -1234, new ArrayList<>(), new ArrayList<>());
dummySp = new ServiceProvider();
dummySp.setApplicationResourceId("sampleApp");
}
Aggregations