Search in sources :

Example 11 with JsAuthenticationContext

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

the class KillSessionFunction method execute.

/**
 * This method will contain the implementation of execute action to kill session.
 *
 * @param context AuthenticationContext passed from Javascript
 * @param map     parameter map
 * @return boolean value indicating the success or failure state of process
 */
@Override
public boolean execute(JsAuthenticationContext context, Map<String, String> map) {
    String sessionId = map.get(SessionValidationConstants.TERMINATION_SESSION_ID);
    SessionManagementService sessionManagementService = new SessionManagementService();
    if (log.isDebugEnabled()) {
        log.debug("Session with session id :" + sessionId + " is requested to kill");
    }
    if (StringUtils.isEmpty(sessionId)) {
        return false;
    }
    sessionManagementService.removeSession(sessionId);
    return true;
}
Also used : SessionManagementService(org.wso2.carbon.identity.application.authentication.framework.services.SessionManagementService)

Example 12 with JsAuthenticationContext

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

the class JsAuthenticationContextTest method testRemoteAddition.

@Test
public void testRemoteAddition() throws ScriptException {
    AuthenticatedUser authenticatedUser = new AuthenticatedUser();
    AuthenticationContext authenticationContext = new AuthenticationContext();
    setupAuthContextWithStepData(authenticationContext, authenticatedUser);
    JsAuthenticationContext jsAuthenticationContext = new JsAuthenticationContext(authenticationContext);
    Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE);
    bindings.put("context", jsAuthenticationContext);
    scriptEngine.eval("context.steps[1].subject.remoteClaims['testClaim']='testValue'");
    ClaimMapping claimMapping = ClaimMapping.build("testClaim", "testClaim", "", false);
    String claimCreatedByJs = authenticatedUser.getUserAttributes().get(claimMapping);
    assertEquals(claimCreatedByJs, "testValue");
}
Also used : ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) Bindings(javax.script.Bindings) Test(org.testng.annotations.Test)

Example 13 with JsAuthenticationContext

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

the class JsAuthenticationContextTest method testGetServiceProviderFromWrappedContext.

@Test
public void testGetServiceProviderFromWrappedContext() throws Exception {
    AuthenticationContext authenticationContext = new AuthenticationContext();
    authenticationContext.setServiceProviderName(SERVICE_PROVIDER_NAME);
    JsAuthenticationContext jsAuthenticationContext = new JsAuthenticationContext(authenticationContext);
    Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE);
    bindings.put("context", jsAuthenticationContext);
    Object result = scriptEngine.eval("context.serviceProviderName");
    assertNotNull(result);
    assertEquals(result, SERVICE_PROVIDER_NAME, "Service Provider name set in AuthenticationContext is not " + "accessible from JSAuthenticationContext");
}
Also used : AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) Bindings(javax.script.Bindings) Test(org.testng.annotations.Test)

Example 14 with JsAuthenticationContext

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

the class JsAuthenticationContextTest method testGetLastLoginFailedUserFromWrappedContext.

@Test
public void testGetLastLoginFailedUserFromWrappedContext() throws Exception {
    AuthenticatedUser lastAttemptedUser = new AuthenticatedUser();
    lastAttemptedUser.setUserName(LAST_ATTEMPTED_USER_USERNAME);
    lastAttemptedUser.setTenantDomain(LAST_ATTEMPTED_USER_TENANT_DOMAIN);
    lastAttemptedUser.setUserStoreDomain(LAST_ATTEMPTED_USER_USERSTORE_DOMAIN);
    AuthenticationContext authenticationContext = new AuthenticationContext();
    authenticationContext.setProperty(FrameworkConstants.JSAttributes.JS_LAST_LOGIN_FAILED_USER, lastAttemptedUser);
    JsAuthenticationContext jsAuthenticationContext = new JsAuthenticationContext(authenticationContext);
    Bindings bindings = scriptEngine.getBindings(ScriptContext.GLOBAL_SCOPE);
    bindings.put("context", jsAuthenticationContext);
    Object result = scriptEngine.eval("context.lastLoginFailedUser");
    assertNotNull(result);
    assertTrue(result instanceof JsAuthenticatedUser);
    String username = (String) scriptEngine.eval("context.lastLoginFailedUser.username");
    assertEquals(username, LAST_ATTEMPTED_USER_USERNAME);
    String tenantDomain = (String) scriptEngine.eval("context.lastLoginFailedUser.tenantDomain");
    assertEquals(tenantDomain, LAST_ATTEMPTED_USER_TENANT_DOMAIN);
    String userStoreDomain = (String) scriptEngine.eval("context.lastLoginFailedUser.userStoreDomain");
    assertEquals(userStoreDomain, LAST_ATTEMPTED_USER_USERSTORE_DOMAIN.toUpperCase());
}
Also used : AuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser) Bindings(javax.script.Bindings) Test(org.testng.annotations.Test)

Example 15 with JsAuthenticationContext

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

the class GraphBasedSequenceHandler method executeFunction.

private void executeFunction(String outcomeName, DynamicDecisionNode dynamicDecisionNode, AuthenticationContext context) {
    SerializableJsFunction fn = dynamicDecisionNode.getFunctionMap().get(outcomeName);
    FrameworkServiceDataHolder dataHolder = FrameworkServiceDataHolder.getInstance();
    JsGraphBuilderFactory jsGraphBuilderFactory = dataHolder.getJsGraphBuilderFactory();
    JsGraphBuilder graphBuilder = jsGraphBuilderFactory.createBuilder(context, context.getSequenceConfig().getAuthenticationGraph().getStepMap(), dynamicDecisionNode);
    JsGraphBuilder.JsBasedEvaluator jsBasedEvaluator = graphBuilder.new JsBasedEvaluator(fn);
    jsBasedEvaluator.evaluate(context, (jsConsumer) -> jsConsumer.call(null, new JsAuthenticationContext(context)));
    if (dynamicDecisionNode.getDefaultEdge() == null) {
        dynamicDecisionNode.setDefaultEdge(new EndStep());
    }
}
Also used : JsGraphBuilderFactory(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilderFactory) JsAuthenticationContext(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext) JsGraphBuilder(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilder) FrameworkServiceDataHolder(org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder) EndStep(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.EndStep) SerializableJsFunction(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.SerializableJsFunction)

Aggregations

JsAuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext)10 AuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext)10 Test (org.testng.annotations.Test)9 Bindings (javax.script.Bindings)6 AuthenticatedUser (org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)6 JsFunctionRegistryImpl (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsFunctionRegistryImpl)5 AuthHistory (org.wso2.carbon.identity.application.authentication.framework.context.AuthHistory)5 FrameworkException (org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException)4 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)4 JsFunctionRegistry (org.wso2.carbon.identity.application.authentication.framework.JsFunctionRegistry)3 JsGraphBuilder (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilder)3 JsGraphBuilderFactory (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilderFactory)3 SerializableJsFunction (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.SerializableJsFunction)3 FrameworkServiceDataHolder (org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder)3 IOException (java.io.IOException)2 Map (java.util.Map)2 EndStep (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.EndStep)2 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1