Search in sources :

Example 1 with ViewState

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

the class AbstractCasWebflowConfigurer method createViewState.

@Override
public ViewState createViewState(final Flow flow, final String id, final Expression expression, final BinderConfiguration binder) {
    try {
        if (containsFlowState(flow, id)) {
            LOGGER.debug("Flow [{}] already contains a definition for state id [{}]", flow.getId(), id);
            return (ViewState) flow.getTransitionableState(id);
        }
        final ViewFactory viewFactory = this.flowBuilderServices.getViewFactoryCreator().createViewFactory(expression, this.flowBuilderServices.getExpressionParser(), this.flowBuilderServices.getConversionService(), binder, this.flowBuilderServices.getValidator(), this.flowBuilderServices.getValidationHintResolver());
        final ViewState viewState = new ViewState(flow, id, viewFactory);
        LOGGER.debug("Added view state [{}]", viewState.getId());
        return viewState;
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return null;
}
Also used : ViewFactory(org.springframework.webflow.execution.ViewFactory) ActionExecutingViewFactory(org.springframework.webflow.engine.support.ActionExecutingViewFactory) ViewState(org.springframework.webflow.engine.ViewState)

Example 2 with ViewState

use of org.springframework.webflow.engine.ViewState 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 3 with ViewState

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

the class DefaultWebflowConfigurer method createRememberMeAuthnWebflowConfig.

private void createRememberMeAuthnWebflowConfig(final Flow flow) {
    if (casProperties.getTicket().getTgt().getRememberMe().isEnabled()) {
        createFlowVariable(flow, CasWebflowConstants.VAR_ID_CREDENTIAL, RememberMeUsernamePasswordCredential.class);
        final ViewState state = (ViewState) flow.getState(CasWebflowConstants.STATE_ID_VIEW_LOGIN_FORM);
        final BinderConfiguration cfg = getViewStateBinderConfiguration(state);
        cfg.addBinding(new BinderConfiguration.Binding("rememberMe", null, false));
    } else {
        createFlowVariable(flow, CasWebflowConstants.VAR_ID_CREDENTIAL, UsernamePasswordCredential.class);
    }
}
Also used : ViewState(org.springframework.webflow.engine.ViewState) BinderConfiguration(org.springframework.webflow.engine.builder.BinderConfiguration)

Example 4 with ViewState

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

the class DefaultWebflowConfigurer method createServiceWarningViewState.

private void createServiceWarningViewState(final Flow flow) {
    final ViewState stateWarning = createViewState(flow, CasWebflowConstants.STATE_ID_SHOW_WARNING_VIEW, CasWebflowConstants.VIEW_ID_CONFIRM);
    createTransitionForState(stateWarning, CasWebflowConstants.TRANSITION_ID_SUCCESS, "finalizeWarning");
    final ActionState finalizeWarn = createActionState(flow, "finalizeWarning", createEvaluateAction("serviceWarningAction"));
    createTransitionForState(finalizeWarn, CasWebflowConstants.STATE_ID_REDIRECT, CasWebflowConstants.STATE_ID_REDIRECT);
}
Also used : ViewState(org.springframework.webflow.engine.ViewState) ActionState(org.springframework.webflow.engine.ActionState)

Example 5 with ViewState

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

the class PasswordManagementWebflowConfigurer method configurePasswordReset.

private void configurePasswordReset() {
    final Flow flow = getLoginFlow();
    if (flow != null) {
        final ViewState state = (ViewState) flow.getState(CasWebflowConstants.STATE_ID_VIEW_LOGIN_FORM);
        createTransitionForState(state, CasWebflowConstants.TRANSITION_ID_RESET_PASSWORD, CasWebflowConstants.VIEW_ID_SEND_RESET_PASSWORD_ACCT_INFO);
        final ViewState accountInfo = createViewState(flow, CasWebflowConstants.VIEW_ID_SEND_RESET_PASSWORD_ACCT_INFO, CasWebflowConstants.VIEW_ID_SEND_RESET_PASSWORD_ACCT_INFO);
        createTransitionForState(accountInfo, "findAccount", SEND_PASSWORD_RESET_INSTRUCTIONS_ACTION);
        final ActionState sendInst = createActionState(flow, SEND_PASSWORD_RESET_INSTRUCTIONS_ACTION, createEvaluateAction("sendPasswordResetInstructionsAction"));
        createTransitionForState(sendInst, CasWebflowConstants.TRANSITION_ID_SUCCESS, CasWebflowConstants.VIEW_ID_SENT_RESET_PASSWORD_ACCT_INFO);
        createTransitionForState(sendInst, CasWebflowConstants.TRANSITION_ID_ERROR, accountInfo.getId());
        createViewState(flow, CasWebflowConstants.VIEW_ID_SENT_RESET_PASSWORD_ACCT_INFO, CasWebflowConstants.VIEW_ID_SENT_RESET_PASSWORD_ACCT_INFO);
        final Flow pswdFlow = buildFlow("classpath:/webflow/pswdreset/pswdreset-webflow.xml", FLOW_ID_PASSWORD_RESET);
        createViewState(pswdFlow, "passwordResetErrorView", "casResetPasswordErrorView");
        createEndState(pswdFlow, "casPasswordUpdateSuccess", "casPasswordUpdateSuccessView");
        configure(pswdFlow, CAS_MUST_CHANGE_PASS_VIEW);
        loginFlowDefinitionRegistry.registerFlowDefinition(pswdFlow);
    }
}
Also used : ViewState(org.springframework.webflow.engine.ViewState) ActionState(org.springframework.webflow.engine.ActionState) Flow(org.springframework.webflow.engine.Flow)

Aggregations

ViewState (org.springframework.webflow.engine.ViewState)20 Flow (org.springframework.webflow.engine.Flow)13 lombok.val (lombok.val)9 Test (org.junit.jupiter.api.Test)7 ActionState (org.springframework.webflow.engine.ActionState)7 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)6 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)6 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)6 MockServletContext (org.springframework.mock.web.MockServletContext)5 Transition (org.springframework.webflow.engine.Transition)4 Action (org.springframework.webflow.execution.Action)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 ActionExecutingViewFactory (org.springframework.webflow.engine.support.ActionExecutingViewFactory)3 ViewFactory (org.springframework.webflow.execution.ViewFactory)3 MockRequestContext (org.springframework.webflow.test.MockRequestContext)3 MockRequestControlContext (org.springframework.webflow.test.MockRequestControlContext)3 Expression (org.springframework.binding.expression.Expression)2 BinderConfiguration (org.springframework.webflow.engine.builder.BinderConfiguration)2 DefaultTargetStateResolver (org.springframework.webflow.engine.support.DefaultTargetStateResolver)2 MockFlowExecutionContext (org.springframework.webflow.test.MockFlowExecutionContext)2