use of org.springframework.binding.mapping.impl.DefaultMapping in project cas by apereo.
the class AbstractCasWebflowConfigurer method createMappingToSubflowState.
/**
* Create mapping to subflow state.
*
* @param name the name
* @param value the value
* @param required the required
* @param type the type
* @return the default mapping
*/
protected DefaultMapping createMappingToSubflowState(final String name, final String value, final boolean required, final Class type) {
final ExpressionParser parser = this.flowBuilderServices.getExpressionParser();
final Expression source = parser.parseExpression(value, new FluentParserContext());
final Expression target = parser.parseExpression(name, new FluentParserContext());
final DefaultMapping mapping = new DefaultMapping(source, target);
mapping.setRequired(required);
final ConversionExecutor typeConverter = new RuntimeBindingConversionExecutor(type, this.flowBuilderServices.getConversionService());
mapping.setTypeConverter(typeConverter);
return mapping;
}
use of org.springframework.binding.mapping.impl.DefaultMapping 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.binding.mapping.impl.DefaultMapping 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.binding.mapping.impl.DefaultMapping in project cas by apereo.
the class AbstractCasWebflowConfigurer method createMappingToSubflowState.
/**
* Create mapping to subflow state.
*
* @param name the name
* @param value the value
* @param required the required
* @param type the type
* @return the default mapping
*/
public DefaultMapping createMappingToSubflowState(final String name, final String value, final boolean required, final Class type) {
val parser = this.flowBuilderServices.getExpressionParser();
val source = parser.parseExpression(value, new FluentParserContext());
val target = parser.parseExpression(name, new FluentParserContext());
val mapping = new DefaultMapping(source, target);
mapping.setRequired(required);
val typeConverter = new RuntimeBindingConversionExecutor(type, this.flowBuilderServices.getConversionService());
mapping.setTypeConverter(typeConverter);
return mapping;
}
use of org.springframework.binding.mapping.impl.DefaultMapping 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