Search in sources :

Example 16 with ViewState

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

the class WebAuthnMultifactorWebflowConfigurerTests method verifyCsrfOperation.

@Test
public void verifyCsrfOperation() {
    val webAuthnFlow = (Flow) loginFlowDefinitionRegistry.getFlowDefinition(WebAuthnMultifactorWebflowConfigurer.FLOW_ID_MFA_WEBAUTHN);
    val context = new MockRequestControlContext(webAuthnFlow);
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    WebUtils.putAuthentication(RegisteredServiceTestUtils.getAuthentication(), context);
    WebUtils.putMultifactorAuthenticationProviderIdIntoFlowScope(context, webAuthnMultifactorAuthenticationProvider);
    val registration = (ViewState) webAuthnFlow.getState(CasWebflowConstants.STATE_ID_WEBAUTHN_VIEW_REGISTRATION);
    registration.enter(context);
    assertNotNull(context.getFlowScope().get("_csrf"));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) ViewState(org.springframework.webflow.engine.ViewState) MockRequestControlContext(org.springframework.webflow.test.MockRequestControlContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Flow(org.springframework.webflow.engine.Flow) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 17 with ViewState

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

the class DefaultLoginWebflowConfigurerTests method verifyRenderAction.

@Test
public void verifyRenderAction() {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    assertFalse(casWebflowExecutionPlan.getWebflowConfigurers().isEmpty());
    val cfg = casWebflowExecutionPlan.getWebflowConfigurers().iterator().next();
    assertNotNull(cfg.createRenderAction("ExampleRenderAction"));
    val flow = (Flow) this.loginFlowDefinitionRegistry.getFlowDefinition(CasWebflowConfigurer.FLOW_ID_LOGIN);
    assertNotNull(flow);
    assertNull(cfg.getState(flow, "InvalidStateId", ViewState.class));
    assertNull(cfg.createTransitionForState(null, "BadCriteria", "BadTarget", false, Map.of(), (Action) null));
    assertNull(cfg.createTransitionForState(null, "BadCriteria", "BadTarget", Map.of(), (Action) null));
    assertTrue(cfg.getTransitionExecutionCriteriaChainForTransition(mock(Transition.class)).isEmpty());
    assertNull(cfg.createViewState(null, "ViewState", (ViewFactory) null));
    assertNull(cfg.createViewState(null, "ViewState", (Expression) null, null));
    assertNotNull(cfg.createViewState(flow, CasWebflowConstants.STATE_ID_VIEW_LOGIN_FORM, (ViewFactory) null));
}
Also used : lombok.val(lombok.val) Action(org.springframework.webflow.execution.Action) Expression(org.springframework.binding.expression.Expression) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) ViewFactory(org.springframework.webflow.execution.ViewFactory) Transition(org.springframework.webflow.engine.Transition) ViewState(org.springframework.webflow.engine.ViewState) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Flow(org.springframework.webflow.engine.Flow) Test(org.junit.jupiter.api.Test)

Example 18 with ViewState

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

the class DelegatedAuthenticationWebflowConfigurerTests 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_DELEGATED_AUTHENTICATION_CLIENT_RETRY));
    assertTrue(flow.containsState(CasWebflowConstants.STATE_ID_DELEGATED_AUTHENTICATION));
    val stopState = (ViewState) flow.getState(CasWebflowConstants.STATE_ID_STOP_WEBFLOW);
    val context = new MockRequestControlContext(flow);
    val request = new MockHttpServletRequest();
    request.addParameter("error_description", "fail");
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    context.getFlowScope().put(CasWebflowConstants.ATTRIBUTE_ERROR_ROOT_CAUSE_EXCEPTION, new RuntimeException());
    stopState.enter(context);
    assertTrue(context.getFlowScope().contains("code"));
    assertTrue(context.getFlowScope().contains("description"));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) ViewState(org.springframework.webflow.engine.ViewState) MockRequestControlContext(org.springframework.webflow.test.MockRequestControlContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Flow(org.springframework.webflow.engine.Flow) Test(org.junit.jupiter.api.Test)

Example 19 with ViewState

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

the class AbstractCasWebflowConfigurer method createViewState.

@Override
public ViewState createViewState(final Flow flow, final String id, final ViewFactory viewFactory) {
    try {
        if (containsFlowState(flow, id)) {
            LOGGER.trace("Flow [{}] already contains a definition for state id [{}]", flow.getId(), id);
            return getTransitionableState(flow, id, ViewState.class);
        }
        val viewState = new ViewState(flow, id, viewFactory);
        LOGGER.trace("Added view state [{}]", viewState.getId());
        return viewState;
    } catch (final Exception e) {
        LoggingUtils.error(LOGGER, e);
    }
    return null;
}
Also used : lombok.val(lombok.val) ViewState(org.springframework.webflow.engine.ViewState)

Example 20 with ViewState

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

the class DuoSecurityUniversalPromptMultifactorWebflowConfigurerTests method verifyUniversalPromptFlow.

@Test
public void verifyUniversalPromptFlow() {
    val loginFlow = (Flow) loginFlowDefinitionRegistry.getFlowDefinition(CasWebflowConfigurer.FLOW_ID_LOGIN);
    assertNotNull(loginFlow.getState(CasWebflowConstants.STATE_ID_DUO_UNIVERSAL_PROMPT_VALIDATE_LOGIN));
    assertEquals(CasWebflowConstants.STATE_ID_DUO_UNIVERSAL_PROMPT_VALIDATE_LOGIN, loginFlow.getStartState().getId());
    val registry = getMultifactorFlowDefinitionRegistry();
    val flow = (Flow) registry.getFlowDefinition(getMultifactorEventId());
    val viewState = (ViewState) flow.getState(CasWebflowConstants.STATE_ID_VIEW_LOGIN_FORM_DUO);
    assertTrue(viewState.getEntryActionList().get(0).toString().contains(CasWebflowConstants.ACTION_ID_DUO_UNIVERSAL_PROMPT_PREPARE_LOGIN));
}
Also used : lombok.val(lombok.val) ViewState(org.springframework.webflow.engine.ViewState) Flow(org.springframework.webflow.engine.Flow) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ViewState (org.springframework.webflow.engine.ViewState)20 Flow (org.springframework.webflow.engine.Flow)13 lombok.val (lombok.val)9 Test (org.junit.jupiter.api.Test)7 ActionState (org.springframework.webflow.engine.ActionState)7 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)6 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)6 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)6 MockServletContext (org.springframework.mock.web.MockServletContext)5 Transition (org.springframework.webflow.engine.Transition)4 Action (org.springframework.webflow.execution.Action)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 ActionExecutingViewFactory (org.springframework.webflow.engine.support.ActionExecutingViewFactory)3 ViewFactory (org.springframework.webflow.execution.ViewFactory)3 MockRequestContext (org.springframework.webflow.test.MockRequestContext)3 MockRequestControlContext (org.springframework.webflow.test.MockRequestControlContext)3 Expression (org.springframework.binding.expression.Expression)2 BinderConfiguration (org.springframework.webflow.engine.builder.BinderConfiguration)2 DefaultTargetStateResolver (org.springframework.webflow.engine.support.DefaultTargetStateResolver)2 MockFlowExecutionContext (org.springframework.webflow.test.MockFlowExecutionContext)2