Search in sources :

Example 1 with DefaultMapping

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;
}
Also used : FluentParserContext(org.springframework.binding.expression.support.FluentParserContext) RuntimeBindingConversionExecutor(org.springframework.binding.convert.service.RuntimeBindingConversionExecutor) ConversionExecutor(org.springframework.binding.convert.ConversionExecutor) Expression(org.springframework.binding.expression.Expression) LiteralExpression(org.springframework.binding.expression.support.LiteralExpression) SpringELExpressionParser(org.springframework.binding.expression.spel.SpringELExpressionParser) ExpressionParser(org.springframework.binding.expression.ExpressionParser) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) DefaultMapping(org.springframework.binding.mapping.impl.DefaultMapping) RuntimeBindingConversionExecutor(org.springframework.binding.convert.service.RuntimeBindingConversionExecutor)

Example 2 with DefaultMapping

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);
}
Also used : DefaultMapper(org.springframework.binding.mapping.impl.DefaultMapper) SubflowAttributeMapper(org.springframework.webflow.engine.SubflowAttributeMapper) GenericSubflowAttributeMapper(org.springframework.webflow.engine.support.GenericSubflowAttributeMapper) Mapper(org.springframework.binding.mapping.Mapper) SubflowAttributeMapper(org.springframework.webflow.engine.SubflowAttributeMapper) GenericSubflowAttributeMapper(org.springframework.webflow.engine.support.GenericSubflowAttributeMapper) ArrayList(java.util.ArrayList) SubflowState(org.springframework.webflow.engine.SubflowState) DefaultMapping(org.springframework.binding.mapping.impl.DefaultMapping) TransitionableState(org.springframework.webflow.engine.TransitionableState) ActionState(org.springframework.webflow.engine.ActionState)

Example 3 with DefaultMapping

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);
    });
}
Also used : Mapper(org.springframework.binding.mapping.Mapper) SubflowAttributeMapper(org.springframework.webflow.engine.SubflowAttributeMapper) SubflowAttributeMapper(org.springframework.webflow.engine.SubflowAttributeMapper) TransitionSet(org.springframework.webflow.engine.TransitionSet) ArrayList(java.util.ArrayList) SubflowState(org.springframework.webflow.engine.SubflowState) DefaultMapping(org.springframework.binding.mapping.impl.DefaultMapping) TransitionableState(org.springframework.webflow.engine.TransitionableState)

Example 4 with DefaultMapping

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;
}
Also used : lombok.val(lombok.val) FluentParserContext(org.springframework.binding.expression.support.FluentParserContext) DefaultMapping(org.springframework.binding.mapping.impl.DefaultMapping) RuntimeBindingConversionExecutor(org.springframework.binding.convert.service.RuntimeBindingConversionExecutor)

Example 5 with DefaultMapping

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);
    });
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) SubflowState(org.springframework.webflow.engine.SubflowState) Ordered(org.springframework.core.Ordered) Arrays(java.util.Arrays) Getter(lombok.Getter) DefaultMapping(org.springframework.binding.mapping.impl.DefaultMapping) FlowBuilderServices(org.springframework.webflow.engine.builder.support.FlowBuilderServices) TransitionableState(org.springframework.webflow.engine.TransitionableState) ArrayList(java.util.ArrayList) CasWebflowConstants(org.apereo.cas.web.flow.CasWebflowConstants) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) LinkedHashSet(java.util.LinkedHashSet) FlowDefinitionRegistry(org.springframework.webflow.definition.registry.FlowDefinitionRegistry) Collection(java.util.Collection) lombok.val(lombok.val) Flow(org.springframework.webflow.engine.Flow) Transition(org.springframework.webflow.engine.Transition) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) WebUtils(org.apereo.cas.web.support.WebUtils) DefaultTargetStateResolver(org.springframework.webflow.engine.support.DefaultTargetStateResolver) StringUtils(org.springframework.util.StringUtils) Transition(org.springframework.webflow.engine.Transition) DefaultTargetStateResolver(org.springframework.webflow.engine.support.DefaultTargetStateResolver) DefaultMapping(org.springframework.binding.mapping.impl.DefaultMapping) TransitionableState(org.springframework.webflow.engine.TransitionableState) Flow(org.springframework.webflow.engine.Flow)

Aggregations

DefaultMapping (org.springframework.binding.mapping.impl.DefaultMapping)5 ArrayList (java.util.ArrayList)3 SubflowState (org.springframework.webflow.engine.SubflowState)3 TransitionableState (org.springframework.webflow.engine.TransitionableState)3 lombok.val (lombok.val)2 RuntimeBindingConversionExecutor (org.springframework.binding.convert.service.RuntimeBindingConversionExecutor)2 FluentParserContext (org.springframework.binding.expression.support.FluentParserContext)2 Mapper (org.springframework.binding.mapping.Mapper)2 SubflowAttributeMapper (org.springframework.webflow.engine.SubflowAttributeMapper)2 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Getter (lombok.Getter)1 Slf4j (lombok.extern.slf4j.Slf4j)1 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)1 CasWebflowConstants (org.apereo.cas.web.flow.CasWebflowConstants)1