use of org.wso2.carbon.identity.oauth.dto.OAuthErrorDTO in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2AuthzEndpointTest method testBuildOAuthProblemException.
@Test(dataProvider = "provideFailedAuthenticationErrorInfo")
public void testBuildOAuthProblemException(Object oAuthErrorDTOObject, Object authenticationResultObject, String expectedCode, String expectedMessage, String expectedURI) throws Exception {
OAuthErrorDTO oAuthErrorDTO = (OAuthErrorDTO) oAuthErrorDTOObject;
AuthenticationResult authenticationResult = (AuthenticationResult) authenticationResultObject;
Assert.assertEquals(expectedCode, oAuth2AuthzEndpoint.buildOAuthProblemException(authenticationResult, oAuthErrorDTO).getError());
Assert.assertEquals(expectedMessage, oAuth2AuthzEndpoint.buildOAuthProblemException(authenticationResult, oAuthErrorDTO).getDescription());
Assert.assertEquals(expectedURI, oAuth2AuthzEndpoint.buildOAuthProblemException(authenticationResult, oAuthErrorDTO).getUri());
}
use of org.wso2.carbon.identity.oauth.dto.OAuthErrorDTO in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2AuthzEndpointTest method provideFailedAuthenticationErrorInfo.
@DataProvider(name = "provideFailedAuthenticationErrorInfo")
public Object[][] provideFailedAuthenticationErrorInfo() {
OAuthErrorDTO oAuthErrorDTO = null;
AuthenticationResult authenticationResult = new AuthenticationResult();
authenticationResult.addProperty(FrameworkConstants.AUTH_ERROR_URI, null);
authenticationResult.addProperty(FrameworkConstants.AUTH_ERROR_MSG, null);
authenticationResult.addProperty(FrameworkConstants.AUTH_ERROR_CODE, null);
OAuthErrorDTO oAuthErrorDTONull = new OAuthErrorDTO();
AuthenticationResult authenticationResultEmpty = new AuthenticationResult();
OAuthErrorDTO oAuthErrorDTOEmpty = new OAuthErrorDTO();
AuthenticationResult authenticationResultWithURI = new AuthenticationResult();
authenticationResultWithURI.addProperty(FrameworkConstants.AUTH_ERROR_URI, "http://sample_error_uri.com");
authenticationResultWithURI.addProperty(FrameworkConstants.AUTH_ERROR_MSG, null);
authenticationResultWithURI.addProperty(FrameworkConstants.AUTH_ERROR_CODE, null);
OAuthErrorDTO oAuthErrorDTOEmptyTest = new OAuthErrorDTO();
AuthenticationResult authenticationResultWithoutErrorcode = new AuthenticationResult();
authenticationResultWithoutErrorcode.addProperty(FrameworkConstants.AUTH_ERROR_MSG, "OverRiddenMessage2");
authenticationResultWithoutErrorcode.addProperty(FrameworkConstants.AUTH_ERROR_URI, "http://sample_error_uri2.com");
authenticationResultWithoutErrorcode.addProperty(FrameworkConstants.AUTH_ERROR_CODE, null);
OAuthErrorDTO oAuthErrorDTOWithDes = new OAuthErrorDTO();
oAuthErrorDTOWithDes.setErrorDescription("messageFromErrorDTO");
AuthenticationResult authenticationResultWithURIOnly = new AuthenticationResult();
authenticationResultWithURIOnly.addProperty(FrameworkConstants.AUTH_ERROR_URI, "http://sample_error_uri3.com");
authenticationResultWithURIOnly.addProperty(FrameworkConstants.AUTH_ERROR_MSG, null);
authenticationResultWithURIOnly.addProperty(FrameworkConstants.AUTH_ERROR_CODE, null);
OAuthErrorDTO oAuthErrorDTOOverWritable = new OAuthErrorDTO();
oAuthErrorDTOOverWritable.setErrorDescription("messageFromErrorDTO");
AuthenticationResult authenticationResultOverRiding = new AuthenticationResult();
authenticationResultOverRiding.addProperty(FrameworkConstants.AUTH_ERROR_MSG, "OverRiddenMessage5");
authenticationResultOverRiding.addProperty(FrameworkConstants.AUTH_ERROR_URI, "http://sample_error_uri4.com");
authenticationResultOverRiding.addProperty(FrameworkConstants.AUTH_ERROR_CODE, null);
return new Object[][] { { null, authenticationResult, "login_required", "Authentication required", null }, { oAuthErrorDTONull, authenticationResultEmpty, "login_required", "Authentication required", null }, { oAuthErrorDTOEmptyTest, authenticationResultWithURI, "login_required", "Authentication required", "http" + "://sample_error_uri.com" }, { oAuthErrorDTOEmptyTest, authenticationResultWithoutErrorcode, "login_required", "OverRiddenMessage2", "http" + "://sample_error_uri2.com" }, { oAuthErrorDTOWithDes, authenticationResultWithURIOnly, "login_required", "messageFromErrorDTO", "http" + "://sample_error_uri3.com" }, { oAuthErrorDTOOverWritable, authenticationResultOverRiding, "login_required", "OverRiddenMessage5", "http" + "://sample_error_uri4.com" } };
}
use of org.wso2.carbon.identity.oauth.dto.OAuthErrorDTO in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2AuthzEndpoint method handleFailedAuthentication.
private Response handleFailedAuthentication(OAuthMessage oAuthMessage, OAuth2Parameters oauth2Params, AuthenticationResult authnResult) throws URISyntaxException {
OAuthErrorDTO oAuthErrorDTO = EndpointUtil.getOAuth2Service().handleAuthenticationFailure(oauth2Params);
OAuthProblemException oauthException = buildOAuthProblemException(authnResult, oAuthErrorDTO);
return handleFailedState(oAuthMessage, oauth2Params, oauthException);
}
use of org.wso2.carbon.identity.oauth.dto.OAuthErrorDTO in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2AuthzEndpoint method handleDeniedConsent.
private Response handleDeniedConsent(OAuthMessage oAuthMessage) throws OAuthSystemException, URISyntaxException {
OAuth2Parameters oauth2Params = getOauth2Params(oAuthMessage);
OpenIDConnectUserRPStore.getInstance().putUserRPToStore(getLoggedInUser(oAuthMessage), getOauth2Params(oAuthMessage).getApplicationName(), false, oauth2Params.getClientId());
OAuthErrorDTO oAuthErrorDTO = EndpointUtil.getOAuth2Service().handleUserConsentDenial(oauth2Params);
OAuthProblemException consentDenialException = buildConsentDenialException(oAuthErrorDTO);
String denyResponse = EndpointUtil.getErrorRedirectURL(oAuthMessage.getRequest(), consentDenialException, oauth2Params);
if (StringUtils.equals(oauth2Params.getResponseMode(), RESPONSE_MODE_FORM_POST)) {
return handleFailedState(oAuthMessage, oauth2Params, consentDenialException);
}
return Response.status(HttpServletResponse.SC_FOUND).location(new URI(denyResponse)).build();
}
use of org.wso2.carbon.identity.oauth.dto.OAuthErrorDTO in project identity-inbound-auth-oauth by wso2-extensions.
the class OAuth2AuthzEndpointTest method testAuthorizeForAuthenticationResponse.
@Test(dataProvider = "provideAuthenticatedData", groups = "testWithConnection")
public void testAuthorizeForAuthenticationResponse(boolean isResultInRequest, boolean isAuthenticated, Map<ClaimMapping, String> attributes, String errorCode, String errorMsg, String errorUri, Set<String> scopes, String responseMode, String redirectUri, int expected) throws Exception {
mockStatic(SessionDataCache.class);
when(SessionDataCache.getInstance()).thenReturn(sessionDataCache);
SessionDataCacheKey loginDataCacheKey = new SessionDataCacheKey(SESSION_DATA_KEY_VALUE);
when(sessionDataCache.getValueFromCache(loginDataCacheKey)).thenReturn(loginCacheEntry);
mockStatic(LoggerUtils.class);
when(LoggerUtils.isDiagnosticLogsEnabled()).thenReturn(true);
AuthenticationResult result = setAuthenticationResult(isAuthenticated, attributes, errorCode, errorMsg, errorUri);
AuthenticationResult resultInRequest = null;
AuthenticationResultCacheEntry authResultCacheEntry = null;
if (isResultInRequest) {
resultInRequest = result;
} else {
authResultCacheEntry = new AuthenticationResultCacheEntry();
authResultCacheEntry.setResult(result);
}
Map<String, String[]> requestParams = new HashMap<>();
Map<String, Object> requestAttributes = new HashMap<>();
requestParams.put(CLIENT_ID, new String[] { CLIENT_ID_VALUE });
requestParams.put(FrameworkConstants.RequestParams.TO_COMMONAUTH, new String[] { "false" });
requestParams.put(OAuthConstants.OAuth20Params.SCOPE, new String[] { OAuthConstants.Scope.OPENID });
requestAttributes.put(FrameworkConstants.RequestParams.FLOW_STATUS, AuthenticatorFlowStatus.INCOMPLETE);
requestAttributes.put(FrameworkConstants.SESSION_DATA_KEY, SESSION_DATA_KEY_VALUE);
requestAttributes.put(FrameworkConstants.RequestAttribute.AUTH_RESULT, resultInRequest);
mockHttpRequest(requestParams, requestAttributes, HttpMethod.POST);
spy(FrameworkUtils.class);
doReturn(requestCoordinator).when(FrameworkUtils.class, "getRequestCoordinator");
doNothing().when(FrameworkUtils.class, "startTenantFlow", anyString());
doNothing().when(FrameworkUtils.class, "endTenantFlow");
spy(IdentityUtil.class);
doReturn("https://localhost:9443/carbon").when(IdentityUtil.class, "getServerURL", anyString(), anyBoolean(), anyBoolean());
OAuth2Parameters oAuth2Params = setOAuth2Parameters(scopes, APP_NAME, responseMode, redirectUri);
oAuth2Params.setClientId(CLIENT_ID_VALUE);
oAuth2Params.setState(STATE);
when(loginCacheEntry.getoAuth2Parameters()).thenReturn(oAuth2Params);
when(loginCacheEntry.getLoggedInUser()).thenReturn(result.getSubject());
mockOAuthServerConfiguration();
mockStatic(IdentityTenantUtil.class);
when(IdentityTenantUtil.getTenantDomain(anyInt())).thenReturn(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
when(IdentityTenantUtil.getTenantId(anyString())).thenReturn(MultitenantConstants.SUPER_TENANT_ID);
spy(FrameworkUtils.class);
doReturn("sample").when(FrameworkUtils.class, "resolveUserIdFromUsername", anyInt(), anyString(), anyString());
doNothing().when(FrameworkUtils.class, "startTenantFlow", anyString());
doNothing().when(FrameworkUtils.class, "endTenantFlow");
try (Connection connection = getConnection()) {
mockStatic(IdentityDatabaseUtil.class);
when(IdentityDatabaseUtil.getDBConnection()).thenReturn(connection);
mockStatic(OpenIDConnectUserRPStore.class);
when(OpenIDConnectUserRPStore.getInstance()).thenReturn(openIDConnectUserRPStore);
when(openIDConnectUserRPStore.hasUserApproved(any(AuthenticatedUser.class), anyString(), anyString())).thenReturn(true);
mockEndpointUtil(false);
when(oAuth2Service.getOauthApplicationState(CLIENT_ID_VALUE)).thenReturn("ACTIVE");
mockApplicationManagementService();
mockEndpointUtil(false);
when(oAuth2Service.handleAuthenticationFailure(oAuth2Params)).thenReturn(oAuthErrorDTO);
when(oAuth2ScopeService.hasUserProvidedConsentForAllRequestedScopes(anyString(), anyString(), anyInt(), anyList())).thenReturn(true);
mockServiceURLBuilder();
Response response = oAuth2AuthzEndpoint.authorize(httpServletRequest, httpServletResponse);
assertEquals(response.getStatus(), expected, "Unexpected HTTP response status");
if (!isAuthenticated) {
String expectedState = "name=\"" + OAuthConstants.OAuth20Params.STATE + "\" value=\"" + STATE + "\"";
assertTrue(response.getEntity().toString().contains(expectedState));
}
}
}
Aggregations