Search in sources :

Example 1 with Transition

use of org.springframework.webflow.engine.Transition in project cas by apereo.

the class AbstractCasWebflowConfigurer method createTransitionForState.

/**
     * Add transition to action state.
     *
     * @param state           the action state
     * @param criteriaOutcome the criteria outcome
     * @param targetState     the target state
     * @param removeExisting  the remove existing
     * @return the transition
     */
protected Transition createTransitionForState(final TransitionableState state, final String criteriaOutcome, final String targetState, final boolean removeExisting) {
    try {
        if (removeExisting) {
            final Transition success = (Transition) state.getTransition(criteriaOutcome);
            if (success != null) {
                state.getTransitionSet().remove(success);
            }
        }
        final Transition transition = createTransition(criteriaOutcome, targetState);
        state.getTransitionSet().add(transition);
        LOGGER.debug("Added transition [{}] to the state [{}]", transition.getId(), state.getId());
        return transition;
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return null;
}
Also used : Transition(org.springframework.webflow.engine.Transition)

Example 2 with Transition

use of org.springframework.webflow.engine.Transition in project cas by apereo.

the class AbstractCasWebflowConfigurer method createDecisionState.

@Override
public DecisionState createDecisionState(final Flow flow, final String id, final String testExpression, final String thenStateId, final String elseStateId) {
    if (containsFlowState(flow, id)) {
        LOGGER.debug("Flow [{}] already contains a definition for state id [[{}]]", flow.getId(), id);
        return (DecisionState) flow.getTransitionableState(id);
    }
    final DecisionState decisionState = new DecisionState(flow, id);
    final Expression expression = createExpression(testExpression, Boolean.class);
    final Transition thenTransition = createTransition(expression, thenStateId);
    decisionState.getTransitionSet().add(thenTransition);
    final Transition elseTransition = createTransition("*", elseStateId);
    decisionState.getTransitionSet().add(elseTransition);
    return decisionState;
}
Also used : Expression(org.springframework.binding.expression.Expression) LiteralExpression(org.springframework.binding.expression.support.LiteralExpression) Transition(org.springframework.webflow.engine.Transition) DecisionState(org.springframework.webflow.engine.DecisionState)

Example 3 with Transition

use of org.springframework.webflow.engine.Transition in project cas by apereo.

the class AbstractCasWebflowConfigurer method createStateDefaultTransition.

/**
     * Add a default transition to a given state.
     *
     * @param state       the state to include the default transition
     * @param targetState the id of the destination state to which the flow should transfer
     */
protected void createStateDefaultTransition(final TransitionableState state, final String targetState) {
    if (state == null) {
        LOGGER.debug("Cannot add default transition of [{}] to the given state is null and cannot be found in the flow.", targetState);
        return;
    }
    final Transition transition = createTransition(targetState);
    state.getTransitionSet().add(transition);
}
Also used : Transition(org.springframework.webflow.engine.Transition)

Example 4 with Transition

use of org.springframework.webflow.engine.Transition in project cas by apereo.

the class AbstractMultifactorTrustedDeviceWebflowConfigurer method registerMultifactorTrustedAuthentication.

/**
     * Register multifactor trusted authentication into webflow.
     *
     * @param flowDefinitionRegistry the flow definition registry
     */
protected void registerMultifactorTrustedAuthentication(final FlowDefinitionRegistry flowDefinitionRegistry) {
    if (flowDefinitionRegistry.getFlowDefinitionCount() <= 0) {
        throw new IllegalArgumentException("Flow definition registry has no flow definitions");
    }
    LOGGER.debug("Flow definitions found in the registry are [{}]", (Object[]) flowDefinitionRegistry.getFlowDefinitionIds());
    final String flowId = Arrays.stream(flowDefinitionRegistry.getFlowDefinitionIds()).findFirst().get();
    LOGGER.debug("Processing flow definition [{}]", flowId);
    final Flow flow = (Flow) flowDefinitionRegistry.getFlowDefinition(flowId);
    // Set the verify action
    final ActionState state = (ActionState) flow.getState(CasWebflowConstants.STATE_ID_INIT_LOGIN_FORM);
    final Transition transition = (Transition) state.getTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS);
    final String targetStateId = transition.getTargetStateId();
    transition.setTargetStateResolver(new DefaultTargetStateResolver(CasWebflowConstants.STATE_ID_VERIFY_TRUSTED_DEVICE));
    final ActionState verifyAction = createActionState(flow, CasWebflowConstants.STATE_ID_VERIFY_TRUSTED_DEVICE, createEvaluateAction("mfaVerifyTrustAction"));
    // handle device registration
    if (enableDeviceRegistration) {
        createTransitionForState(verifyAction, CasWebflowConstants.TRANSITION_ID_YES, "finishMfaTrustedAuth");
    } else {
        createTransitionForState(verifyAction, CasWebflowConstants.TRANSITION_ID_YES, CasWebflowConstants.TRANSITION_ID_REAL_SUBMIT);
    }
    createTransitionForState(verifyAction, CasWebflowConstants.TRANSITION_ID_NO, targetStateId);
    createDecisionState(flow, CasWebflowConstants.DECISION_STATE_REQUIRE_REGISTRATION, isDeviceRegistrationRequired(), CasWebflowConstants.VIEW_ID_REGISTER_DEVICE, CasWebflowConstants.TRANSITION_ID_REAL_SUBMIT);
    final ActionState submit = (ActionState) flow.getState(CasWebflowConstants.TRANSITION_ID_REAL_SUBMIT);
    final Transition success = (Transition) submit.getTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS);
    if (enableDeviceRegistration) {
        success.setTargetStateResolver(new DefaultTargetStateResolver(CasWebflowConstants.VIEW_ID_REGISTER_DEVICE));
    } else {
        success.setTargetStateResolver(new DefaultTargetStateResolver(CasWebflowConstants.STATE_ID_REGISTER_TRUSTED_DEVICE));
    }
    final ViewState viewRegister = createViewState(flow, CasWebflowConstants.VIEW_ID_REGISTER_DEVICE, "casMfaRegisterDeviceView");
    viewRegister.getTransitionSet().add(createTransition(CasWebflowConstants.TRANSITION_ID_SUBMIT, CasWebflowConstants.STATE_ID_REGISTER_TRUSTED_DEVICE));
    final ActionState registerAction = createActionState(flow, CasWebflowConstants.STATE_ID_REGISTER_TRUSTED_DEVICE, createEvaluateAction("mfaSetTrustAction"));
    createStateDefaultTransition(registerAction, CasWebflowConstants.STATE_ID_SUCCESS);
    if (submit.getActionList().size() == 0) {
        throw new IllegalArgumentException("There are no actions defined for the final submission event of " + flowId);
    }
    final Action act = submit.getActionList().iterator().next();
    final ActionState finishMfaTrustedAuth = createActionState(flow, "finishMfaTrustedAuth", act);
    finishMfaTrustedAuth.getTransitionSet().add(createTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS, CasWebflowConstants.STATE_ID_SUCCESS));
    createStateDefaultTransition(finishMfaTrustedAuth, CasWebflowConstants.STATE_ID_SUCCESS);
}
Also used : Action(org.springframework.webflow.execution.Action) Transition(org.springframework.webflow.engine.Transition) DefaultTargetStateResolver(org.springframework.webflow.engine.support.DefaultTargetStateResolver) ViewState(org.springframework.webflow.engine.ViewState) ActionState(org.springframework.webflow.engine.ActionState) Flow(org.springframework.webflow.engine.Flow)

Example 5 with Transition

use of org.springframework.webflow.engine.Transition in project cas by apereo.

the class AbstractMultifactorTrustedDeviceWebflowConfigurer method registerMultifactorTrustedAuthentication.

/**
 * Register multifactor trusted authentication into webflow.
 *
 * @param flowDefinitionRegistry the flow definition registry
 */
protected void registerMultifactorTrustedAuthentication(final FlowDefinitionRegistry flowDefinitionRegistry) {
    validateFlowDefinitionConfiguration(flowDefinitionRegistry);
    LOGGER.debug("Flow definitions found in the registry are [{}]", (Object[]) flowDefinitionRegistry.getFlowDefinitionIds());
    final String flowId = Arrays.stream(flowDefinitionRegistry.getFlowDefinitionIds()).findFirst().get();
    LOGGER.debug("Processing flow definition [{}]", flowId);
    final Flow flow = (Flow) flowDefinitionRegistry.getFlowDefinition(flowId);
    // Set the verify action
    final ActionState state = getState(flow, CasWebflowConstants.STATE_ID_INIT_LOGIN_FORM, ActionState.class);
    final Transition transition = (Transition) state.getTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS);
    final String targetStateId = transition.getTargetStateId();
    transition.setTargetStateResolver(new DefaultTargetStateResolver(CasWebflowConstants.STATE_ID_VERIFY_TRUSTED_DEVICE));
    final ActionState verifyAction = createActionState(flow, CasWebflowConstants.STATE_ID_VERIFY_TRUSTED_DEVICE, createEvaluateAction(MFA_VERIFY_TRUST_ACTION_BEAN_ID));
    // handle device registration
    if (enableDeviceRegistration) {
        createTransitionForState(verifyAction, CasWebflowConstants.TRANSITION_ID_YES, CasWebflowConstants.STATE_ID_FINISH_MFA_TRUSTED_AUTH);
    } else {
        createTransitionForState(verifyAction, CasWebflowConstants.TRANSITION_ID_YES, CasWebflowConstants.STATE_ID_REAL_SUBMIT);
    }
    createTransitionForState(verifyAction, CasWebflowConstants.TRANSITION_ID_NO, targetStateId);
    createDecisionState(flow, CasWebflowConstants.DECISION_STATE_REQUIRE_REGISTRATION, isDeviceRegistrationRequired(), CasWebflowConstants.VIEW_ID_REGISTER_DEVICE, CasWebflowConstants.STATE_ID_REAL_SUBMIT);
    final ActionState submit = getState(flow, CasWebflowConstants.STATE_ID_REAL_SUBMIT, ActionState.class);
    final Transition success = (Transition) submit.getTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS);
    if (enableDeviceRegistration) {
        success.setTargetStateResolver(new DefaultTargetStateResolver(CasWebflowConstants.VIEW_ID_REGISTER_DEVICE));
    } else {
        success.setTargetStateResolver(new DefaultTargetStateResolver(CasWebflowConstants.STATE_ID_REGISTER_TRUSTED_DEVICE));
    }
    final ViewState viewRegister = createViewState(flow, CasWebflowConstants.VIEW_ID_REGISTER_DEVICE, "casMfaRegisterDeviceView");
    final Transition viewRegisterTransition = createTransition(CasWebflowConstants.TRANSITION_ID_SUBMIT, CasWebflowConstants.STATE_ID_REGISTER_TRUSTED_DEVICE);
    viewRegister.getTransitionSet().add(viewRegisterTransition);
    final ActionState registerAction = createActionState(flow, CasWebflowConstants.STATE_ID_REGISTER_TRUSTED_DEVICE, createEvaluateAction(MFA_SET_TRUST_ACTION_BEAN_ID));
    createStateDefaultTransition(registerAction, CasWebflowConstants.STATE_ID_SUCCESS);
    if (submit.getActionList().size() == 0) {
        throw new IllegalArgumentException("There are no actions defined for the final submission event of " + flowId);
    }
    final Action act = submit.getActionList().iterator().next();
    final ActionState finishMfaTrustedAuth = createActionState(flow, CasWebflowConstants.STATE_ID_FINISH_MFA_TRUSTED_AUTH, act);
    final Transition finishedTransition = createTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS, CasWebflowConstants.STATE_ID_SUCCESS);
    finishMfaTrustedAuth.getTransitionSet().add(finishedTransition);
    createStateDefaultTransition(finishMfaTrustedAuth, CasWebflowConstants.STATE_ID_SUCCESS);
}
Also used : Action(org.springframework.webflow.execution.Action) Transition(org.springframework.webflow.engine.Transition) DefaultTargetStateResolver(org.springframework.webflow.engine.support.DefaultTargetStateResolver) ViewState(org.springframework.webflow.engine.ViewState) ActionState(org.springframework.webflow.engine.ActionState) Flow(org.springframework.webflow.engine.Flow)

Aggregations

Transition (org.springframework.webflow.engine.Transition)38 lombok.val (lombok.val)29 DefaultTargetStateResolver (org.springframework.webflow.engine.support.DefaultTargetStateResolver)29 DefaultTransitionCriteria (org.springframework.webflow.engine.support.DefaultTransitionCriteria)24 LiteralExpression (org.springframework.binding.expression.support.LiteralExpression)23 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)22 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)22 MockServletContext (org.springframework.mock.web.MockServletContext)22 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)22 MockRequestContext (org.springframework.webflow.test.MockRequestContext)22 Test (org.junit.jupiter.api.Test)17 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)5 ClientInfo (org.apereo.inspektr.common.web.ClientInfo)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Flow (org.springframework.webflow.engine.Flow)4 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)3 ActionState (org.springframework.webflow.engine.ActionState)3 Authentication (org.apereo.cas.authentication.Authentication)2 DefaultRegisteredServiceMultifactorPolicy (org.apereo.cas.services.DefaultRegisteredServiceMultifactorPolicy)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2