Search in sources :

Example 26 with OAuth2AuthorizeRespDTO

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

the class AuthorizationHandlerManagerTest method testHandleAuthorizationIDTokenTokenResponse.

@Test(dataProvider = "IdpIDColumnAvailabilityDataProvider")
public void testHandleAuthorizationIDTokenTokenResponse(boolean isIDPIdColumnEnabled) throws Exception {
    OAuth2ServiceComponentHolder.setIDPIdColumnEnabled(isIDPIdColumnEnabled);
    authorizationHandlerManager = AuthorizationHandlerManager.getInstance();
    authzReqDTO.setResponseType(TestConstants.AUTHORIZATION_HANDLER_RESPONSE_TYPE_ID_TOKEN_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(), "Access 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 27 with OAuth2AuthorizeRespDTO

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

the class AuthorizationHandlerManagerTest method testHandleAuthorizationTokenResponseNoScopes.

@Test(dataProvider = "IdpIDColumnAvailabilityDataProvider")
public void testHandleAuthorizationTokenResponseNoScopes(boolean isIDPIdColumnEnabled) throws Exception {
    OAuth2ServiceComponentHolder.setIDPIdColumnEnabled(isIDPIdColumnEnabled);
    authorizationHandlerManager = AuthorizationHandlerManager.getInstance();
    authzReqDTO.setResponseType(TestConstants.AUTHORIZATION_HANDLER_RESPONSE_TYPE_TOKEN);
    authzReqDTO.setConsumerKey(TestConstants.CLIENT_ID);
    authzReqDTO.setScopes(new String[0]);
    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(), "Access 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 28 with OAuth2AuthorizeRespDTO

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

the class NoneResponseTypeHandlerTest method testIssue.

@Test(dataProvider = "CommonDataProvider")
public void testIssue(String callBackUri) throws Exception {
    NoneResponseTypeHandler noneResponseTypeHandler = new NoneResponseTypeHandler();
    OAuth2AuthorizeReqDTO authorizationReqDTO = new OAuth2AuthorizeReqDTO();
    authorizationReqDTO.setCallbackUrl(callBackUri);
    authorizationReqDTO.setConsumerKey("SDSDSDS23131231");
    authorizationReqDTO.setResponseType(OAuthConstants.NONE);
    OAuthAuthzReqMessageContext messageContext = new OAuthAuthzReqMessageContext(authorizationReqDTO);
    messageContext.setApprovedScope(new String[] { "scope1", "scope2", OAuthConstants.Scope.OPENID });
    OAuth2AuthorizeRespDTO auth2AuthorizeReqDTO = noneResponseTypeHandler.issue(messageContext);
    // In the "response_type = none", none of the code, id token or the access token is returned. The user-agent
    // is redirected to the given call back uri.
    Assert.assertNull(auth2AuthorizeReqDTO.getAccessToken());
    Assert.assertNull(auth2AuthorizeReqDTO.getAuthorizationCode());
    Assert.assertNull(auth2AuthorizeReqDTO.getIdToken());
    Assert.assertEquals(auth2AuthorizeReqDTO.getCallbackURI(), callBackUri);
}
Also used : OAuth2AuthorizeRespDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO) OAuthAuthzReqMessageContext(org.wso2.carbon.identity.oauth2.authz.OAuthAuthzReqMessageContext) OAuth2AuthorizeReqDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeReqDTO) Test(org.testng.annotations.Test)

Example 29 with OAuth2AuthorizeRespDTO

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

the class AuthorizationHandlerManager method handleAuthorization.

public OAuth2AuthorizeRespDTO handleAuthorization(OAuth2AuthorizeReqDTO authzReqDTO) throws IdentityOAuth2Exception, IdentityOAuthAdminException, InvalidOAuthClientException {
    OAuthAuthzReqMessageContext authzReqMsgCtx = getOAuthAuthzReqMessageContext(authzReqDTO);
    ResponseTypeHandler authzHandler = getResponseHandler(authzReqDTO);
    OAuth2AuthorizeRespDTO authorizeRespDTO = validateAuthzRequest(authzReqDTO, authzReqMsgCtx, authzHandler);
    if (isErrorResponseFound(authorizeRespDTO)) {
        if (log.isDebugEnabled()) {
            log.debug("Error response received for authorization request by user : " + authzReqDTO.getUser() + ", client : " + authzReqDTO.getConsumerKey() + ", scope : " + OAuth2Util.buildScopeString(authzReqDTO.getScopes()));
        }
        return authorizeRespDTO;
    }
    try {
        // set the authorization request context to be used by downstream handlers. This is introduced as a fix for
        // IDENTITY-4111
        OAuth2Util.setAuthzRequestContext(authzReqMsgCtx);
        authorizeRespDTO = authzHandler.issue(authzReqMsgCtx);
    } finally {
        // clears authorization request context
        OAuth2Util.clearAuthzRequestContext();
    }
    return authorizeRespDTO;
}
Also used : ResponseTypeHandler(org.wso2.carbon.identity.oauth2.authz.handlers.ResponseTypeHandler) OAuth2AuthorizeRespDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO)

Example 30 with OAuth2AuthorizeRespDTO

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

the class TokenResponseTypeHandler method triggerPostListeners.

private void triggerPostListeners(OAuthAuthzReqMessageContext oauthAuthzMsgCtx, AccessTokenDO tokenDO, OAuth2AuthorizeRespDTO respDTO) {
    OAuthEventInterceptor oAuthEventInterceptorProxy = OAuthComponentServiceHolder.getInstance().getOAuthEventInterceptorProxy();
    if (oAuthEventInterceptorProxy != null && oAuthEventInterceptorProxy.isEnabled()) {
        try {
            Map<String, Object> paramMap = new HashMap<>();
            oAuthEventInterceptorProxy.onPostTokenIssue(oauthAuthzMsgCtx, tokenDO, respDTO, paramMap);
        } catch (IdentityOAuth2Exception e) {
            log.error("Oauth post token issue listener ", e);
        }
    }
}
Also used : IdentityOAuth2Exception(org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception) HashMap(java.util.HashMap) OAuthEventInterceptor(org.wso2.carbon.identity.oauth.event.OAuthEventInterceptor)

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