Java Code Examples for org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext#getAuthenticationStepHistory()

The following examples show how to use org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext#getAuthenticationStepHistory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GraphBasedSequenceHandlerNoJsTest.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
@Test(dataProvider = "noJsDataProvider")
public void testHandleStaticSequence(String spFileName, int authHistoryCount) throws
        Exception {
    ServiceProvider sp1 = getTestServiceProvider(spFileName);

    AuthenticationContext context = getAuthenticationContext(sp1);

    SequenceConfig sequenceConfig = configurationLoader
            .getSequenceConfig(context, Collections.<String, String[]>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);
}
 
Example 2
Source File: GraphBasedSequenceHandlerCustomFunctionsTest.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
@Test
public void testHandleDynamicJavascript1() throws Exception {

    JsFunctionRegistryImpl jsFunctionRegistrar = new JsFunctionRegistryImpl();
    FrameworkServiceDataHolder.getInstance().setJsFunctionRegistry(jsFunctionRegistrar);
    jsFunctionRegistrar.register(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER, "fn1",
            (Function<JsAuthenticationContext, String>) GraphBasedSequenceHandlerCustomFunctionsTest::customFunction1);
    jsFunctionRegistrar.register(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER, "fn2", new CustomFunctionImpl2());

    AuthenticationContext context = processSequenceWithAcr(new String[] { "acr1" });
    List<AuthHistory> authHistories = context.getAuthenticationStepHistory();
    assertNotNull(authHistories);
    assertEquals(3, authHistories.size());
    assertEquals(authHistories.get(0).getAuthenticatorName(), "BasicMockAuthenticator");
    assertEquals(authHistories.get(1).getAuthenticatorName(), "HwkMockAuthenticator");
    assertEquals(authHistories.get(2).getAuthenticatorName(), "FptMockAuthenticator");
}
 
Example 3
Source File: GraphBasedSequenceHandlerAcrTest.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Test(dataProvider = "staticAcrDataProvider")
public void testHandleStaticJavascriptAcr(String spFileName, String[] acrArray, 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);
    if (acrArray != null) {
        for (String acr : acrArray) {
            context.addRequestedAcr(acr);
        }
    }

    SequenceConfig sequenceConfig = configurationLoader
            .getSequenceConfig(context, Collections.<String, String[]>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);
}
 
Example 4
Source File: GraphBasedSequenceHandlerCustomFunctionsTest.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Test
public void testHandleDynamicOnFail() throws Exception {

    FrameworkServiceDataHolder.getInstance().getAuthenticators()
            .add(new MockFailingAuthenticator("BasicFailingMockAuthenticator"));

    JsFunctionRegistryImpl jsFunctionRegistrar = new JsFunctionRegistryImpl();
    FrameworkServiceDataHolder.getInstance().setJsFunctionRegistry(jsFunctionRegistrar);
    jsFunctionRegistrar.register(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER, "fn1",
            (Function<JsAuthenticationContext, String>) GraphBasedSequenceHandlerCustomFunctionsTest::customFunction1);
    jsFunctionRegistrar.register(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER, "getTrueFunction",
            (Function<JsAuthenticationContext, Boolean>) GraphBasedSequenceHandlerCustomFunctionsTest::customBoolean);

    jsFunctionRegistrar.register(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER, "getTrueFunction2",
            (BiFunction<JsAuthenticationContext, String, Boolean>) GraphBasedSequenceHandlerCustomFunctionsTest::customBoolean2);

    ServiceProvider sp1 = getTestServiceProvider("js-sp-dynamic-on-fail.xml");

    AuthenticationContext context = processAndGetAuthenticationContext(new String[0], sp1);
    List<AuthHistory> authHistories = context.getAuthenticationStepHistory();
    assertNotNull(authHistories);
    assertEquals( authHistories.size(), 3);
    assertEquals(authHistories.get(0).getAuthenticatorName(), "BasicFailingMockAuthenticator");
    assertEquals(authHistories.get(1).getAuthenticatorName(), "BasicMockAuthenticator");
    assertEquals(authHistories.get(2).getAuthenticatorName(), "FptMockAuthenticator");

    assertTrue(context.isRequestAuthenticated());
}
 
Example 5
Source File: GraphBasedSequenceHandlerCustomFunctionsTest.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Test
public void testHandleDynamicOnFallback() throws Exception {

    FrameworkServiceDataHolder.getInstance().getAuthenticators()
            .add(new MockFallbackAuthenticator("MockFallbackAuthenticator"));

    JsFunctionRegistryImpl jsFunctionRegistrar = new JsFunctionRegistryImpl();
    FrameworkServiceDataHolder.getInstance().setJsFunctionRegistry(jsFunctionRegistrar);
    jsFunctionRegistrar.register(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER, "fn1",
            (Function<JsAuthenticationContext, String>) GraphBasedSequenceHandlerCustomFunctionsTest::customFunction1);
    jsFunctionRegistrar.register(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER, "getTrueFunction",
            (Function<JsAuthenticationContext, Boolean>) GraphBasedSequenceHandlerCustomFunctionsTest::customBoolean);

    jsFunctionRegistrar.register(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER, "getTrueFunction2",
            (BiFunction<JsAuthenticationContext, String, Boolean>) GraphBasedSequenceHandlerCustomFunctionsTest::customBoolean2);

    ServiceProvider sp1 = getTestServiceProvider("js-sp-dynamic-on-fallback.xml");

    AuthenticationContext context = processAndGetAuthenticationContext(new String[0], sp1);
    List<AuthHistory> authHistories = context.getAuthenticationStepHistory();
    assertNotNull(authHistories);
    assertEquals( authHistories.size(), 4);
    assertEquals(authHistories.get(0).getAuthenticatorName(), "MockFallbackAuthenticator");
    assertEquals(authHistories.get(1).getAuthenticatorName(), "BasicMockAuthenticator");
    assertEquals(authHistories.get(2).getAuthenticatorName(), "HwkMockAuthenticator");
    assertEquals(authHistories.get(3).getAuthenticatorName(), "FptMockAuthenticator");

    assertTrue(context.isRequestAuthenticated());
}
 
Example 6
Source File: GraphBasedSequenceHandlerCustomFunctionsTest.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
@Test
public void testHandleDynamicJavascriptSerialization() throws Exception {

    JsFunctionRegistry jsFunctionRegistrar = new JsFunctionRegistryImpl();
    FrameworkServiceDataHolder.getInstance().setJsFunctionRegistry(jsFunctionRegistrar);
    jsFunctionRegistrar.register(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER, "fn1",
            (Function<JsAuthenticationContext, String>) GraphBasedSequenceHandlerCustomFunctionsTest::customFunction1);

    ServiceProvider sp1 = getTestServiceProvider("js-sp-dynamic-1.xml");

    AuthenticationContext context = getAuthenticationContext(sp1);

    SequenceConfig sequenceConfig = configurationLoader
            .getSequenceConfig(context, Collections.<String, String[]>emptyMap(), sp1);
    context.setSequenceConfig(sequenceConfig);

    byte[] serialized = SerializationUtils.serialize(context);

    AuthenticationContext deseralizedContext = (AuthenticationContext) SerializationUtils.deserialize(serialized);
    assertNotNull(deseralizedContext);

    HttpServletRequest req = mock(HttpServletRequest.class);
    addMockAttributes(req);

    HttpServletResponse resp = mock(HttpServletResponse.class);

    UserCoreUtil.setDomainInThreadLocal("test_domain");

    graphBasedSequenceHandler.handle(req, resp, deseralizedContext);

    List<AuthHistory> authHistories = deseralizedContext.getAuthenticationStepHistory();
    assertNotNull(authHistories);
    assertEquals(3, authHistories.size());
    assertEquals(authHistories.get(0).getAuthenticatorName(), "BasicMockAuthenticator");
    assertEquals(authHistories.get(1).getAuthenticatorName(), "HwkMockAuthenticator");
    assertEquals(authHistories.get(2).getAuthenticatorName(), "FptMockAuthenticator");
}
 
Example 7
Source File: GraphBasedSequenceHandlerCustomFunctionsTest.java    From carbon-identity-framework with Apache License 2.0 4 votes vote down vote up
public void testHandleDynamicBoolean() throws Exception {

        JsFunctionRegistry jsFunctionRegistrar = new JsFunctionRegistryImpl();
        FrameworkServiceDataHolder.getInstance().setJsFunctionRegistry(jsFunctionRegistrar);
        jsFunctionRegistrar.register(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER, "fn1",
                (Function<JsAuthenticationContext, String>) GraphBasedSequenceHandlerCustomFunctionsTest::customFunction1);
        jsFunctionRegistrar.register(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER, "getTrueFunction",
                (Function<JsAuthenticationContext, Boolean>) GraphBasedSequenceHandlerCustomFunctionsTest::customBoolean);

        jsFunctionRegistrar.register(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER, "getTrueFunction2",
                (BiFunction<JsAuthenticationContext, String, Boolean>)GraphBasedSequenceHandlerCustomFunctionsTest::customBoolean2);

        ServiceProvider sp1 = getTestServiceProvider("js-sp-dynamic-1.xml");

        String script =
                "var onLoginRequest = function(context) {\n" +
                "    var myBool = getTrueFunction2(context, 'a');\n" +
                "    Log.info(\"My Bool Value \"+myBool);\n" +
                "    if(myBool) {\n" +
                "        Log.info(\"My Bool Is Selected \"+myBool);\n" +
                "        executeStep(1, {\n" +
                "            onSuccess : function(context) {\n" +
                "                executeStep(3);\n" +
                "            }\n" +
                "        });\n" +
                "        executeStep(2);\n" +
                "    }  else {\n" +
                "        Log.info(\"My Bool Not Selected \"+myBool);\n" +
                "        executeStep(1);\n" +
                "        executeStep(3);\n" +
                "    }\n" +
                "};";
        sp1.getLocalAndOutBoundAuthenticationConfig().getAuthenticationScriptConfig().setContent(script);

        AuthenticationContext context = processAndGetAuthenticationContext(new String[0], sp1);
        List<AuthHistory> authHistories = context.getAuthenticationStepHistory();
        assertNotNull(authHistories);
        assertEquals( authHistories.size(), 3);
        assertEquals(authHistories.get(0).getAuthenticatorName(), "BasicMockAuthenticator");
        assertEquals(authHistories.get(1).getAuthenticatorName(), "FptMockAuthenticator");
        assertEquals(authHistories.get(2).getAuthenticatorName(), "HwkMockAuthenticator");
    }