Search in sources :

Example 1 with EndStep

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

the class GraphBasedSequenceHandler method executeFunction.

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

Example 2 with EndStep

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

the class GraphBasedSequenceHandler method gotoToNextNode.

private void gotoToNextNode(AuthenticationContext context, SequenceConfig sequenceConfig, AuthGraphNode currentNode) {
    AuthGraphNode nextNode = null;
    if (currentNode instanceof StepConfigGraphNode) {
        nextNode = ((StepConfigGraphNode) currentNode).getNext();
    }
    if (nextNode == null) {
        if (log.isDebugEnabled()) {
            log.debug("No Next node found for the current graph node : " + currentNode.getName() + ", Service Provider: " + context.getServiceProviderName() + " . Ending the authentication flow.");
        }
        nextNode = new EndStep();
    }
    context.setProperty(FrameworkConstants.JSAttributes.PROP_CURRENT_NODE, nextNode);
}
Also used : StepConfigGraphNode(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.StepConfigGraphNode) EndStep(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.EndStep) AuthGraphNode(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.AuthGraphNode)

Example 3 with EndStep

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

the class GraphBasedSequenceHandler method modifyCurrentNodeAsFirstStep.

private void modifyCurrentNodeAsFirstStep(AuthenticationContext context) {
    context.removeProperty(BACK_TO_FIRST_STEP);
    if (context.getProperty(PROP_CURRENT_NODE) != null) {
        // Identifier first should be the first step. Other steps will be determine dynamically.
        int size = context.getSequenceConfig().getStepMap().size();
        for (int i = 2; i <= size; i++) {
            context.getSequenceConfig().getStepMap().remove(i);
        }
        context.getSequenceConfig().setCompleted(false);
        context.setProperty(PROP_CURRENT_NODE, null);
        AuthGraphNode startNode = context.getSequenceConfig().getAuthenticationGraph().getStartNode();
        if (startNode instanceof StepConfigGraphNode) {
            ((StepConfigGraphNode) startNode).getStepConfig().setCompleted(false);
            ((StepConfigGraphNode) startNode).getStepConfig().setAuthenticatedAutenticator(null);
            ((StepConfigGraphNode) startNode).getStepConfig().setAuthenticatedUser(null);
            if (((StepConfigGraphNode) startNode).getNext() instanceof DynamicDecisionNode) {
                ((DynamicDecisionNode) ((StepConfigGraphNode) startNode).getNext()).setDefaultEdge(new EndStep());
            }
        }
        if (log.isDebugEnabled()) {
            log.debug("Modified current node a parent node which can restart authentication flow" + " from first step.");
        }
    }
}
Also used : DynamicDecisionNode(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.DynamicDecisionNode) StepConfigGraphNode(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.StepConfigGraphNode) EndStep(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.EndStep) AuthGraphNode(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.AuthGraphNode)

Example 4 with EndStep

use of org.wso2.carbon.identity.application.authentication.framework.config.model.graph.EndStep 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)

Example 5 with EndStep

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

the class GraphBasedSequenceHandler method handleDecisionPoint.

private void handleDecisionPoint(HttpServletRequest request, HttpServletResponse response, AuthenticationContext context, SequenceConfig sequenceConfig, DynamicDecisionNode dynamicDecisionNode) throws FrameworkException {
    if (dynamicDecisionNode == null) {
        log.error("Dynamic decision node is null");
        return;
    }
    AuthenticatorFlowStatus flowStatus = (AuthenticatorFlowStatus) request.getAttribute(FrameworkConstants.RequestParams.FLOW_STATUS);
    if (flowStatus != null) {
        switch(flowStatus) {
            case SUCCESS_COMPLETED:
                executeFunction("onSuccess", dynamicDecisionNode, context);
                break;
            case FAIL_COMPLETED:
                if (dynamicDecisionNode.getFunctionMap().get("onFail") != null) {
                    executeFunction("onFail", dynamicDecisionNode, context);
                } else {
                    if (context.isRetrying()) {
                        AuthGraphNode nextNode = dynamicDecisionNode.getParent();
                        context.setProperty(FrameworkConstants.JSAttributes.PROP_CURRENT_NODE, nextNode);
                        return;
                    }
                }
                if (dynamicDecisionNode.getDefaultEdge() instanceof EndStep) {
                    dynamicDecisionNode.setDefaultEdge(new FailNode());
                }
                break;
            case FALLBACK:
                executeFunction("onFallback", dynamicDecisionNode, context);
                break;
            case USER_ABORT:
                executeFunction("onUserAbort", dynamicDecisionNode, context);
                break;
        }
    }
    AuthGraphNode nextNode = dynamicDecisionNode.getDefaultEdge();
    context.setProperty(FrameworkConstants.JSAttributes.PROP_CURRENT_NODE, nextNode);
}
Also used : FailNode(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.FailNode) AuthenticatorFlowStatus(org.wso2.carbon.identity.application.authentication.framework.AuthenticatorFlowStatus) EndStep(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.EndStep) AuthGraphNode(org.wso2.carbon.identity.application.authentication.framework.config.model.graph.AuthGraphNode)

Aggregations

EndStep (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.EndStep)5 AuthGraphNode (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.AuthGraphNode)3 JsGraphBuilder (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilder)2 JsGraphBuilderFactory (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.JsGraphBuilderFactory)2 SerializableJsFunction (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.SerializableJsFunction)2 StepConfigGraphNode (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.StepConfigGraphNode)2 JsAuthenticationContext (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsAuthenticationContext)2 FrameworkServiceDataHolder (org.wso2.carbon.identity.application.authentication.framework.internal.FrameworkServiceDataHolder)2 AuthenticatorFlowStatus (org.wso2.carbon.identity.application.authentication.framework.AuthenticatorFlowStatus)1 DynamicDecisionNode (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.DynamicDecisionNode)1 FailNode (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.FailNode)1 JsWritableParameters (org.wso2.carbon.identity.application.authentication.framework.config.model.graph.js.JsWritableParameters)1