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 getTransitionableState(flow, id, ViewState.class);
}
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;
}
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) {
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);
}
use of org.springframework.webflow.engine.ViewState 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.ViewState in project cas by apereo.
the class AccountManagementWebflowConfigurerTests method verifyOperation.
@Test
public void verifyOperation() {
assertFalse(casWebflowExecutionPlan.getWebflowConfigurers().isEmpty());
val flow = (Flow) this.loginFlowDefinitionRegistry.getFlowDefinition(CasWebflowConfigurer.FLOW_ID_LOGIN);
assertNotNull(flow);
assertTrue(flow.containsState(CasWebflowConstants.STATE_ID_VIEW_ACCOUNT_SIGNUP));
assertTrue(flow.containsState(CasWebflowConstants.STATE_ID_SUBMIT_ACCOUNT_REGISTRATION));
assertTrue(flow.containsState(CasWebflowConstants.STATE_ID_SENT_ACCOUNT_SIGNUP_INFO));
assertTrue(flow.containsState(CasWebflowConstants.STATE_ID_ACCOUNT_REGISTRATION_SUBFLOW));
val subflow = (SubflowState) flow.getState(CasWebflowConstants.STATE_ID_ACCOUNT_REGISTRATION_SUBFLOW);
assertNotNull(subflow);
val regFlow = (Flow) loginFlowDefinitionRegistry.getFlowDefinition(AccountManagementWebflowConfigurer.FLOW_ID_ACCOUNT_REGISTRATION);
val context = new MockRequestControlContext(regFlow);
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
val completeState = (ViewState) regFlow.getState(CasWebflowConstants.STATE_ID_COMPLETE_ACCOUNT_REGISTRATION);
completeState.enter(context);
assertNotNull(WebUtils.getPasswordPolicyPattern(context));
assertEquals(2, AccountRegistrationUtils.getAccountRegistrationSecurityQuestionsCount(context));
}
use of org.springframework.webflow.engine.ViewState in project cas by apereo.
the class PrepareMultifactorProviderSelectionActionTests method verifyOperation.
@Test
public void verifyOperation() throws Exception {
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
val flowSession = new MockFlowSession(new Flow(CasWebflowConfigurer.FLOW_ID_LOGIN));
flowSession.setState(new ViewState(flowSession.getDefinitionInternal(), "viewState", mock(ViewFactory.class)));
val exec = new MockFlowExecutionContext(flowSession);
val context = new MockRequestContext(exec);
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
val chain = new DefaultChainingMultifactorAuthenticationProvider(new DefaultMultifactorAuthenticationFailureModeEvaluator(casProperties));
val provider = new TestMultifactorAuthenticationProvider();
provider.setBypassEvaluator(new DefaultChainingMultifactorAuthenticationBypassProvider());
chain.addMultifactorAuthenticationProvider(provider);
val attributes = new LocalAttributeMap(RegisteredService.class.getName(), RegisteredServiceTestUtils.getRegisteredService());
attributes.put(MultifactorAuthenticationProvider.class.getName(), chain);
val event = new EventFactorySupport().event(this, ChainingMultifactorAuthenticationProvider.DEFAULT_IDENTIFIER, attributes);
context.setCurrentEvent(event);
assertNull(action.execute(context));
assertNotNull(WebUtils.getSelectableMultifactorAuthenticationProviders(context));
}
Aggregations