Search in sources :

Example 1 with Flow

use of org.springframework.webflow.engine.Flow in project cas by apereo.

the class AbstractCasWebflowConfigurer method createFlowVariable.

/**
     * Create flow variable flow variable.
     *
     * @param flow the flow
     * @param id   the id
     * @param type the type
     * @return the flow variable
     */
protected FlowVariable createFlowVariable(final Flow flow, final String id, final Class type) {
    final Optional<FlowVariable> opt = Arrays.stream(flow.getVariables()).filter(v -> v.getName().equalsIgnoreCase(id)).findFirst();
    if (opt.isPresent()) {
        return opt.get();
    }
    final FlowVariable flowVar = new FlowVariable(id, new BeanFactoryVariableValueFactory(type, applicationContext.getAutowireCapableBeanFactory()));
    flow.addVariable(flowVar);
    return flowVar;
}
Also used : CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) ReflectivePropertyAccessor(org.springframework.expression.spel.support.ReflectivePropertyAccessor) Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ViewFactory(org.springframework.webflow.execution.ViewFactory) DefaultTransitionCriteria(org.springframework.webflow.engine.support.DefaultTransitionCriteria) DefaultMapping(org.springframework.binding.mapping.impl.DefaultMapping) FlowBuilderServices(org.springframework.webflow.engine.builder.support.FlowBuilderServices) DecisionState(org.springframework.webflow.engine.DecisionState) TransitionableState(org.springframework.webflow.engine.TransitionableState) RuntimeBindingConversionExecutor(org.springframework.binding.convert.service.RuntimeBindingConversionExecutor) ConversionExecutor(org.springframework.binding.convert.ConversionExecutor) Map(java.util.Map) DefaultMapper(org.springframework.binding.mapping.impl.DefaultMapper) ScopeSearchingPropertyAccessor(org.springframework.webflow.expression.spel.ScopeSearchingPropertyAccessor) FlowDefinitionRegistry(org.springframework.webflow.definition.registry.FlowDefinitionRegistry) FlowVariable(org.springframework.webflow.engine.FlowVariable) Expression(org.springframework.binding.expression.Expression) WildcardTransitionCriteria(org.springframework.webflow.engine.WildcardTransitionCriteria) BeanFactoryVariableValueFactory(org.springframework.webflow.engine.support.BeanFactoryVariableValueFactory) Action(org.springframework.webflow.execution.Action) FlowVariablePropertyAccessor(org.springframework.webflow.expression.spel.FlowVariablePropertyAccessor) SpringELExpressionParser(org.springframework.binding.expression.spel.SpringELExpressionParser) TransitionCriteria(org.springframework.webflow.engine.TransitionCriteria) FlowDefinitionRegistryBuilder(org.springframework.webflow.config.FlowDefinitionRegistryBuilder) SubflowAttributeMapper(org.springframework.webflow.engine.SubflowAttributeMapper) List(java.util.List) EndState(org.springframework.webflow.engine.EndState) ViewState(org.springframework.webflow.engine.ViewState) ExpressionParser(org.springframework.binding.expression.ExpressionParser) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) BeanExpressionContextAccessor(org.springframework.context.expression.BeanExpressionContextAccessor) GenericSubflowAttributeMapper(org.springframework.webflow.engine.support.GenericSubflowAttributeMapper) WebUtils(org.apereo.cas.web.support.WebUtils) DefaultTargetStateResolver(org.springframework.webflow.engine.support.DefaultTargetStateResolver) FluentParserContext(org.springframework.binding.expression.support.FluentParserContext) SubflowState(org.springframework.webflow.engine.SubflowState) ActionState(org.springframework.webflow.engine.ActionState) ParserContext(org.springframework.binding.expression.ParserContext) ExternalRedirectAction(org.springframework.webflow.action.ExternalRedirectAction) ActionExecutingViewFactory(org.springframework.webflow.engine.support.ActionExecutingViewFactory) ArrayList(java.util.ArrayList) LiteralExpression(org.springframework.binding.expression.support.LiteralExpression) Mapper(org.springframework.binding.mapping.Mapper) MapAccessor(org.springframework.context.expression.MapAccessor) ViewFactoryActionAdapter(org.springframework.webflow.action.ViewFactoryActionAdapter) FlowDefinition(org.springframework.webflow.definition.FlowDefinition) ActionPropertyAccessor(org.springframework.webflow.expression.spel.ActionPropertyAccessor) MultifactorAuthenticationProvider(org.apereo.cas.services.MultifactorAuthenticationProvider) MapAdaptablePropertyAccessor(org.springframework.webflow.expression.spel.MapAdaptablePropertyAccessor) Logger(org.slf4j.Logger) EvaluateAction(org.springframework.webflow.action.EvaluateAction) Flow(org.springframework.webflow.engine.Flow) SpelParserConfiguration(org.springframework.expression.spel.SpelParserConfiguration) Field(java.lang.reflect.Field) ApplicationContext(org.springframework.context.ApplicationContext) Transition(org.springframework.webflow.engine.Transition) BeanFactoryPropertyAccessor(org.springframework.webflow.expression.spel.BeanFactoryPropertyAccessor) BinderConfiguration(org.springframework.webflow.engine.builder.BinderConfiguration) EnvironmentAccessor(org.springframework.context.expression.EnvironmentAccessor) ReflectionUtils(org.springframework.util.ReflectionUtils) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) MessageSourcePropertyAccessor(org.springframework.webflow.expression.spel.MessageSourcePropertyAccessor) BeanFactoryVariableValueFactory(org.springframework.webflow.engine.support.BeanFactoryVariableValueFactory) FlowVariable(org.springframework.webflow.engine.FlowVariable)

Example 2 with Flow

use of org.springframework.webflow.engine.Flow 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) {
    if (flowDefinitionRegistry.getFlowDefinitionCount() <= 0) {
        throw new IllegalArgumentException("Flow definition registry has no flow definitions");
    }
    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 = (ActionState) flow.getState(CasWebflowConstants.STATE_ID_INIT_LOGIN_FORM);
    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("mfaVerifyTrustAction"));
    // handle device registration
    if (enableDeviceRegistration) {
        createTransitionForState(verifyAction, CasWebflowConstants.TRANSITION_ID_YES, "finishMfaTrustedAuth");
    } else {
        createTransitionForState(verifyAction, CasWebflowConstants.TRANSITION_ID_YES, CasWebflowConstants.TRANSITION_ID_REAL_SUBMIT);
    }
    createTransitionForState(verifyAction, CasWebflowConstants.TRANSITION_ID_NO, targetStateId);
    createDecisionState(flow, CasWebflowConstants.DECISION_STATE_REQUIRE_REGISTRATION, isDeviceRegistrationRequired(), CasWebflowConstants.VIEW_ID_REGISTER_DEVICE, CasWebflowConstants.TRANSITION_ID_REAL_SUBMIT);
    final ActionState submit = (ActionState) flow.getState(CasWebflowConstants.TRANSITION_ID_REAL_SUBMIT);
    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");
    viewRegister.getTransitionSet().add(createTransition(CasWebflowConstants.TRANSITION_ID_SUBMIT, CasWebflowConstants.STATE_ID_REGISTER_TRUSTED_DEVICE));
    final ActionState registerAction = createActionState(flow, CasWebflowConstants.STATE_ID_REGISTER_TRUSTED_DEVICE, createEvaluateAction("mfaSetTrustAction"));
    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, "finishMfaTrustedAuth", act);
    finishMfaTrustedAuth.getTransitionSet().add(createTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS, CasWebflowConstants.STATE_ID_SUCCESS));
    createStateDefaultTransition(finishMfaTrustedAuth, CasWebflowConstants.STATE_ID_SUCCESS);
}
Also used : Action(org.springframework.webflow.execution.Action) Transition(org.springframework.webflow.engine.Transition) DefaultTargetStateResolver(org.springframework.webflow.engine.support.DefaultTargetStateResolver) ViewState(org.springframework.webflow.engine.ViewState) ActionState(org.springframework.webflow.engine.ActionState) Flow(org.springframework.webflow.engine.Flow)

Example 3 with Flow

use of org.springframework.webflow.engine.Flow in project cas by apereo.

the class ClearWebflowCredentialAction method doExecute.

@Override
protected Event doExecute(final RequestContext requestContext) throws Exception {
    WebUtils.putCredential(requestContext, null);
    final String current = requestContext.getCurrentEvent().getId();
    if (current.equalsIgnoreCase(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE) || current.equalsIgnoreCase(CasWebflowConstants.TRANSITION_ID_ERROR)) {
        LOGGER.debug("Current event signaled a failure. Recreating credentials instance from the context");
        try {
            final Flow flow = (Flow) requestContext.getFlowExecutionContext().getDefinition();
            final FlowVariable var = flow.getVariable(CasWebflowConstants.VAR_ID_CREDENTIAL);
            var.create(requestContext);
        } catch (final Exception e) {
            throw Throwables.propagate(e);
        }
    }
    return null;
}
Also used : Flow(org.springframework.webflow.engine.Flow) FlowVariable(org.springframework.webflow.engine.FlowVariable)

Example 4 with Flow

use of org.springframework.webflow.engine.Flow in project cas by apereo.

the class AcceptableUsagePolicyWebflowConfigurer method doInitialize.

@Override
protected void doInitialize() throws Exception {
    final Flow flow = getLoginFlow();
    if (flow != null) {
        createVerifyActionState(flow);
        createAcceptableUsagePolicyView(flow);
        createSubmitActionState(flow);
        createTransitionStateToAcceptableUsagePolicy(flow);
    }
}
Also used : Flow(org.springframework.webflow.engine.Flow)

Example 5 with Flow

use of org.springframework.webflow.engine.Flow in project cas by apereo.

the class GraphicalUserAuthenticationWebflowConfigurer method doInitialize.

@Override
protected void doInitialize() throws Exception {
    final Flow flow = getLoginFlow();
    if (flow != null) {
        final ActionState state = (ActionState) flow.getState(CasWebflowConstants.STATE_ID_INIT_LOGIN_FORM);
        final Transition transition = (Transition) state.getTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS);
        final String targetStateId = transition.getTargetStateId();
        createTransitionForState(state, TRANSITION_ID_GUA_GET_USERID, STATE_ID_GUA_GET_USERID);
        final ViewState viewState = createViewState(flow, STATE_ID_GUA_GET_USERID, "casGuaGetUserIdView");
        createTransitionForState(viewState, CasWebflowConstants.TRANSITION_ID_SUBMIT, STATE_ID_GUA_DISPLAY_USER_GFX);
        final ViewState viewStateGfx = createViewState(flow, STATE_ID_GUA_DISPLAY_USER_GFX, "casGuaDisplayUserGraphicsView");
        viewStateGfx.getRenderActionList().add(createEvaluateAction("displayUserGraphicsBeforeAuthenticationAction"));
        createTransitionForState(viewStateGfx, CasWebflowConstants.TRANSITION_ID_SUBMIT, STATE_ID_ACCEPT_GUA);
        final ActionState acceptState = createActionState(flow, STATE_ID_ACCEPT_GUA, createEvaluateAction("acceptUserGraphicsForAuthenticationAction"));
        createStateDefaultTransition(acceptState, targetStateId);
    }
}
Also used : Transition(org.springframework.webflow.engine.Transition) ViewState(org.springframework.webflow.engine.ViewState) ActionState(org.springframework.webflow.engine.ActionState) Flow(org.springframework.webflow.engine.Flow)

Aggregations

Flow (org.springframework.webflow.engine.Flow)29 ActionState (org.springframework.webflow.engine.ActionState)17 ViewState (org.springframework.webflow.engine.ViewState)10 Action (org.springframework.webflow.execution.Action)4 DecisionState (org.springframework.webflow.engine.DecisionState)3 Transition (org.springframework.webflow.engine.Transition)3 ArrayList (java.util.ArrayList)2 Optional (java.util.Optional)2 WebUtils (org.apereo.cas.web.support.WebUtils)2 FlowDefinitionRegistry (org.springframework.webflow.definition.registry.FlowDefinitionRegistry)2 FlowVariable (org.springframework.webflow.engine.FlowVariable)2 DefaultTargetStateResolver (org.springframework.webflow.engine.support.DefaultTargetStateResolver)2 Field (java.lang.reflect.Field)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 PostConstruct (javax.annotation.PostConstruct)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)1