Search in sources :

Example 16 with AuthHistory

use of org.wso2.carbon.identity.application.authentication.framework.context.AuthHistory in project carbon-identity-framework by wso2.

the class GraphBasedSequenceHandlerFailTest method handleFailMethodWithoutParamsOnFailTest.

@Test
public void handleFailMethodWithoutParamsOnFailTest() throws Exception {
    PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
    PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
    ServiceProvider sp1 = getTestServiceProvider("js-sp-fail-method-without-params-onFail.xml");
    AuthenticationContext context = getAuthenticationContext(sp1);
    SequenceConfig sequenceConfig = configurationLoader.getSequenceConfig(context, Collections.<String, String[]>emptyMap(), sp1);
    context.setSequenceConfig(sequenceConfig);
    HttpServletRequest req = mock(HttpServletRequest.class);
    when(req.getAttribute(FrameworkConstants.RequestParams.FLOW_STATUS)).thenReturn(AuthenticatorFlowStatus.FAIL_COMPLETED);
    HttpServletResponse resp = mock(HttpServletResponse.class);
    UserCoreUtil.setDomainInThreadLocal("test_domain");
    graphBasedSequenceHandler.handle(req, resp, context);
    List<AuthHistory> authHistories = context.getAuthenticationStepHistory();
    assertNotNull(authHistories);
    assertFalse(context.isRequestAuthenticated());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) HttpServletResponse(javax.servlet.http.HttpServletResponse) SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig) AuthHistory(org.wso2.carbon.identity.application.authentication.framework.context.AuthHistory) Test(org.testng.annotations.Test)

Example 17 with AuthHistory

use of org.wso2.carbon.identity.application.authentication.framework.context.AuthHistory in project carbon-identity-framework by wso2.

the class GraphBasedSequenceHandlerNoJsTest method testHandleStaticSequence.

@Test(dataProvider = "noJsDataProvider")
public void testHandleStaticSequence(String spFileName, int authHistoryCount) throws Exception {
    PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
    PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
    ServiceProvider sp1 = getTestServiceProvider(spFileName);
    AuthenticationContext context = getAuthenticationContext(sp1);
    SequenceConfig sequenceConfig = configurationLoader.getSequenceConfig(context, Collections.emptyMap(), sp1);
    context.setSequenceConfig(sequenceConfig);
    HttpServletRequest req = mock(HttpServletRequest.class);
    HttpServletResponse resp = mock(HttpServletResponse.class);
    UserCoreUtil.setDomainInThreadLocal("test_domain");
    graphBasedSequenceHandler.handle(req, resp, context);
    List<AuthHistory> authHistories = context.getAuthenticationStepHistory();
    assertNotNull(authHistories);
    assertEquals(authHistories.size(), authHistoryCount);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) HttpServletResponse(javax.servlet.http.HttpServletResponse) SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig) AuthHistory(org.wso2.carbon.identity.application.authentication.framework.context.AuthHistory) Test(org.testng.annotations.Test)

Example 18 with AuthHistory

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

the class OAuth2AuthzEndpoint method associateAuthenticationHistory.

/**
 * Associates the authentication method references done while logged into the session (if any) to the OAuth cache.
 * The SessionDataCacheEntry then will be used when getting "AuthenticationMethodReferences". Please see
 * <a href="https://tools.ietf.org/html/draft-ietf-oauth-amr-values-02" >draft-ietf-oauth-amr-values-02</a>.
 *
 * @param resultFromLogin
 * @param cookie
 */
private void associateAuthenticationHistory(SessionDataCacheEntry resultFromLogin, Cookie cookie) {
    SessionContext sessionContext = getSessionContext(cookie, resultFromLogin.getoAuth2Parameters().getLoginTenantDomain());
    if (sessionContext != null && sessionContext.getSessionAuthHistory() != null && sessionContext.getSessionAuthHistory().getHistory() != null) {
        List<String> authMethods = new ArrayList<>();
        for (AuthHistory authHistory : sessionContext.getSessionAuthHistory().getHistory()) {
            authMethods.add(authHistory.toTranslatableString());
        }
        resultFromLogin.getParamMap().put(OAuthConstants.AMR, authMethods.toArray(new String[authMethods.size()]));
    }
}
Also used : ArrayList(java.util.ArrayList) SessionContext(org.wso2.carbon.identity.application.authentication.framework.context.SessionContext) AuthHistory(org.wso2.carbon.identity.application.authentication.framework.context.AuthHistory)

Aggregations

AuthHistory (org.wso2.carbon.identity.application.authentication.framework.context.AuthHistory)16 SequenceConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig)11 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)11 Test (org.testng.annotations.Test)10 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)10 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 JsFunctionRegistryImpl (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsFunctionRegistryImpl)5 JsAuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext)5 UserSessionException (org.wso2.carbon.identity.application.authentication.framework.exception.UserSessionException)5 FrameworkException (org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException)4 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)4 ApplicationAuthenticator (org.wso2.carbon.identity.application.authentication.framework.ApplicationAuthenticator)3 AuthenticatorFlowStatus (org.wso2.carbon.identity.application.authentication.framework.AuthenticatorFlowStatus)3 StepConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.StepConfig)3 SessionContext (org.wso2.carbon.identity.application.authentication.framework.context.SessionContext)3 AuthenticationFailedException (org.wso2.carbon.identity.application.authentication.framework.exception.AuthenticationFailedException)3 LogoutFailedException (org.wso2.carbon.identity.application.authentication.framework.exception.LogoutFailedException)3 ArrayList (java.util.ArrayList)2 JsFunctionRegistry (org.wso2.carbon.identity.application.authentication.framework.JsFunctionRegistry)2