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