use of org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO in project identity-inbound-auth-oauth by wso2-extensions.
the class AuthorizationHandlerManagerTest method testHandleAuthorizationTokenResponse.
@Test(dataProvider = "IdpIDColumnAvailabilityDataProvider")
public void testHandleAuthorizationTokenResponse(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(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");
}
use of org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO in project identity-inbound-auth-oauth by wso2-extensions.
the class CodeResponseTypeHandlerTest method testIssue.
@Test(dataProvider = "IdpIDColumnAvailabilityDataProvider")
public void testIssue(boolean isIDPIdColumnEnabled) throws Exception {
OAuth2ServiceComponentHolder.setIDPIdColumnEnabled(isIDPIdColumnEnabled);
OAuthAppDO oAuthAppDO = new OAuthAppDO();
oAuthAppDO.setGrantTypes("implicit");
oAuthAppDO.setOauthConsumerKey(TEST_CONSUMER_KEY);
oAuthAppDO.setState("active");
AuthenticatedUser user = new AuthenticatedUser();
user.setUserStoreDomain("PRIMARY");
user.setUserName("testUser");
user.setFederatedIdPName(TestConstants.LOCAL_IDP);
oAuthAppDO.setUser(user);
oAuthAppDO.setApplicationName("testApp");
AppInfoCache appInfoCache = AppInfoCache.getInstance();
appInfoCache.addToCache(TEST_CONSUMER_KEY, oAuthAppDO);
CodeResponseTypeHandler codeResponseTypeHandler = new CodeResponseTypeHandler();
codeResponseTypeHandler.init();
OAuth2AuthorizeRespDTO oAuth2AuthorizeRespDTO = codeResponseTypeHandler.issue(authAuthzReqMessageContext);
Assert.assertNotNull(oAuth2AuthorizeRespDTO.getAuthorizationCode(), "Access token not Authorization code");
Assert.assertEquals(oAuth2AuthorizeRespDTO.getCallbackURI(), TEST_CALLBACK_URL, "Callback url not set");
}
use of org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO in project identity-inbound-auth-oauth by wso2-extensions.
the class TokenResponseTypeHandlerTest method testIssue.
@Test(dataProvider = "CommonDataProvider")
public void testIssue(boolean isIDPIdColumnEnabled, String clientId) throws Exception {
OAuth2ServiceComponentHolder.setIDPIdColumnEnabled(isIDPIdColumnEnabled);
AccessTokenResponseTypeHandler tokenResponseTypeHandler = new AccessTokenResponseTypeHandler();
tokenResponseTypeHandler.init();
OAuth2AuthorizeReqDTO authorizationReqDTO = new OAuth2AuthorizeReqDTO();
authorizationReqDTO.setCallbackUrl("https://localhost:8000/callback");
authorizationReqDTO.setConsumerKey(clientId);
authenticatedUser.setUserName(TEST_USER_ID);
authenticatedUser.setUserId("4b4414e1-916b-4475-aaee-6b0751c29ff6");
authenticatedUser.setTenantDomain("carbon.super");
authenticatedUser.setUserStoreDomain("PTEST");
authenticatedUser.setFederatedIdPName(TestConstants.LOCAL_IDP);
authorizationReqDTO.setUser(authenticatedUser);
authorizationReqDTO.setResponseType(OAuthConstants.GrantTypes.TOKEN);
OAuthAuthzReqMessageContext authAuthzReqMessageContext = new OAuthAuthzReqMessageContext(authorizationReqDTO);
authAuthzReqMessageContext.setApprovedScope(new String[] { "scope1", "scope2", OAuthConstants.Scope.OPENID });
OAuthAppDO oAuthAppDO = new OAuthAppDO();
oAuthAppDO.setGrantTypes("implicit");
oAuthAppDO.setOauthConsumerKey(clientId);
oAuthAppDO.setUser(authenticatedUser);
oAuthAppDO.setOauthVersion(OAuthConstants.OAuthVersions.VERSION_2);
AccessTokenDO accessTokenDO = new AccessTokenDO();
accessTokenDO.setAccessToken("abcdefghijklmn");
accessTokenDO.setAuthzUser(authenticatedUser);
new OAuthAppDAO().addOAuthApplication(oAuthAppDO);
OAuth2AuthorizeRespDTO auth2AuthorizeReqDTO = tokenResponseTypeHandler.issue(authAuthzReqMessageContext);
Assert.assertNotNull(auth2AuthorizeReqDTO.getAccessToken());
Assert.assertTrue(auth2AuthorizeReqDTO.getValidityPeriod() > 1, "Access Token should be valid, i.e. not expired.");
}
use of org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO in project identity-inbound-auth-oauth by wso2-extensions.
the class DefaultIDTokenBuilderTest method testBuildIDTokenForAuthorization.
@Test
public void testBuildIDTokenForAuthorization() throws Exception {
String clientId = "dabfba9390aa423f8b04332794d83614";
OAuth2AuthorizeRespDTO oAuth2AuthorizeRespDTO = new OAuth2AuthorizeRespDTO();
AuthenticatedUser user = getDefaultAuthenticatedUserFederatedUser();
OAuthAuthzReqMessageContext oAuthAuthzReqMessageContext = getOAuthAuthzReqMessageContextForUser(user, clientId);
oAuth2AuthorizeRespDTO.setAccessToken("2sa9a678f890877856y66e75f605d456");
mockRealmService();
String idToken = defaultIDTokenBuilder.buildIDToken(oAuthAuthzReqMessageContext, oAuth2AuthorizeRespDTO);
JWTClaimsSet claims = SignedJWT.parse(idToken).getJWTClaimsSet();
Assert.assertEquals(claims.getAudience().get(0), clientId);
Assert.assertEquals(claims.getIssuer(), "https://localhost:9443/oauth2/token");
Assert.assertEquals(claims.getSubject(), "user1");
Assert.assertEquals(claims.getClaim("isk"), "wso2.is.com");
Long expirationTime = ((Date) claims.getClaim("exp")).getTime();
Assert.assertTrue(expirationTime > (new Date()).getTime());
Long issueTime = ((Date) claims.getClaim("iat")).getTime();
Assert.assertTrue(issueTime <= (new Date()).getTime());
}
use of org.wso2.carbon.identity.oauth2.dto.OAuth2AuthorizeRespDTO in project identity-inbound-auth-oauth by wso2-extensions.
the class DefaultIDTokenBuilderTest method testBuildEncryptedIDTokenForAuthorization.
@Test(dataProvider = "testBuildEncryptedIDTokenForSupportedAlgorithm")
public void testBuildEncryptedIDTokenForAuthorization(String algorithm) throws Exception {
OAuthAuthzReqMessageContext oAuthAuthzReqMessageContext = getOAuthAuthzReqMessageContextForUser(getDefaultAuthenticatedLocalUser(), CLIENT_ID);
OAuth2AuthorizeRespDTO oAuth2AuthorizeRespDTO = new OAuth2AuthorizeRespDTO();
oAuth2AuthorizeRespDTO.setAccessToken(ACCESS_TOKEN);
OAuthAppDO entry = getOAuthAppDO(algorithm);
AppInfoCache.getInstance().addToCache(CLIENT_ID, entry);
mockRealmService();
String idToken = defaultIDTokenBuilder.buildIDToken(oAuthAuthzReqMessageContext, oAuth2AuthorizeRespDTO);
EncryptedJWT encryptedJWT = decryptToken(idToken);
JWTClaimsSet claims = encryptedJWT.getPayload().toSignedJWT().getJWTClaimsSet();
Assert.assertEquals(claims.getAudience().get(0), CLIENT_ID);
Assert.assertEquals(claims.getIssuer(), "https://localhost:9443/oauth2/token");
Assert.assertEquals(claims.getSubject(), "user1");
Assert.assertEquals(claims.getClaim("isk"), "wso2.is.com");
Long expirationTime = ((Date) claims.getClaim("exp")).getTime();
Assert.assertTrue(expirationTime < (new Date()).getTime());
Long issueTime = ((Date) claims.getClaim("iat")).getTime();
Assert.assertTrue(issueTime <= (new Date()).getTime());
}
Aggregations