Search in sources :

Example 1 with EndState

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

the class AbstractCasWebflowConfigurer method createEndState.

@Override
public EndState createEndState(final Flow flow, final String id, final ViewFactory viewFactory) {
    if (containsFlowState(flow, id)) {
        LOGGER.debug("Flow [{}] already contains a definition for state id [{}]", flow.getId(), id);
        return (EndState) flow.getStateInstance(id);
    }
    final EndState endState = new EndState(flow, id);
    if (viewFactory != null) {
        final Action finalResponseAction = new ViewFactoryActionAdapter(viewFactory);
        endState.setFinalResponseAction(finalResponseAction);
        LOGGER.debug("Created end state state [{}] on flow id [{}], backed by view factory [{}]", id, flow.getId(), viewFactory);
    } else {
        LOGGER.debug("Created end state state [{}] on flow id [{}]", id, flow.getId());
    }
    return endState;
}
Also used : Action(org.springframework.webflow.execution.Action) ExternalRedirectAction(org.springframework.webflow.action.ExternalRedirectAction) EvaluateAction(org.springframework.webflow.action.EvaluateAction) ViewFactoryActionAdapter(org.springframework.webflow.action.ViewFactoryActionAdapter) EndState(org.springframework.webflow.engine.EndState)

Example 2 with EndState

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

the class DefaultLoginWebflowConfigurer method createHeaderEndState.

/**
 * Create header end state.
 *
 * @param flow the flow
 */
protected void createHeaderEndState(final Flow flow) {
    final EndState endState = createEndState(flow, CasWebflowConstants.STATE_ID_HEADER_VIEW);
    endState.setFinalResponseAction(createEvaluateAction("injectResponseHeadersAction"));
}
Also used : EndState(org.springframework.webflow.engine.EndState)

Example 3 with EndState

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

the class SpringWebflowEndpoint method getStateDetails.

private static Map<String, Object> getStateDetails(final Flow flowDefinition, final String st) {
    val state = (State) flowDefinition.getState(st);
    val stateMap = new LinkedHashMap<String, Object>();
    if (!state.getAttributes().asMap().isEmpty()) {
        stateMap.put("attributes", CollectionUtils.wrap(state.getAttributes()));
    }
    if (StringUtils.isNotBlank(state.getCaption())) {
        stateMap.put("caption", state.getCaption());
    }
    var acts = StreamSupport.stream(state.getEntryActionList().spliterator(), false).map(SpringWebflowEndpoint::convertActionToString).collect(Collectors.toList());
    if (!acts.isEmpty()) {
        stateMap.put("entryActions", acts);
    }
    if (state instanceof ActionState) {
        acts = StreamSupport.stream(((ActionState) state).getActionList().spliterator(), false).map(SpringWebflowEndpoint::convertActionToString).collect(Collectors.toList());
        if (!acts.isEmpty()) {
            stateMap.put("actionList", acts);
        }
    }
    if (state instanceof EndState) {
        stateMap.put("isEndState", Boolean.TRUE);
    }
    if (state.isViewState()) {
        val viewState = (ViewState) state;
        stateMap.put("isViewState", state.isViewState());
        stateMap.put("isRedirect", viewState.getRedirect());
        acts = StreamSupport.stream(state.getEntryActionList().spliterator(), false).map(Object::toString).collect(Collectors.toList());
        if (!acts.isEmpty()) {
            stateMap.put("renderActions", viewState.getRenderActionList());
        }
        acts = Arrays.stream(viewState.getVariables()).map(variable -> variable.getName() + " -> " + variable.getValueFactory().toString()).collect(Collectors.toList());
        if (!acts.isEmpty()) {
            stateMap.put("viewVariables", acts);
        }
        val field = ReflectionUtils.findField(viewState.getViewFactory().getClass(), "viewId");
        if (field != null) {
            ReflectionUtils.makeAccessible(field);
            val exp = (Expression) ReflectionUtils.getField(field, viewState.getViewFactory());
            stateMap.put("viewId", StringUtils.defaultIfBlank(Objects.requireNonNull(exp).getExpressionString(), exp.getValue(null).toString()));
        } else if (viewState.getViewFactory() instanceof ActionExecutingViewFactory) {
            val factory = (ActionExecutingViewFactory) viewState.getViewFactory();
            if (factory.getAction() instanceof ExternalRedirectAction) {
                val redirect = (ExternalRedirectAction) factory.getAction();
                val uri = ReflectionUtils.findField(redirect.getClass(), "resourceUri");
                ReflectionUtils.makeAccessible(Objects.requireNonNull(uri));
                val exp = (Expression) ReflectionUtils.getField(uri, redirect);
                stateMap.put("viewId", "externalRedirect -> #{" + Objects.requireNonNull(exp).getExpressionString() + '}');
            } else {
                stateMap.put("viewId", factory.getAction().toString());
            }
        } else {
            LOGGER.info("Field viewId cannot be located on view state [{}]", state);
        }
    }
    if (state instanceof TransitionableState) {
        val stDef = (TransitionableState) state;
        acts = StreamSupport.stream(stDef.getExitActionList().spliterator(), false).map(Object::toString).collect(Collectors.toList());
        if (!acts.isEmpty()) {
            stateMap.put("exitActions", acts);
        }
        acts = Arrays.stream(stDef.getTransitions()).map(tr -> tr.getId() + " -> " + tr.getTargetStateId()).collect(Collectors.toList());
        if (!acts.isEmpty()) {
            stateMap.put("transitions", acts);
        }
    }
    return stateMap;
}
Also used : lombok.val(lombok.val) ViewState(org.springframework.webflow.engine.ViewState) TransitionableState(org.springframework.webflow.engine.TransitionableState) ExternalRedirectAction(org.springframework.webflow.action.ExternalRedirectAction) LinkedHashMap(java.util.LinkedHashMap) Expression(org.springframework.binding.expression.Expression) ActionState(org.springframework.webflow.engine.ActionState) TransitionableState(org.springframework.webflow.engine.TransitionableState) State(org.springframework.webflow.engine.State) EndState(org.springframework.webflow.engine.EndState) ViewState(org.springframework.webflow.engine.ViewState) ActionExecutingViewFactory(org.springframework.webflow.engine.support.ActionExecutingViewFactory) ActionState(org.springframework.webflow.engine.ActionState) EndState(org.springframework.webflow.engine.EndState)

Example 4 with EndState

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

the class DefaultLoginWebflowConfigurerTests method verifyWebflowConfigError.

@Test
public void verifyWebflowConfigError() {
    val flow = (Flow) this.loginFlowDefinitionRegistry.getFlowDefinition(CasWebflowConfigurer.FLOW_ID_LOGIN);
    val stopState = (EndState) flow.getState(CasWebflowConstants.STATE_ID_VIEW_WEBFLOW_CONFIG_ERROR);
    val context = new MockRequestControlContext(flow);
    val request = new MockHttpServletRequest();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    context.getFlashScope().put(CasWebflowConstants.ATTRIBUTE_ERROR_ROOT_CAUSE_EXCEPTION, new RuntimeException());
    assertDoesNotThrow(new Executable() {

        @Override
        public void execute() throws Throwable {
            stopState.enter(context);
        }
    });
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Executable(org.junit.jupiter.api.function.Executable) EndState(org.springframework.webflow.engine.EndState) MockRequestControlContext(org.springframework.webflow.test.MockRequestControlContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Flow(org.springframework.webflow.engine.Flow) Test(org.junit.jupiter.api.Test)

Example 5 with EndState

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

the class DefaultWebflowConfigurer method createGenericLoginSuccessEndState.

private void createGenericLoginSuccessEndState(final Flow flow) {
    final EndState state = createEndState(flow, CasWebflowConstants.STATE_ID_VIEW_GENERIC_LOGIN_SUCCESS, CasWebflowConstants.VIEW_ID_GENERIC_SUCCESS);
    state.getEntryActionList().add(createEvaluateAction("genericSuccessViewAction"));
}
Also used : EndState(org.springframework.webflow.engine.EndState)

Aggregations

EndState (org.springframework.webflow.engine.EndState)6 lombok.val (lombok.val)3 ExternalRedirectAction (org.springframework.webflow.action.ExternalRedirectAction)2 ViewFactoryActionAdapter (org.springframework.webflow.action.ViewFactoryActionAdapter)2 LinkedHashMap (java.util.LinkedHashMap)1 Test (org.junit.jupiter.api.Test)1 Executable (org.junit.jupiter.api.function.Executable)1 Expression (org.springframework.binding.expression.Expression)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 MockServletContext (org.springframework.mock.web.MockServletContext)1 EvaluateAction (org.springframework.webflow.action.EvaluateAction)1 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)1 ActionState (org.springframework.webflow.engine.ActionState)1 Flow (org.springframework.webflow.engine.Flow)1 State (org.springframework.webflow.engine.State)1 TransitionableState (org.springframework.webflow.engine.TransitionableState)1 ViewState (org.springframework.webflow.engine.ViewState)1 ActionExecutingViewFactory (org.springframework.webflow.engine.support.ActionExecutingViewFactory)1 Action (org.springframework.webflow.execution.Action)1