Search in sources :

Example 6 with LongWaitStatusStoreService

use of org.wso2.carbon.identity.application.authentication.framework.store.LongWaitStatusStoreService 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)

Example 7 with LongWaitStatusStoreService

use of org.wso2.carbon.identity.application.authentication.framework.store.LongWaitStatusStoreService in project identity-conditional-auth-functions by wso2-extensions.

the class CallAnalyticsFunctionImplTest method testRiskScore.

@Test
public void testRiskScore() throws JsTestException, NoSuchFieldException, IllegalAccessException, IdentityGovernanceException {
    IdentityGovernanceService identityGovernanceService = Mockito.mock(IdentityGovernanceService.class);
    FunctionsDataHolder functionsDataHolder = Mockito.mock(FunctionsDataHolder.class);
    Mockito.when(functionsDataHolder.getIdentityGovernanceService()).thenReturn(identityGovernanceService);
    Property property = new Property();
    property.setValue("http://localhost:" + microServicePort);
    Mockito.when(identityGovernanceService.getConfiguration(new String[] { AnalyticsEngineConfigImpl.RECEIVER }, "test_domain")).thenReturn(new Property[] { property });
    Field functionsDataHolderInstance = FunctionsDataHolder.class.getDeclaredField("instance");
    functionsDataHolderInstance.setAccessible(true);
    functionsDataHolderInstance.set(null, functionsDataHolder);
    Field frameworkServiceDataHolderInstance = FrameworkServiceDataHolder.class.getDeclaredField("instance");
    frameworkServiceDataHolderInstance.setAccessible(true);
    FrameworkServiceDataHolder availableInstance = (FrameworkServiceDataHolder) frameworkServiceDataHolderInstance.get(null);
    LongWaitStatusDAOImpl daoImpl = new LongWaitStatusDAOImpl();
    CacheBackedLongWaitStatusDAO cacheBackedDao = new CacheBackedLongWaitStatusDAO(daoImpl);
    int connectionTimeout = 5000;
    LongWaitStatusStoreService longWaitStatusStoreService = new LongWaitStatusStoreService(cacheBackedDao, connectionTimeout);
    availableInstance.setLongWaitStatusStoreService(longWaitStatusStoreService);
    ServiceProvider sp1 = sequenceHandlerRunner.loadServiceProviderFromResource("risk-test-sp.xml", this);
    AuthenticationContext context = sequenceHandlerRunner.createAuthenticationContext(sp1);
    SequenceConfig sequenceConfig = sequenceHandlerRunner.getSequenceConfig(context, sp1);
    context.setSequenceConfig(sequenceConfig);
    context.initializeAnalyticsData();
    HttpServletRequest req = sequenceHandlerRunner.createHttpServletRequest();
    HttpServletResponse resp = sequenceHandlerRunner.createHttpServletResponse();
    sequenceHandlerRunner.handle(req, resp, context, "carbon.super");
    assertNotNull(context.getSelectedAcr());
    assertEquals(context.getSelectedAcr(), "1", "Expected acr value not found");
}
Also used : AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) FrameworkServiceDataHolder(org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder) LongWaitStatusDAOImpl(org.wso2.carbon.identity.application.authentication.framework.dao.impl.LongWaitStatusDAOImpl) HttpServletRequest(javax.servlet.http.HttpServletRequest) Field(java.lang.reflect.Field) CacheBackedLongWaitStatusDAO(org.wso2.carbon.identity.application.authentication.framework.dao.impl.CacheBackedLongWaitStatusDAO) LongWaitStatusStoreService(org.wso2.carbon.identity.application.authentication.framework.store.LongWaitStatusStoreService) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) IdentityGovernanceService(org.wso2.carbon.identity.governance.IdentityGovernanceService) SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig) Property(org.wso2.carbon.identity.application.common.model.Property) FunctionsDataHolder(org.wso2.carbon.identity.conditional.auth.functions.common.internal.FunctionsDataHolder) Test(org.testng.annotations.Test) JsSequenceHandlerAbstractTest(org.wso2.carbon.identity.conditional.auth.functions.test.utils.sequence.JsSequenceHandlerAbstractTest)

Example 8 with LongWaitStatusStoreService

use of org.wso2.carbon.identity.application.authentication.framework.store.LongWaitStatusStoreService in project identity-conditional-auth-functions by wso2-extensions.

the class HTTPGetFunctionImplTest method initClass.

@BeforeClass
protected void initClass() throws Exception {
    super.setUp();
    LongWaitStatusDAOImpl daoImpl = new LongWaitStatusDAOImpl();
    CacheBackedLongWaitStatusDAO cacheBackedDao = new CacheBackedLongWaitStatusDAO(daoImpl);
    int connectionTimeout = 5000;
    LongWaitStatusStoreService longWaitStatusStoreService = new LongWaitStatusStoreService(cacheBackedDao, connectionTimeout);
    FrameworkServiceDataHolder.getInstance().setLongWaitStatusStoreService(longWaitStatusStoreService);
    sequenceHandlerRunner.registerJsFunction("httpGet", new HTTPGetFunctionImpl());
}
Also used : CacheBackedLongWaitStatusDAO(org.wso2.carbon.identity.application.authentication.framework.dao.impl.CacheBackedLongWaitStatusDAO) LongWaitStatusStoreService(org.wso2.carbon.identity.application.authentication.framework.store.LongWaitStatusStoreService) LongWaitStatusDAOImpl(org.wso2.carbon.identity.application.authentication.framework.dao.impl.LongWaitStatusDAOImpl) BeforeClass(org.testng.annotations.BeforeClass)

Example 9 with LongWaitStatusStoreService

use of org.wso2.carbon.identity.application.authentication.framework.store.LongWaitStatusStoreService in project identity-conditional-auth-functions by wso2-extensions.

the class CallChoreoFunctionImplTest method testCallChoreo.

@Test(dataProvider = "choreoEpValidity")
public void testCallChoreo(boolean isValidChoreoDomain) throws JsTestException, NoSuchFieldException, IllegalAccessException, FrameworkException {
    FunctionsDataHolder functionsDataHolder = Mockito.mock(FunctionsDataHolder.class);
    Field functionsDataHolderInstance = FunctionsDataHolder.class.getDeclaredField("instance");
    functionsDataHolderInstance.setAccessible(true);
    functionsDataHolderInstance.set(null, functionsDataHolder);
    Field frameworkServiceDataHolderInstance = FrameworkServiceDataHolder.class.getDeclaredField("instance");
    frameworkServiceDataHolderInstance.setAccessible(true);
    FrameworkServiceDataHolder availableInstance = (FrameworkServiceDataHolder) frameworkServiceDataHolderInstance.get(null);
    ClientManager clientManager = new ClientManager();
    ChoreoFunctionServiceHolder.getInstance().setClientManager(clientManager);
    LongWaitStatusDAOImpl daoImpl = new LongWaitStatusDAOImpl();
    CacheBackedLongWaitStatusDAO cacheBackedDao = new CacheBackedLongWaitStatusDAO(daoImpl);
    int connectionTimeout = 5000;
    LongWaitStatusStoreService longWaitStatusStoreService = new LongWaitStatusStoreService(cacheBackedDao, connectionTimeout);
    availableInstance.setLongWaitStatusStoreService(longWaitStatusStoreService);
    ServiceProvider sp1 = sequenceHandlerRunner.loadServiceProviderFromResource("risk-test-sp.xml", this);
    LocalAndOutboundAuthenticationConfig localAndOutboundAuthenticationConfig = sp1.getLocalAndOutBoundAuthenticationConfig();
    AuthenticationScriptConfig authenticationScriptConfig = localAndOutboundAuthenticationConfig.getAuthenticationScriptConfig();
    String content = authenticationScriptConfig.getContent();
    if (isValidChoreoDomain) {
        // Setting localhost as the valid domain as
        // the unit test is calling a mock local endpoint.
        setChoreoDomain("localhost");
    } else {
        setChoreoDomain("abc");
    }
    String newContent = String.format(content, microServicePort);
    authenticationScriptConfig.setContent(newContent);
    localAndOutboundAuthenticationConfig.setAuthenticationScriptConfig(authenticationScriptConfig);
    sp1.setLocalAndOutBoundAuthenticationConfig(localAndOutboundAuthenticationConfig);
    AuthenticationContext context = sequenceHandlerRunner.createAuthenticationContext(sp1);
    SequenceConfig sequenceConfig = sequenceHandlerRunner.getSequenceConfig(context, sp1);
    context.setSequenceConfig(sequenceConfig);
    context.initializeAnalyticsData();
    HttpServletRequest req = sequenceHandlerRunner.createHttpServletRequest();
    HttpServletResponse resp = sequenceHandlerRunner.createHttpServletResponse();
    sequenceHandlerRunner.handle(req, resp, context, "carbon.super");
    if (isValidChoreoDomain) {
        assertNotNull(context.getSelectedAcr());
        assertEquals(context.getSelectedAcr(), "1", "Expected acr value not found");
    } else {
        assertEquals(context.getSelectedAcr(), FAILED, "Expected the request to fail");
    }
}
Also used : AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) FrameworkServiceDataHolder(org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder) LongWaitStatusDAOImpl(org.wso2.carbon.identity.application.authentication.framework.dao.impl.LongWaitStatusDAOImpl) HttpServletRequest(javax.servlet.http.HttpServletRequest) Field(java.lang.reflect.Field) CacheBackedLongWaitStatusDAO(org.wso2.carbon.identity.application.authentication.framework.dao.impl.CacheBackedLongWaitStatusDAO) LocalAndOutboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig) AuthenticationScriptConfig(org.wso2.carbon.identity.application.common.model.script.AuthenticationScriptConfig) LongWaitStatusStoreService(org.wso2.carbon.identity.application.authentication.framework.store.LongWaitStatusStoreService) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) SequenceConfig(org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig) FunctionsDataHolder(org.wso2.carbon.identity.conditional.auth.functions.common.internal.FunctionsDataHolder) Test(org.testng.annotations.Test) JsSequenceHandlerAbstractTest(org.wso2.carbon.identity.conditional.auth.functions.test.utils.sequence.JsSequenceHandlerAbstractTest)

Aggregations

LongWaitStatusStoreService (org.wso2.carbon.identity.application.authentication.framework.store.LongWaitStatusStoreService)9 CacheBackedLongWaitStatusDAO (org.wso2.carbon.identity.application.authentication.framework.dao.impl.CacheBackedLongWaitStatusDAO)7 LongWaitStatusDAOImpl (org.wso2.carbon.identity.application.authentication.framework.dao.impl.LongWaitStatusDAOImpl)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 SequenceConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig)4 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)4 Test (org.testng.annotations.Test)3 JsFunctionRegistryImpl (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsFunctionRegistryImpl)3 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)3 Field (java.lang.reflect.Field)2 BeforeClass (org.testng.annotations.BeforeClass)2 FrameworkException (org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException)2 FrameworkServiceDataHolder (org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder)2 FunctionsDataHolder (org.wso2.carbon.identity.conditional.auth.functions.common.internal.FunctionsDataHolder)2 JsSequenceHandlerAbstractTest (org.wso2.carbon.identity.conditional.auth.functions.test.utils.sequence.JsSequenceHandlerAbstractTest)2 Gson (com.google.gson.Gson)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 Map (java.util.Map)1