Search in sources :

Example 86 with ServiceProvider

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.

the class GraphBasedSequenceHandlerAcrTest method testHandleIncorrectFunctionJavascriptAcr.

@Test(expectedExceptions = FrameworkException.class)
public void testHandleIncorrectFunctionJavascriptAcr() throws Exception {
    ServiceProvider sp1 = getTestServiceProvider("incorrect-function-js-sp-1.xml");
    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);
}
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) Test(org.testng.annotations.Test)

Example 87 with ServiceProvider

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.

the class GraphBasedSequenceHandlerClaimsTest method testHandleClaimHandling.

public void testHandleClaimHandling() throws Exception {
    ServiceProvider sp1 = getTestServiceProvider("js-sp-5-claim.xml");
    AuthenticationContext context = getAuthenticationContext(sp1);
    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);
    Assert.assertEquals(context.getRuntimeClaim("http://wso2.org/custom/claim1"), "value1");
    Assert.assertEquals(context.getRuntimeClaim("http://wso2.org/claims/lastname"), "newLastNameValue");
}
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)

Example 88 with ServiceProvider

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.

the class GraphBasedSequenceHandlerCustomFunctionsTest method testHandleDynamicBoolean.

public void testHandleDynamicBoolean() throws Exception {
    PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
    PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
    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");
}
Also used : JsFunctionRegistry(org.wso2.carbon.identity.application.authentication.framework.JsFunctionRegistry) 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)

Example 89 with ServiceProvider

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.

the class GraphBasedSequenceHandlerCustomFunctionsTest method testHandleDynamicJavascriptSerialization.

@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");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JsFunctionRegistry(org.wso2.carbon.identity.application.authentication.framework.JsFunctionRegistry) 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) 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 90 with ServiceProvider

use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.

the class GraphBasedSequenceHandlerExceptionRetryTest method testExceptionRetry.

public void testExceptionRetry() throws Exception {
    JsFunctionRegistryImpl jsFunctionRegistrar = new JsFunctionRegistryImpl();
    FrameworkServiceDataHolder.getInstance().setJsFunctionRegistry(jsFunctionRegistrar);
    LongWaitStatusDAOImpl daoImpl = new LongWaitStatusDAOImpl();
    CacheBackedLongWaitStatusDAO cacheBackedDao = new CacheBackedLongWaitStatusDAO(daoImpl);
    FrameworkServiceDataHolder.getInstance().getAuthenticators().add(new FailingMockAuthenticator("FailingMockAuthenticator"));
    FrameworkServiceDataHolder.getInstance().setLongWaitStatusStoreService(new LongWaitStatusStoreService(cacheBackedDao, 5000));
    jsFunctionRegistrar.register(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER, "hasAnyOfTheRoles", (BiFunction<JsAuthenticatedUser, List<String>, Boolean>) this::hasAnyOfTheRolesFunction);
    ServiceProvider sp1 = getTestServiceProvider("js-sp-exception-retry.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);
    Integer currentAttempts = (Integer) context.getProperties().get(CONTEXT_ATTRIBUTE_NAME_CURRENT_FAIL_TRIES);
    Assert.assertNotNull(currentAttempts);
    Assert.assertEquals(currentAttempts.intValue(), 2);
}
Also used : AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) JsFunctionRegistryImpl(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsFunctionRegistryImpl) HttpServletResponse(javax.servlet.http.HttpServletResponse) LongWaitStatusDAOImpl(org.wso2.carbon.identity.application.authentication.framework.dao.impl.LongWaitStatusDAOImpl) HttpServletRequest(javax.servlet.http.HttpServletRequest) CacheBackedLongWaitStatusDAO(org.wso2.carbon.identity.application.authentication.framework.dao.impl.CacheBackedLongWaitStatusDAO) BiFunction(java.util.function.BiFunction) 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)

Aggregations

ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)222 Test (org.testng.annotations.Test)120 ServiceProvider (org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider)96 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)85 ArrayList (java.util.ArrayList)65 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)58 HashMap (java.util.HashMap)50 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationRequestConfig)49 ApplicationManagementService (org.wso2.carbon.identity.application.mgt.ApplicationManagementService)40 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)35 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)33 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)29 InboundAuthenticationRequestConfig (org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig)26 SequenceConfig (org.wso2.carbon.identity.application.authentication.framework.config.model.SequenceConfig)25 IdentityException (org.wso2.carbon.identity.base.IdentityException)23 Property (org.wso2.carbon.identity.application.common.model.xsd.Property)21 LocalAndOutboundAuthenticationConfig (org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig)20 InboundAuthenticationConfig (org.wso2.carbon.identity.application.common.model.xsd.InboundAuthenticationConfig)20 IdentityOAuth2Exception (org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception)20 Matchers.anyString (org.mockito.Matchers.anyString)19