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;
}
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");
}
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");
}
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());
}
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());
}
}
Aggregations