Search in sources :

Example 6 with OAuth2AuthorizeRespDTO

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

the class OAuth2AuthzEndpoint method handleUserConsent.

private String handleUserConsent(OAuthMessage oAuthMessage, String consent, OIDCSessionState sessionState) throws OAuthSystemException {
    OAuth2Parameters oauth2Params = getOauth2Params(oAuthMessage);
    storeUserConsent(oAuthMessage, consent);
    OAuthResponse oauthResponse;
    String responseType = oauth2Params.getResponseType();
    HttpRequestHeaderHandler httpRequestHeaderHandler = new HttpRequestHeaderHandler(oAuthMessage.getRequest());
    // authorizing the request
    OAuth2AuthorizeRespDTO authzRespDTO = authorize(oauth2Params, oAuthMessage.getSessionDataCacheEntry(), httpRequestHeaderHandler);
    if (isSuccessfulAuthorization(authzRespDTO)) {
        oauthResponse = handleSuccessAuthorization(oAuthMessage, sessionState, oauth2Params, responseType, authzRespDTO);
    } else if (isFailureAuthorizationWithErorrCode(authzRespDTO)) {
        // Authorization failure due to various reasons
        return handleFailureAuthorization(oAuthMessage, sessionState, oauth2Params, authzRespDTO);
    } else {
        // Authorization failure due to various reasons
        return handleServerErrorAuthorization(oAuthMessage, sessionState, oauth2Params);
    }
    // When response_mode equals to form_post, body parameter is passed back.
    if (isFormPostModeAndResponseBodyExists(oauth2Params, oauthResponse)) {
        return oauthResponse.getBody();
    } else {
        // as per the specification: http://openid.net/specs/openid-connect-core-1_0.html#HybridCallback
        if (hasIDTokenInResponseType(responseType)) {
            return buildOIDCResponseWithURIFragment(oauthResponse, authzRespDTO);
        } else {
            return appendAuthenticatedIDPs(oAuthMessage.getSessionDataCacheEntry(), oauthResponse.getLocationUri());
        }
    }
}
Also used : OAuth2Parameters(org.wso2.carbon.identity.oauth2.model.OAuth2Parameters) HttpRequestHeaderHandler(org.wso2.carbon.identity.oauth2.model.HttpRequestHeaderHandler) OAuth2AuthorizeRespDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO) OAuthResponse(org.apache.oltu.oauth2.common.message.OAuthResponse)

Example 7 with OAuth2AuthorizeRespDTO

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

the class AuthorizationHandlerManagerTest method testHandleAuthorizationIDTokenResponse.

@Test(dataProvider = "IdpIDColumnAvailabilityDataProvider")
public void testHandleAuthorizationIDTokenResponse(boolean isIDPIdColumnEnabled) throws Exception {
    OAuth2ServiceComponentHolder.setIDPIdColumnEnabled(isIDPIdColumnEnabled);
    authorizationHandlerManager = AuthorizationHandlerManager.getInstance();
    authzReqDTO.setResponseType(TestConstants.AUTHORIZATION_HANDLER_RESPONSE_TYPE_ID_TOKEN);
    authzReqDTO.setConsumerKey(TestConstants.CLIENT_ID);
    authzReqDTO.setScopes(TestConstants.SCOPE_STRING.split(" "));
    AuthenticatedUser user = new AuthenticatedUser();
    user.setUserName(TestConstants.USER_NAME);
    user.setUserId("4b4414e1-916b-4475-aaee-6b0751c29ff6");
    user.setTenantDomain(TestConstants.TENANT_DOMAIN);
    user.setUserStoreDomain(TestConstants.USER_DOMAIN_PRIMARY);
    user.setFederatedIdPName(TestConstants.LOCAL_IDP);
    authzReqDTO.setUser(user);
    OAuth2AuthorizeRespDTO respDTO = authorizationHandlerManager.handleAuthorization(authzReqDTO);
    Assert.assertNotNull(respDTO, "Response is null");
    Assert.assertNotNull(respDTO.getAccessToken(), "ID token returned is null");
}
Also used : OAuth2AuthorizeRespDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) Test(org.testng.annotations.Test) IdentityBaseTest(org.wso2.carbon.identity.testutil.IdentityBaseTest)

Example 8 with OAuth2AuthorizeRespDTO

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

the class AuthorizationHandlerManagerTest method testHandleAuthorizationIDTokenTokenResponseTypeUnauthorized.

@Test
public void testHandleAuthorizationIDTokenTokenResponseTypeUnauthorized() throws Exception {
    authzReqDTO.setResponseType(TestConstants.AUTHORIZATION_HANDLER_RESPONSE_TYPE_ID_TOKEN_TOKEN);
    authzReqDTO.setConsumerKey(TestConstants.CLIENT_ID_UNAUTHORIZED_CLIENT);
    authzReqDTO.setScopes(TestConstants.SCOPE_STRING.split(" "));
    AuthenticatedUser user = new AuthenticatedUser();
    user.setUserName(TestConstants.USER_NAME);
    user.setTenantDomain(TestConstants.TENANT_DOMAIN);
    user.setUserStoreDomain(TestConstants.USER_DOMAIN_PRIMARY);
    authzReqDTO.setUser(user);
    OAuth2AuthorizeRespDTO respDTO = authorizationHandlerManager.handleAuthorization(authzReqDTO);
    String errorCode = respDTO.getErrorCode();
    Assert.assertNotNull(respDTO, "Response is null");
    Assert.assertNotNull(respDTO.getErrorCode(), "Error code returned is null");
    Assert.assertEquals(errorCode, TestConstants.UNAUTHORIZED_CLIENT_ERROR_CODE, "Expected unauthorized_client error code but found : " + errorCode);
}
Also used : OAuth2AuthorizeRespDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO) Matchers.anyString(org.mockito.Matchers.anyString) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) Test(org.testng.annotations.Test) IdentityBaseTest(org.wso2.carbon.identity.testutil.IdentityBaseTest)

Example 9 with OAuth2AuthorizeRespDTO

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

the class AuthorizationHandlerManagerTest method testHandleAuthorizationCodeResponseTypeUnauthorized.

@Test
public void testHandleAuthorizationCodeResponseTypeUnauthorized() throws Exception {
    authzReqDTO.setResponseType(TestConstants.AUTHORIZATION_HANDLER_RESPONSE_TYPE_CODE);
    authzReqDTO.setConsumerKey(TestConstants.CLIENT_ID_UNAUTHORIZED_CLIENT);
    authzReqDTO.setScopes(TestConstants.SCOPE_STRING.split(" "));
    AuthenticatedUser user = new AuthenticatedUser();
    user.setUserName(TestConstants.USER_NAME);
    user.setTenantDomain(TestConstants.TENANT_DOMAIN);
    user.setUserStoreDomain(TestConstants.USER_DOMAIN_PRIMARY);
    authzReqDTO.setUser(user);
    OAuth2AuthorizeRespDTO respDTO = authorizationHandlerManager.handleAuthorization(authzReqDTO);
    String errorCode = respDTO.getErrorCode();
    Assert.assertNotNull(respDTO, "Response is null");
    Assert.assertNotNull(respDTO.getErrorCode(), "Error code returned is null");
    Assert.assertEquals(errorCode, TestConstants.UNAUTHORIZED_CLIENT_ERROR_CODE, "Expected unauthorized_client error code but found : " + errorCode);
}
Also used : OAuth2AuthorizeRespDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO) Matchers.anyString(org.mockito.Matchers.anyString) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) Test(org.testng.annotations.Test) IdentityBaseTest(org.wso2.carbon.identity.testutil.IdentityBaseTest)

Example 10 with OAuth2AuthorizeRespDTO

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

the class AuthorizationHandlerManagerTest method testHandleAuthorizationCodeResponse.

@Test(dataProvider = "IdpIDColumnAvailabilityDataProvider")
public void testHandleAuthorizationCodeResponse(boolean isIDPIdColumnEnabled) throws Exception {
    OAuth2ServiceComponentHolder.setIDPIdColumnEnabled(isIDPIdColumnEnabled);
    authorizationHandlerManager = AuthorizationHandlerManager.getInstance();
    authzReqDTO.setResponseType(TestConstants.AUTHORIZATION_HANDLER_RESPONSE_TYPE_CODE);
    authzReqDTO.setConsumerKey(TestConstants.CLIENT_ID);
    authzReqDTO.setScopes(TestConstants.SCOPE_STRING.split(" "));
    AuthenticatedUser user = new AuthenticatedUser();
    user.setUserName(TestConstants.USER_NAME);
    user.setTenantDomain(TestConstants.TENANT_DOMAIN);
    user.setUserStoreDomain(TestConstants.USER_DOMAIN_PRIMARY);
    user.setFederatedIdPName(TestConstants.LOCAL_IDP);
    authzReqDTO.setUser(user);
    OAuth2AuthorizeRespDTO respDTO = authorizationHandlerManager.handleAuthorization(authzReqDTO);
    Assert.assertNotNull(respDTO, "Response is null");
    Assert.assertNotNull(respDTO.getAuthorizationCode(), "Code returned is null");
}
Also used : OAuth2AuthorizeRespDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) Test(org.testng.annotations.Test) IdentityBaseTest(org.wso2.carbon.identity.testutil.IdentityBaseTest)

Aggregations

OAuth2AuthorizeRespDTO (org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO)36 Test (org.testng.annotations.Test)22 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)18 Matchers.anyString (org.mockito.Matchers.anyString)13 IdentityBaseTest (org.wso2.carbon.identity.testutil.IdentityBaseTest)12 OAuth2AuthorizeReqDTO (org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeReqDTO)10 HashMap (java.util.HashMap)7 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)6 OAuthAuthzReqMessageContext (org.wso2.carbon.identity.oauth2.authz.OAuthAuthzReqMessageContext)6 AccessTokenDO (org.wso2.carbon.identity.oauth2.model.AccessTokenDO)6 OAuthAppDO (org.wso2.carbon.identity.oauth.dao.OAuthAppDO)5 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)4 Date (java.util.Date)4 OAuthResponse (org.apache.oltu.oauth2.common.message.OAuthResponse)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 BeforeTest (org.testng.annotations.BeforeTest)3 OAuthEventInterceptor (org.wso2.carbon.identity.oauth.event.OAuthEventInterceptor)3 OAuth2Parameters (org.wso2.carbon.identity.oauth2.model.OAuth2Parameters)3 RequestObject (org.wso2.carbon.identity.openidconnect.model.RequestObject)3