Search in sources :

Example 6 with AuthenticationResult

use of org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationResult 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());
}
Also used : OAuthErrorDTO(org.wso2.carbon.identity.oauth.dto.OAuthErrorDTO) AuthenticationResult(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationResult) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with AuthenticationResult

use of org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationResult 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" } };
}
Also used : RequestObject(org.wso2.carbon.identity.openidconnect.model.RequestObject) OAuthErrorDTO(org.wso2.carbon.identity.oauth.dto.OAuthErrorDTO) AuthenticationResult(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationResult) DataProvider(org.testng.annotations.DataProvider)

Example 8 with AuthenticationResult

use of org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationResult 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);
}
Also used : OAuthProblemException(org.apache.oltu.oauth2.common.exception.OAuthProblemException) OAuthErrorDTO(org.wso2.carbon.identity.oauth.dto.OAuthErrorDTO)

Example 9 with AuthenticationResult

use of org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationResult in project identity-inbound-auth-oauth by wso2-extensions.

the class OAuth2AuthzEndpoint method getAuthenticationResult.

private AuthenticationResult getAuthenticationResult(OAuthMessage oAuthMessage, String sessionDataKey) {
    AuthenticationResult result = getAuthenticationResultFromRequest(oAuthMessage.getRequest());
    if (result == null) {
        isCacheAvailable = true;
        result = getAuthenticationResultFromCache(sessionDataKey);
    }
    return result;
}
Also used : AuthenticationResult(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationResult)

Example 10 with AuthenticationResult

use of org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationResult in project identity-inbound-auth-oauth by wso2-extensions.

the class OAuth2AuthzEndpoint method getAuthenticationResultFromCache.

private AuthenticationResult getAuthenticationResultFromCache(String sessionDataKey) {
    AuthenticationResult authResult = null;
    AuthenticationResultCacheEntry authResultCacheEntry = FrameworkUtils.getAuthenticationResultFromCache(sessionDataKey);
    if (authResultCacheEntry != null) {
        authResult = authResultCacheEntry.getResult();
    } else {
        log.error("Cannot find AuthenticationResult from the cache");
    }
    return authResult;
}
Also used : AuthenticationResultCacheEntry(org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationResultCacheEntry) AuthenticationResult(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationResult)

Aggregations

AuthenticationResult (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticationResult)15 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 Test (org.testng.annotations.Test)8 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)7 AuthenticationResult (org.wso2.carbon.user.core.common.AuthenticationResult)6 AuthenticationResultCacheEntry (org.wso2.carbon.identity.application.authentication.framework.cache.AuthenticationResultCacheEntry)5 OAuth2Parameters (org.wso2.carbon.identity.oauth2.model.OAuth2Parameters)5 HashMap (java.util.HashMap)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 AfterTest (org.testng.annotations.AfterTest)4 BeforeTest (org.testng.annotations.BeforeTest)4 RequestObject (org.wso2.carbon.identity.openidconnect.model.RequestObject)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)3 Response (javax.ws.rs.core.Response)3 OAuthResponse (org.apache.oltu.oauth2.common.message.OAuthResponse)3 Matchers.anyString (org.mockito.Matchers.anyString)3 CommonAuthResponseWrapper (org.wso2.carbon.identity.application.authentication.framework.model.CommonAuthResponseWrapper)3 AbstractIdentityUserOperationEventListener (org.wso2.carbon.identity.core.AbstractIdentityUserOperationEventListener)3 ResolvedUserResult (org.wso2.carbon.identity.multi.attribute.login.mgt.ResolvedUserResult)3