Search in sources :

Example 1 with OAuth2Parameters

use of org.wso2.carbon.identity.oauth2.model.OAuth2Parameters in project identity-inbound-auth-oauth by wso2-extensions.

the class OAuth2AuthzEndpointTest method setOAuth2Parameters.

private OAuth2Parameters setOAuth2Parameters(Set<String> scopes, String appName, String responseMode, String redirectUri) {
    OAuth2Parameters oAuth2Parameters = new OAuth2Parameters();
    oAuth2Parameters.setScopes(scopes);
    oAuth2Parameters.setResponseMode(responseMode);
    oAuth2Parameters.setRedirectURI(redirectUri);
    oAuth2Parameters.setApplicationName(appName);
    return oAuth2Parameters;
}
Also used : OAuth2Parameters(org.wso2.carbon.identity.oauth2.model.OAuth2Parameters)

Example 2 with OAuth2Parameters

use of org.wso2.carbon.identity.oauth2.model.OAuth2Parameters in project identity-inbound-auth-oauth by wso2-extensions.

the class OAuth2AuthzEndpointTest method testHandleMaxAgeParameter.

@Test(dataProvider = "provideHandleMaxAgeParameterData")
public void testHandleMaxAgeParameter(String value, Boolean state) throws Exception {
    Method handleMaxAgeParameter = authzEndpointObject.getClass().getDeclaredMethod("handleMaxAgeParameter", OAuthAuthzRequest.class, OAuth2Parameters.class);
    handleMaxAgeParameter.setAccessible(true);
    OAuth2Parameters oAuth2Parameters = new OAuth2Parameters();
    when(oAuthAuthzRequest.getParam(OAuthConstants.OIDCClaims.MAX_AGE)).thenReturn(value);
    try {
        handleMaxAgeParameter.invoke(authzEndpointObject, oAuthAuthzRequest, oAuth2Parameters);
    } catch (Exception e1) {
        assertTrue(state);
    }
}
Also used : OAuth2Parameters(org.wso2.carbon.identity.oauth2.model.OAuth2Parameters) HttpMethod(javax.ws.rs.HttpMethod) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidRequestParentException(org.wso2.carbon.identity.oauth.endpoint.exception.InvalidRequestParentException) IdentityOAuth2Exception(org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception) IOException(java.io.IOException) URLBuilderException(org.wso2.carbon.identity.core.URLBuilderException) ParseException(java.text.ParseException) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) OAuthProblemException(org.apache.oltu.oauth2.common.exception.OAuthProblemException) IdentityOAuth2ClientException(org.wso2.carbon.identity.oauth2.IdentityOAuth2ClientException) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with OAuth2Parameters

use of org.wso2.carbon.identity.oauth2.model.OAuth2Parameters in project identity-inbound-auth-oauth by wso2-extensions.

the class EndpointUtilTest method provideErrorPageData.

@DataProvider(name = "provideErrorPageData")
public Object[][] provideErrorPageData() {
    OAuth2Parameters params1 = new OAuth2Parameters();
    OAuth2Parameters params2 = new OAuth2Parameters();
    OAuth2Parameters params3 = new OAuth2Parameters();
    String state = "active";
    String responseType = "dummyResponceType";
    String appName = "myApp";
    params1.setState(state);
    params1.setResponseType(responseType);
    params1.setApplicationName(appName);
    params1.setRedirectURI("http://localhost:8080/callback");
    params2.setState(state);
    params2.setResponseType(responseType);
    params2.setApplicationName(appName);
    params2.setRedirectURI(null);
    params3.setState(null);
    params3.setResponseType(responseType);
    params3.setApplicationName(appName);
    params3.setRedirectURI("http://localhost:8080/callback");
    return new Object[][] { { true, true, true, params1, "http://localhost:8080/location", false }, { true, false, true, params1, "http://localhost:8080/location", false }, { false, true, true, params1, "http://localhost:8080/location", true }, { false, false, false, params1, ERROR_PAGE_URL, true }, { true, true, true, params3, "http://localhost:8080/location", false } };
}
Also used : OAuth2Parameters(org.wso2.carbon.identity.oauth2.model.OAuth2Parameters) Matchers.anyString(org.mockito.Matchers.anyString) DataProvider(org.testng.annotations.DataProvider)

Example 4 with OAuth2Parameters

use of org.wso2.carbon.identity.oauth2.model.OAuth2Parameters in project identity-inbound-auth-oauth by wso2-extensions.

the class EndpointUtilTest method provideErrorRedirectData.

@DataProvider(name = "provideErrorRedirectData")
public Object[][] provideErrorRedirectData() {
    OAuth2Parameters params1 = new OAuth2Parameters();
    OAuth2Parameters params2 = new OAuth2Parameters();
    String state = "active";
    String responseType = "dummyResponceType";
    String appName = "myApp";
    params1.setState(state);
    params1.setResponseType(responseType);
    params1.setApplicationName(appName);
    params1.setRedirectURI("http://localhost:8080/callback");
    params2.setState(state);
    params2.setResponseType(responseType);
    params2.setApplicationName(appName);
    params2.setRedirectURI(null);
    return new Object[][] { { true, true, params1, null, "http://localhost:8080/location", false }, { true, false, params1, null, "http://localhost:8080/location", false }, { false, true, params1, null, "http://localhost:8080/location", false }, { true, true, params2, null, ERROR_PAGE_URL, false }, { true, true, null, null, ERROR_PAGE_URL, false }, { true, true, params1, new OAuthSystemException(), ERROR_PAGE_URL, false }, { true, true, params1, new OAuthSystemException(), ERROR_PAGE_URL, true } };
}
Also used : OAuth2Parameters(org.wso2.carbon.identity.oauth2.model.OAuth2Parameters) OAuthSystemException(org.apache.oltu.oauth2.common.exception.OAuthSystemException) Matchers.anyString(org.mockito.Matchers.anyString) DataProvider(org.testng.annotations.DataProvider)

Example 5 with OAuth2Parameters

use of org.wso2.carbon.identity.oauth2.model.OAuth2Parameters in project identity-inbound-auth-oauth by wso2-extensions.

the class EndpointUtil method getAllowedOAuthScopes.

private static List<String> getAllowedOAuthScopes(OAuth2Parameters params) throws OAuthSystemException {
    Set<String> allowedScopes = params.getScopes();
    List<String> allowedOAuthScopes = new ArrayList<>();
    if (CollectionUtils.isNotEmpty(allowedScopes)) {
        try {
            startTenantFlow(params.getTenantDomain());
            /* If DropUnregisteredScopes scopes config is enabled
             then any unregistered scopes(excluding internal scopes
             and allowed scopes) is be dropped. Therefore they will
             not be shown in the user consent screen.*/
            if (oauthServerConfiguration.isDropUnregisteredScopes()) {
                if (log.isDebugEnabled()) {
                    log.debug("DropUnregisteredScopes config is enabled. Attempting to drop unregistered scopes.");
                }
                allowedScopes = dropUnregisteredScopes(params);
            }
            // Get registered OIDC scopes.
            String[] oidcScopes = oAuthAdminService.getScopeNames();
            List<String> oidcScopeList = new ArrayList<>(Arrays.asList(oidcScopes));
            for (String scope : allowedScopes) {
                if (!oidcScopeList.contains(scope)) {
                    allowedOAuthScopes.add(scope);
                }
            }
        } catch (IdentityOAuthAdminException e) {
            throw new OAuthSystemException("Error while retrieving OIDC scopes.", e);
        } finally {
            PrivilegedCarbonContext.endTenantFlow();
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Allowed OAuth scopes : " + allowedOAuthScopes.stream().collect(Collectors.joining(" ")) + " for client : " + params.getClientId());
    }
    return allowedOAuthScopes;
}
Also used : IdentityOAuthAdminException(org.wso2.carbon.identity.oauth.IdentityOAuthAdminException) OAuthSystemException(org.apache.oltu.oauth2.common.exception.OAuthSystemException) ArrayList(java.util.ArrayList)

Aggregations

OAuth2Parameters (org.wso2.carbon.identity.oauth2.model.OAuth2Parameters)40 RequestObject (org.wso2.carbon.identity.openidconnect.model.RequestObject)23 HashMap (java.util.HashMap)22 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)19 Test (org.testng.annotations.Test)19 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)17 Matchers.anyString (org.mockito.Matchers.anyString)14 BeforeTest (org.testng.annotations.BeforeTest)13 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)13 RequestObjectException (org.wso2.carbon.identity.oauth2.RequestObjectException)12 JSONObject (org.json.JSONObject)10 OAuthResponse (org.apache.oltu.oauth2.common.message.OAuthResponse)9 OAuthSystemException (org.apache.oltu.oauth2.common.exception.OAuthSystemException)8 ArrayList (java.util.ArrayList)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 OAuthProblemException (org.apache.oltu.oauth2.common.exception.OAuthProblemException)7 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)7 SessionDataCacheKey (org.wso2.carbon.identity.oauth.cache.SessionDataCacheKey)7 OAuth2ScopeConsentResponse (org.wso2.carbon.identity.oauth2.model.OAuth2ScopeConsentResponse)7 URI (java.net.URI)6