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