Search in sources :

Example 6 with JsFunctionRegistryImpl

use of org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsFunctionRegistryImpl in project identity-conditional-auth-functions by wso2-extensions.

the class JsSequenceHandlerRunner method init.

public void init(URL applicationAuthenticatorConfigFileLocation) throws InvocationTargetException {
    this.applicationAuthenticatorConfigFileLocation = applicationAuthenticatorConfigFileLocation;
    configurationLoader = new UIBasedConfigurationLoader();
    graphBuilderFactory = new JsGraphBuilderFactory();
    jsFunctionRegistry = new JsFunctionRegistryImpl();
    FrameworkServiceDataHolder.getInstance().setJsFunctionRegistry(jsFunctionRegistry);
    jsExecutionSupervisor = new JSExecutionSupervisor(THREAD_COUNT, SUPERVISOR_TIMEOUT);
    FrameworkServiceDataHolder.getInstance().setJsExecutionSupervisor(jsExecutionSupervisor);
    graphBuilderFactory.init();
    FrameworkServiceDataHolder.getInstance().setJsGraphBuilderFactory(graphBuilderFactory);
    AsyncSequenceExecutor asyncSequenceExecutor = new AsyncSequenceExecutor();
    asyncSequenceExecutor.init();
    FrameworkServiceDataHolder.getInstance().setAsyncSequenceExecutor(asyncSequenceExecutor);
    if (applicationAuthenticatorConfigFileLocation == null) {
        this.applicationAuthenticatorConfigFileLocation = this.getClass().getClassLoader().getResource(DEFAULT_APPLICATION_AUTHENTICATION_XML_FILE_NAME);
    }
    reset();
}
Also used : UIBasedConfigurationLoader(org.wso2.carbon.identity.application.authentication.framework.config.loader.UIBasedConfigurationLoader) JsGraphBuilderFactory(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilderFactory) JSExecutionSupervisor(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JSExecutionSupervisor) JsFunctionRegistryImpl(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsFunctionRegistryImpl) AsyncSequenceExecutor(org.wso2.carbon.identity.application.authentication.framework.handler.sequence.impl.AsyncSequenceExecutor)

Example 7 with JsFunctionRegistryImpl

use of org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsFunctionRegistryImpl in project carbon-identity-framework by wso2.

the class GraphBasedSequenceHandlerCustomFunctionsTest method testHandleDynamicOnFallback.

@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());
}
Also used : JsAuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext) AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) JsAuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext) JsFunctionRegistryImpl(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsFunctionRegistryImpl) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) AuthHistory(org.wso2.carbon.identity.application.authentication.framework.context.AuthHistory) Test(org.testng.annotations.Test)

Example 8 with JsFunctionRegistryImpl

use of org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsFunctionRegistryImpl in project carbon-identity-framework by wso2.

the class GraphBasedSequenceHandlerCustomFunctionsTest method testHandleDynamicOnFail.

@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());
}
Also used : JsAuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext) AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) JsAuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext) JsFunctionRegistryImpl(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsFunctionRegistryImpl) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) AuthHistory(org.wso2.carbon.identity.application.authentication.framework.context.AuthHistory) Test(org.testng.annotations.Test)

Example 9 with JsFunctionRegistryImpl

use of org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsFunctionRegistryImpl in project carbon-identity-framework by wso2.

the class GraphBasedSequenceHandlerCustomFunctionsTest method testHandleDynamicJavascript1.

@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");
}
Also used : JsAuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext) AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) JsAuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext) JsFunctionRegistryImpl(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsFunctionRegistryImpl) AuthHistory(org.wso2.carbon.identity.application.authentication.framework.context.AuthHistory) Test(org.testng.annotations.Test)

Example 10 with JsFunctionRegistryImpl

use of org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsFunctionRegistryImpl in project carbon-identity-framework by wso2.

the class GraphBasedSequenceHandlerLongWaitTest method testHandleLongWait.

@Test
public void testHandleLongWait() throws Exception {
    PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
    PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
    JsFunctionRegistryImpl jsFunctionRegistrar = new JsFunctionRegistryImpl();
    FrameworkServiceDataHolder.getInstance().setJsFunctionRegistry(jsFunctionRegistrar);
    LongWaitStatusDAOImpl daoImpl = new LongWaitStatusDAOImpl();
    CacheBackedLongWaitStatusDAO cacheBackedDao = new CacheBackedLongWaitStatusDAO(daoImpl);
    FrameworkServiceDataHolder.getInstance().setLongWaitStatusStoreService(new LongWaitStatusStoreService(cacheBackedDao, 5000));
    jsFunctionRegistrar.register(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER, "testLongWaitCall", new AsyncAnalyticsCbFunctionImpl());
    ServiceProvider sp1 = getTestServiceProvider("js-sp-longwait-1.xml");
    AuthenticationContext context = getAuthenticationContext(sp1);
    context.setSessionIdentifier("1234");
    SequenceConfig sequenceConfig = configurationLoader.getSequenceConfig(context, Collections.emptyMap(), sp1);
    context.setSequenceConfig(sequenceConfig);
    HttpServletRequest req = createMockHttpServletRequest();
    HttpServletResponse resp = mock(HttpServletResponse.class);
    UserCoreUtil.setDomainInThreadLocal("test_domain");
    graphBasedSequenceHandler.handle(req, resp, context);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) CacheBackedLongWaitStatusDAO(org.wso2.carbon.identity.application.authentication.framework.dao.impl.CacheBackedLongWaitStatusDAO) JsFunctionRegistryImpl(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsFunctionRegistryImpl) LongWaitStatusStoreService(org.wso2.carbon.identity.application.authentication.framework.store.LongWaitStatusStoreService) 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) LongWaitStatusDAOImpl(org.wso2.carbon.identity.application.authentication.framework.dao.impl.LongWaitStatusDAOImpl) Test(org.testng.annotations.Test)

Aggregations

JsFunctionRegistryImpl (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsFunctionRegistryImpl)11 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)7 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)6 Test (org.testng.annotations.Test)5 JsAuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext)5 AuthHistory (org.wso2.carbon.identity.application.authentication.framework.context.AuthHistory)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 JsFunctionRegistry (org.wso2.carbon.identity.application.authentication.framework.JsFunctionRegistry)3 UIBasedConfigurationLoader (org.wso2.carbon.identity.application.authentication.framework.config.loader.UIBasedConfigurationLoader)3 SequenceConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig)3 JsGraphBuilderFactory (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilderFactory)3 CacheBackedLongWaitStatusDAO (org.wso2.carbon.identity.application.authentication.framework.dao.impl.CacheBackedLongWaitStatusDAO)3 LongWaitStatusDAOImpl (org.wso2.carbon.identity.application.authentication.framework.dao.impl.LongWaitStatusDAOImpl)3 LongWaitStatusStoreService (org.wso2.carbon.identity.application.authentication.framework.store.LongWaitStatusStoreService)3 AsyncSequenceExecutor (org.wso2.carbon.identity.application.authentication.framework.handler.sequence.impl.AsyncSequenceExecutor)2 IOException (java.io.IOException)1 BiFunction (java.util.function.BiFunction)1 Servlet (javax.servlet.Servlet)1 ContextPathServletAdaptor (org.eclipse.equinox.http.helper.ContextPathServletAdaptor)1