Search in sources :

Example 26 with Transition

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

the class AbstractCasWebflowConfigurer method createTransitionForState.

/**
 * Add transition to action state.
 *
 * @param state           the action state
 * @param criteriaOutcome the criteria outcome
 * @param targetState     the target state
 * @param removeExisting  the remove existing
 * @return the transition
 */
public Transition createTransitionForState(final TransitionableState state, final String criteriaOutcome, final String targetState, final boolean removeExisting) {
    try {
        if (removeExisting) {
            final Transition success = (Transition) state.getTransition(criteriaOutcome);
            if (success != null) {
                state.getTransitionSet().remove(success);
            }
        }
        final Transition transition = createTransition(criteriaOutcome, targetState);
        state.getTransitionSet().add(transition);
        LOGGER.debug("Added transition [{}] to the state [{}]", transition.getId(), state.getId());
        return transition;
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return null;
}
Also used : Transition(org.springframework.webflow.engine.Transition)

Example 27 with Transition

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

the class AbstractCasWebflowConfigurer method createTransition.

@Override
public Transition createTransition(final Expression criteriaOutcomeExpression, final String targetState) {
    final TransitionCriteria criteria;
    if (criteriaOutcomeExpression.toString().equals(WildcardTransitionCriteria.WILDCARD_EVENT_ID)) {
        criteria = WildcardTransitionCriteria.INSTANCE;
    } else {
        criteria = new DefaultTransitionCriteria(criteriaOutcomeExpression);
    }
    final DefaultTargetStateResolver resolver = new DefaultTargetStateResolver(targetState);
    final Transition t = new Transition(criteria, resolver);
    return t;
}
Also used : DefaultTransitionCriteria(org.springframework.webflow.engine.support.DefaultTransitionCriteria) Transition(org.springframework.webflow.engine.Transition) DefaultTargetStateResolver(org.springframework.webflow.engine.support.DefaultTargetStateResolver) DefaultTransitionCriteria(org.springframework.webflow.engine.support.DefaultTransitionCriteria) WildcardTransitionCriteria(org.springframework.webflow.engine.WildcardTransitionCriteria) TransitionCriteria(org.springframework.webflow.engine.TransitionCriteria)

Example 28 with Transition

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

the class MultifactorAuthenticationUtilsTests method verifyResolveBySingleAttribute.

@Test
public void verifyResolveBySingleAttribute() {
    val applicationContext = new StaticApplicationContext();
    applicationContext.refresh();
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    ApplicationContextProvider.holdApplicationContext(applicationContext);
    val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
    assertTrue(MultifactorAuthenticationUtils.getMultifactorAuthenticationProviderFromApplicationContext(provider.getId()).isPresent());
    val targetResolver = new DefaultTargetStateResolver(TestMultifactorAuthenticationProvider.ID);
    val transition = new Transition(new DefaultTransitionCriteria(new LiteralExpression(TestMultifactorAuthenticationProvider.ID)), targetResolver);
    context.getRootFlow().getGlobalTransitionSet().add(transition);
    val result = MultifactorAuthenticationUtils.resolveEventViaSingleAttribute(MultifactorAuthenticationTestUtils.getPrincipal("casuser"), List.of("mfa-value1"), MultifactorAuthenticationTestUtils.getRegisteredService(), Optional.of(context), provider, (s, mfaProvider) -> RegexUtils.find("mismatch-.+", s));
    assertNull(result);
}
Also used : lombok.val(lombok.val) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DefaultTransitionCriteria(org.springframework.webflow.engine.support.DefaultTransitionCriteria) LiteralExpression(org.springframework.binding.expression.support.LiteralExpression) Transition(org.springframework.webflow.engine.Transition) DefaultTargetStateResolver(org.springframework.webflow.engine.support.DefaultTargetStateResolver) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 29 with Transition

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

the class MultifactorAuthenticationUtilsTests method verifyMissingTransition.

@Test
public void verifyMissingTransition() {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setCurrentEvent(new Event(this, "currentState"));
    context.setCurrentTransition(new Transition());
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    assertThrows(AuthenticationException.class, () -> MultifactorAuthenticationUtils.validateEventIdForMatchingTransitionInContext("unknown", Optional.of(context), Map.of()));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Transition(org.springframework.webflow.engine.Transition) Event(org.springframework.webflow.execution.Event) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 30 with Transition

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

the class AbstractMultifactorTrustedDeviceWebflowConfigurer method registerMultifactorTrustedAuthentication.

/**
 * Register multifactor trusted authentication.
 *
 * @param registry the registry
 */
protected void registerMultifactorTrustedAuthentication(final FlowDefinitionRegistry registry) {
    validateFlowDefinitionConfiguration();
    LOGGER.trace("Flow definitions found in the registry are [{}]", (Object[]) registry.getFlowDefinitionIds());
    val flowId = Arrays.stream(registry.getFlowDefinitionIds()).findFirst().orElseThrow();
    LOGGER.trace("Processing flow definition [{}]", flowId);
    val flow = (Flow) registry.getFlowDefinition(flowId);
    Assert.notNull(flow, String.format("%s flow cannot be null or undefined", flowId));
    val state = getState(flow, CasWebflowConstants.STATE_ID_INIT_LOGIN_FORM, ActionState.class);
    Assert.notNull(state, String.format("%s state cannot be null or undefined", CasWebflowConstants.STATE_ID_INIT_LOGIN_FORM));
    val transition = (Transition) state.getTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS);
    Assert.notNull(state, String.format("%s transition cannot be null or undefined", CasWebflowConstants.TRANSITION_ID_SUCCESS));
    val targetStateId = transition.getTargetStateId();
    transition.setTargetStateResolver(new DefaultTargetStateResolver(CasWebflowConstants.STATE_ID_VERIFY_TRUSTED_DEVICE));
    val verifyAction = createActionState(flow, CasWebflowConstants.STATE_ID_VERIFY_TRUSTED_DEVICE, CasWebflowConstants.ACTION_ID_MFA_VERIFY_TRUST_ACTION);
    val enableDeviceRegistration = casProperties.getAuthn().getMfa().getTrusted().getCore().isDeviceRegistrationEnabled();
    if (enableDeviceRegistration) {
        LOGGER.trace("Device registration is turned on for multifactor flow [{}]", flowId);
        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);
    createTransitionForState(verifyAction, CasWebflowConstants.TRANSITION_ID_SKIP, targetStateId);
    val submit = getState(flow, CasWebflowConstants.STATE_ID_REAL_SUBMIT, ActionState.class);
    val success = (Transition) submit.getTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS);
    Assert.notNull(state, String.format("%s transition cannot be null or undefined", CasWebflowConstants.TRANSITION_ID_SUCCESS));
    if (enableDeviceRegistration) {
        success.setTargetStateResolver(new DefaultTargetStateResolver(CasWebflowConstants.STATE_ID_PREPARE_REGISTER_TRUSTED_DEVICE));
    } else {
        success.setTargetStateResolver(new DefaultTargetStateResolver(CasWebflowConstants.STATE_ID_REGISTER_TRUSTED_DEVICE));
    }
    createRegisterDeviceView(flow);
    val registerAction = createActionState(flow, CasWebflowConstants.STATE_ID_REGISTER_TRUSTED_DEVICE, CasWebflowConstants.ACTION_ID_MFA_SET_TRUST_ACTION);
    createStateDefaultTransition(registerAction, CasWebflowConstants.STATE_ID_SUCCESS);
    Assert.isTrue(submit.getActionList().size() > 0, "There are no actions defined for " + flowId);
    val act = submit.getActionList().iterator().next();
    val finishMfaTrustedAuth = createActionState(flow, CasWebflowConstants.STATE_ID_FINISH_MFA_TRUSTED_AUTH, act);
    val finishedTransition = createTransition(CasWebflowConstants.TRANSITION_ID_SUCCESS, CasWebflowConstants.STATE_ID_SUCCESS);
    finishMfaTrustedAuth.getTransitionSet().add(finishedTransition);
    createStateDefaultTransition(finishMfaTrustedAuth, CasWebflowConstants.STATE_ID_SUCCESS);
}
Also used : lombok.val(lombok.val) Transition(org.springframework.webflow.engine.Transition) DefaultTargetStateResolver(org.springframework.webflow.engine.support.DefaultTargetStateResolver) Flow(org.springframework.webflow.engine.Flow)

Aggregations

Transition (org.springframework.webflow.engine.Transition)38 lombok.val (lombok.val)29 DefaultTargetStateResolver (org.springframework.webflow.engine.support.DefaultTargetStateResolver)29 DefaultTransitionCriteria (org.springframework.webflow.engine.support.DefaultTransitionCriteria)24 LiteralExpression (org.springframework.binding.expression.support.LiteralExpression)23 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)22 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)22 MockServletContext (org.springframework.mock.web.MockServletContext)22 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)22 MockRequestContext (org.springframework.webflow.test.MockRequestContext)22 Test (org.junit.jupiter.api.Test)17 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)5 ClientInfo (org.apereo.inspektr.common.web.ClientInfo)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Flow (org.springframework.webflow.engine.Flow)4 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)3 ActionState (org.springframework.webflow.engine.ActionState)3 Authentication (org.apereo.cas.authentication.Authentication)2 DefaultRegisteredServiceMultifactorPolicy (org.apereo.cas.services.DefaultRegisteredServiceMultifactorPolicy)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2