Search in sources :

Example 16 with OAuth2AuthorizeRespDTO

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

the class OpenIDConnectSystemClaimImplTest method setUp.

@BeforeClass
public void setUp() throws Exception {
    oAuth2AccessTokenReqDTO = new OAuth2AccessTokenReqDTO();
    oAuthTokenReqMessageContext = new OAuthTokenReqMessageContext(oAuth2AccessTokenReqDTO);
    oAuth2AccessTokenRespDTO = new OAuth2AccessTokenRespDTO();
    oAuth2AuthorizeReqDTO = new OAuth2AuthorizeReqDTO();
    oAuthAuthzReqMessageContext = new OAuthAuthzReqMessageContext(oAuth2AuthorizeReqDTO);
    oAuth2AuthorizeRespDTO = new OAuth2AuthorizeRespDTO();
    openIDConnectSystemClaim = new OpenIDConnectSystemClaimImpl();
}
Also used : OAuth2AccessTokenRespDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AccessTokenRespDTO) OAuth2AuthorizeRespDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO) OAuthTokenReqMessageContext(org.wso2.carbon.identity.oauth2.token.OAuthTokenReqMessageContext) OAuthAuthzReqMessageContext(org.wso2.carbon.identity.oauth2.authz.OAuthAuthzReqMessageContext) OAuth2AuthorizeReqDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeReqDTO) OAuth2AccessTokenReqDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AccessTokenReqDTO) BeforeClass(org.testng.annotations.BeforeClass)

Example 17 with OAuth2AuthorizeRespDTO

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

the class ClaimProviderImpl method getAdditionalClaims.

@Override
public Map<String, Object> getAdditionalClaims(OAuthAuthzReqMessageContext oAuthAuthzReqMessageContext, OAuth2AuthorizeRespDTO oAuth2AuthorizeRespDTO) throws IdentityOAuth2Exception {
    Map<String, Object> additionalClaims = new HashMap<>();
    String claimValue;
    OIDCSessionState previousSession = getSessionState(oAuthAuthzReqMessageContext);
    if (previousSession == null) {
        // If there is no previous browser session, generate new sid value.
        claimValue = UUID.randomUUID().toString();
        if (log.isDebugEnabled()) {
            log.debug("sid claim is generated for auth request. ");
        }
    } else {
        // Previous browser session exists, get sid claim from OIDCSessionState.
        claimValue = previousSession.getSidClaim();
        if (log.isDebugEnabled()) {
            log.debug("sid claim is found in the session state");
        }
    }
    additionalClaims.put(OAuthConstants.OIDCClaims.SESSION_ID_CLAIM, claimValue);
    oAuth2AuthorizeRespDTO.setOidcSessionId(claimValue);
    return additionalClaims;
}
Also used : HashMap(java.util.HashMap) OIDCSessionState(org.wso2.carbon.identity.oidc.session.OIDCSessionState)

Example 18 with OAuth2AuthorizeRespDTO

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

the class DeviceFlowResponseTypeHandler method issue.

/**
 * This method is used to handle the response type. After authentication process finish this will redirect to the
 * constant page.
 *
 * @param oauthAuthzMsgCtx Authorization message context.
 * @return Response DTO.
 * @throws IdentityOAuth2Exception Error at device response type handler.
 */
@Override
public OAuth2AuthorizeRespDTO issue(OAuthAuthzReqMessageContext oauthAuthzMsgCtx) throws IdentityOAuth2Exception {
    OAuth2AuthorizeRespDTO respDTO = new OAuth2AuthorizeRespDTO();
    OAuth2AuthorizeReqDTO authzReqDTO = oauthAuthzMsgCtx.getAuthorizationReqDTO();
    AuthenticatedUser authenticatedUser = authzReqDTO.getUser();
    String userCode = authzReqDTO.getNonce();
    DeviceFlowPersistenceFactory.getInstance().getDeviceFlowDAO().setAuthzUserAndStatus(userCode, Constants.AUTHORIZED, authenticatedUser);
    respDTO.setCallbackURI(authzReqDTO.getCallbackUrl());
    return respDTO;
}
Also used : OAuth2AuthorizeRespDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO) OAuth2AuthorizeReqDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeReqDTO) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)

Example 19 with OAuth2AuthorizeRespDTO

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

the class OAuth2ServiceTest method testAuthorizeWithException.

@Test
public void testAuthorizeWithException() throws IdentityOAuth2Exception {
    mockStatic(IdentityTenantUtil.class);
    when(IdentityTenantUtil.getTenantId(anyString())).thenReturn(-1234);
    String callbackUrl = "dummyCallBackUrl";
    mockStatic(AuthorizationHandlerManager.class);
    when(oAuth2AuthorizeReqDTO.getCallbackUrl()).thenReturn(callbackUrl);
    when(AuthorizationHandlerManager.getInstance()).thenThrow(new IdentityOAuth2Exception("Error while creating AuthorizationHandlerManager instance"));
    OAuth2AuthorizeRespDTO oAuth2AuthorizeRespDTO = oAuth2Service.authorize(oAuth2AuthorizeReqDTO);
    assertNotNull(oAuth2AuthorizeRespDTO);
}
Also used : OAuth2AuthorizeRespDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PowerMockIdentityBaseTest(org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)

Example 20 with OAuth2AuthorizeRespDTO

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

the class OAuth2ServiceTest method testAuthorize.

@Test
public void testAuthorize() throws Exception {
    mockStatic(AuthorizationHandlerManager.class);
    when(AuthorizationHandlerManager.getInstance()).thenReturn(authorizationHandlerManager);
    when(authorizationHandlerManager.handleAuthorization((OAuth2AuthorizeReqDTO) anyObject())).thenReturn(mockedOAuth2AuthorizeRespDTO);
    when(oAuthServerConfiguration.getTimeStampSkewInSeconds()).thenReturn(300L);
    OAuth2AuthorizeRespDTO oAuth2AuthorizeRespDTO = oAuth2Service.authorize(oAuth2AuthorizeReqDTO);
    assertNotNull(oAuth2AuthorizeRespDTO);
}
Also used : OAuth2AuthorizeRespDTO(org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PowerMockIdentityBaseTest(org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)

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