use of org.springframework.webflow.engine.SubflowState in project cas by apereo.
the class AbstractCasWebflowConfigurer method registerMultifactorProviderAuthenticationWebflow.
/**
* Register multifactor provider authentication webflow.
*
* @param flow the flow
* @param subflowId the subflow id
* @param registry the registry
*/
protected void registerMultifactorProviderAuthenticationWebflow(final Flow flow, final String subflowId, final FlowDefinitionRegistry registry) {
final SubflowState subflowState = createSubflowState(flow, subflowId, subflowId);
final ActionState actionState = (ActionState) flow.getState(CasWebflowConstants.TRANSITION_ID_REAL_SUBMIT);
final String targetStateId = actionState.getTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS).getTargetStateId();
final List<DefaultMapping> mappings = new ArrayList<>();
final Mapper inputMapper = createMapperToSubflowState(mappings);
final SubflowAttributeMapper subflowMapper = createSubflowAttributeMapper(inputMapper, null);
subflowState.setAttributeMapper(subflowMapper);
subflowState.getTransitionSet().add(createTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS, targetStateId));
LOGGER.debug("Retrieved action state [{}]", actionState.getId());
createTransitionForState(actionState, subflowId, subflowId);
registerFlowDefinitionIntoLoginFlowRegistry(registry);
final TransitionableState state = flow.getTransitionableState(CasWebflowConstants.TRANSITION_ID_INITIAL_AUTHN_REQUEST_VALIDATION_CHECK);
createTransitionForState(state, subflowId, subflowId);
}
use of org.springframework.webflow.engine.SubflowState in project cas by apereo.
the class AbstractCasMultifactorWebflowConfigurer method registerMultifactorProviderAuthenticationWebflow.
/**
* Register multifactor provider authentication webflow.
*
* @param flow the flow
* @param subflowId the subflow id
* @param mfaProviderFlowRegistry the registry
*/
protected void registerMultifactorProviderAuthenticationWebflow(final Flow flow, final String subflowId, final FlowDefinitionRegistry mfaProviderFlowRegistry) {
final SubflowState subflowState = createSubflowState(flow, subflowId, subflowId);
final Collection<String> states = getCandidateStatesForMultifactorAuthentication();
LOGGER.debug("Candidate states for multifactor authentication are [{}]", states);
states.forEach(s -> {
LOGGER.debug("Locating state [{}] to process for multifactor authentication", s);
final TransitionableState actionState = getState(flow, s);
LOGGER.debug("Locating transition id [{}] to process multifactor authentication for state [{}", CasWebflowConstants.TRANSITION_ID_SUCCESS, s);
final String targetSuccessId = actionState.getTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS).getTargetStateId();
LOGGER.debug("Locating transition id [{}] to process multifactor authentication for state [{}", CasWebflowConstants.TRANSITION_ID_SUCCESS_WITH_WARNINGS, s);
final String targetWarningsId = actionState.getTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS_WITH_WARNINGS).getTargetStateId();
final List<DefaultMapping> mappings = new ArrayList<>();
final Mapper inputMapper = createMapperToSubflowState(mappings);
final SubflowAttributeMapper subflowMapper = createSubflowAttributeMapper(inputMapper, null);
subflowState.setAttributeMapper(subflowMapper);
LOGGER.debug("Creating transitions to subflow state [{}]", subflowState.getId());
final TransitionSet transitionSet = subflowState.getTransitionSet();
transitionSet.add(createTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS, targetSuccessId));
transitionSet.add(createTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS_WITH_WARNINGS, targetWarningsId));
LOGGER.debug("Creating transition [{}] fpr state [{}]", subflowId, actionState.getId());
createTransitionForState(actionState, subflowId, subflowId);
registerMultifactorFlowDefinitionIntoLoginFlowRegistry(mfaProviderFlowRegistry);
augmentMultifactorProviderFlowRegistry(mfaProviderFlowRegistry);
final TransitionableState state = getTransitionableState(flow, CasWebflowConstants.STATE_ID_INITIAL_AUTHN_REQUEST_VALIDATION_CHECK);
createTransitionForState(state, subflowId, subflowId);
});
}
use of org.springframework.webflow.engine.SubflowState in project cas by apereo.
the class BaseMultifactorWebflowConfigurerTests method verifyOperation.
@Test
public void verifyOperation() {
val registry = getMultifactorFlowDefinitionRegistry();
assertTrue(registry.containsFlowDefinition(getMultifactorEventId()));
val flow = (Flow) registry.getFlowDefinition(getMultifactorEventId());
assertTrue(flow.containsState(CasWebflowConstants.STATE_ID_MFA_CHECK_BYPASS));
assertTrue(flow.containsState(CasWebflowConstants.STATE_ID_MFA_CHECK_AVAILABLE));
assertTrue(flow.containsState(CasWebflowConstants.STATE_ID_MFA_FAILURE));
val loginFlow = (Flow) loginFlowDefinitionRegistry.getFlowDefinition(CasWebflowConfigurer.FLOW_ID_LOGIN);
assertTrue(loginFlow.getState(getMultifactorEventId()) instanceof SubflowState);
}
use of org.springframework.webflow.engine.SubflowState 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.SubflowState in project cas by apereo.
the class AbstractCasMultifactorWebflowConfigurer method registerMultifactorProviderAuthenticationWebflow.
@Override
public void registerMultifactorProviderAuthenticationWebflow(final Flow flow, final String subflowId, final String providerId) {
multifactorAuthenticationFlowDefinitionRegistries.forEach(registry -> {
if (!registry.containsFlowDefinition(subflowId)) {
LOGGER.error("Could not locate flow id [{}]", subflowId);
return;
}
if (flow == null) {
LOGGER.error("Unable to locate parent flow definition to register provider [{}]", providerId);
return;
}
val mfaFlow = (Flow) registry.getFlowDefinition(subflowId);
mfaFlow.getStartActionList().add(requestContext -> {
WebUtils.createCredential(requestContext);
return null;
});
mfaFlow.getStartActionList().add(createSetAction("flowScope.".concat(CasWebflowConstants.VAR_ID_MFA_PROVIDER_ID), StringUtils.quote(providerId)));
val initStartState = (TransitionableState) mfaFlow.getStartState();
val transition = (Transition) initStartState.getTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS);
val targetStateId = transition.getTargetStateId();
transition.setTargetStateResolver(new DefaultTargetStateResolver(CasWebflowConstants.STATE_ID_MFA_CHECK_BYPASS));
registerMultifactorProviderBypassAction(mfaFlow);
registerMultifactorProviderAvailableAction(mfaFlow, targetStateId);
registerMultifactorProviderFailureAction(flow, mfaFlow);
val subflowState = createSubflowState(flow, subflowId, subflowId);
val subflowMappings = Stream.of(CasWebflowConstants.ATTRIBUTE_SERVICE, CasWebflowConstants.ATTRIBUTE_REGISTERED_SERVICE).map(attr -> new DefaultMapping(createExpression("flowScope." + attr), createExpression(attr))).collect(Collectors.toList());
subflowMappings.add(new DefaultMapping(createExpression("flowScope." + CasWebflowConstants.VAR_ID_CREDENTIAL), createExpression("parent" + StringUtils.capitalize(CasWebflowConstants.VAR_ID_CREDENTIAL))));
multifactorAuthenticationFlowCustomizers.forEach(c -> c.getMultifactorWebflowAttributeMappings().forEach(key -> subflowMappings.add(new DefaultMapping(createExpression("flowScope." + key), createExpression(key)))));
val inputMapper = createMapperToSubflowState(subflowMappings);
val subflowMapper = createSubflowAttributeMapper(inputMapper, null);
subflowState.setAttributeMapper(subflowMapper);
val flowMappings = Stream.of(CasWebflowConstants.ATTRIBUTE_SERVICE, CasWebflowConstants.ATTRIBUTE_REGISTERED_SERVICE).map(attr -> new DefaultMapping(createExpression(attr), createExpression("flowScope." + attr))).collect(Collectors.toList());
flowMappings.add(new DefaultMapping(createExpression("parent" + StringUtils.capitalize(CasWebflowConstants.VAR_ID_CREDENTIAL)), createExpression("flowScope.parent" + StringUtils.capitalize(CasWebflowConstants.VAR_ID_CREDENTIAL))));
multifactorAuthenticationFlowCustomizers.forEach(c -> c.getMultifactorWebflowAttributeMappings().forEach(key -> flowMappings.add(new DefaultMapping(createExpression(key), createExpression("flowScope." + key)))));
val flowInputMapper = createMapperToSubflowState(flowMappings);
mfaFlow.setInputMapper(flowInputMapper);
val states = getCandidateStatesForMultifactorAuthentication();
registerMultifactorAuthenticationSubflowWithStates(flow, subflowState, states);
registerMultifactorFlowDefinitionIntoLoginFlowRegistry();
augmentMultifactorProviderFlowRegistry();
LOGGER.trace("Registering the [{}] flow into the flow [{}]", subflowId, flow.getId());
val startState = flow.getTransitionableState(flow.getStartState().getId());
createTransitionForState(startState, subflowId, subflowId, true);
val initState = getState(flow, CasWebflowConstants.STATE_ID_INITIAL_AUTHN_REQUEST_VALIDATION_CHECK);
createTransitionForState(initState, subflowId, subflowId, true);
});
}
Aggregations