Search in sources :

Example 1 with OAuth2ScopeConsentResponse

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<>());
}
Also used : OAuth2ScopeConsentResponse(org.wso2.carbon.identity.oauth2.model.OAuth2ScopeConsentResponse) ArrayList(java.util.ArrayList) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) BeforeTest(org.testng.annotations.BeforeTest)

Example 2 with OAuth2ScopeConsentResponse

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);
    }
}
Also used : OAuth2ScopeConsentResponse(org.wso2.carbon.identity.oauth2.model.OAuth2ScopeConsentResponse) UserApplicationScopeConsentDO(org.wso2.carbon.identity.oauth2.model.UserApplicationScopeConsentDO)

Example 3 with OAuth2ScopeConsentResponse

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);
}
Also used : OAuth2ScopeConsentResponse(org.wso2.carbon.identity.oauth2.model.OAuth2ScopeConsentResponse) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 4 with OAuth2ScopeConsentResponse

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));
}
Also used : OAuth2ScopeConsentResponse(org.wso2.carbon.identity.oauth2.model.OAuth2ScopeConsentResponse) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 5 with OAuth2ScopeConsentResponse

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");
}
Also used : OAuth2ScopeConsentResponse(org.wso2.carbon.identity.oauth2.model.OAuth2ScopeConsentResponse) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) ArrayList(java.util.ArrayList) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

OAuth2ScopeConsentResponse (org.wso2.carbon.identity.oauth2.model.OAuth2ScopeConsentResponse)9 ArrayList (java.util.ArrayList)7 Test (org.testng.annotations.Test)5 BeforeTest (org.testng.annotations.BeforeTest)3 OAuthSystemException (org.apache.oltu.oauth2.common.exception.OAuthSystemException)2 JDBCPermissionBasedInternalScopeValidator (org.wso2.carbon.identity.oauth2.validators.JDBCPermissionBasedInternalScopeValidator)2 Constructor (java.lang.reflect.Constructor)1 Field (java.lang.reflect.Field)1 Modifier (java.lang.reflect.Modifier)1 URLEncoder (java.net.URLEncoder)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1