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");
}
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");
}
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);
}
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;
}
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);
}
}
}
Aggregations