Search in sources :

Example 11 with ViewState

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

the class DuoSecurityPrepareWebLoginFormActionTests method verifyOperation.

@Test
public void verifyOperation() throws Exception {
    val applicationContext = new StaticApplicationContext();
    applicationContext.refresh();
    ApplicationContextProvider.holdApplicationContext(applicationContext);
    ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, MultifactorAuthenticationPrincipalResolver.identical(), UUID.randomUUID().toString());
    val flowSession = new MockFlowSession(new Flow(CasWebflowConfigurer.FLOW_ID_LOGIN));
    flowSession.setState(new ViewState(flowSession.getDefinitionInternal(), "viewState", mock(ViewFactory.class)));
    val exec = new MockFlowExecutionContext(flowSession);
    val context = new MockRequestContext(exec);
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    WebUtils.putServiceIntoFlowScope(context, CoreAuthenticationTestUtils.getWebApplicationService());
    val authentication = CoreAuthenticationTestUtils.getAuthentication();
    WebUtils.putAuthentication(authentication, context);
    val duoService = mock(DuoSecurityAuthenticationService.class);
    when(duoService.getProperties()).thenReturn(casProperties.getAuthn().getMfa().getDuo().get(0));
    val provider = mock(DuoSecurityMultifactorAuthenticationProvider.class);
    when(provider.getId()).thenReturn(DuoSecurityMultifactorAuthenticationProperties.DEFAULT_IDENTIFIER);
    when(provider.getDuoAuthenticationService()).thenReturn(duoService);
    when(provider.matches(anyString())).thenReturn(Boolean.TRUE);
    WebUtils.putCredential(context, new DuoSecurityCredential(authentication.getPrincipal().getId(), UUID.randomUUID().toString(), provider.getId()));
    WebUtils.putMultifactorAuthenticationProviderIdIntoFlowScope(context, provider);
    TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext, provider);
    val action = new DuoSecurityPrepareWebLoginFormAction();
    val event = action.execute(context);
    assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, event.getId());
}
Also used : lombok.val(lombok.val) MockFlowSession(org.springframework.webflow.test.MockFlowSession) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ViewState(org.springframework.webflow.engine.ViewState) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.apereo.cas.util.MockServletContext) Flow(org.springframework.webflow.engine.Flow) MockFlowExecutionContext(org.springframework.webflow.test.MockFlowExecutionContext) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) DuoSecurityCredential(org.apereo.cas.adaptors.duo.authn.DuoSecurityCredential) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 12 with ViewState

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

the class Pac4jWebflowConfigurer method createStopWebflowViewState.

private void createStopWebflowViewState(final Flow flow) {
    final ViewState state = createViewState(flow, DelegatedClientAuthenticationAction.STOP_WEBFLOW, DelegatedClientAuthenticationAction.VIEW_ID_STOP_WEBFLOW);
    state.getEntryActionList().add(new AbstractAction() {

        @Override
        protected Event doExecute(final RequestContext requestContext) throws Exception {
            final HttpServletRequest request = WebUtils.getHttpServletRequest(requestContext);
            final HttpServletResponse response = WebUtils.getHttpServletResponse(requestContext);
            final Optional<ModelAndView> mv = DelegatedClientAuthenticationAction.hasDelegationRequestFailed(request, response.getStatus());
            mv.ifPresent(modelAndView -> modelAndView.getModel().forEach((k, v) -> requestContext.getFlowScope().put(k, v)));
            return null;
        }
    });
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ActionState(org.springframework.webflow.engine.ActionState) FlowDefinitionRegistry(org.springframework.webflow.definition.registry.FlowDefinitionRegistry) AbstractAction(org.springframework.webflow.action.AbstractAction) HttpServletResponse(javax.servlet.http.HttpServletResponse) Flow(org.springframework.webflow.engine.Flow) FlowBuilderServices(org.springframework.webflow.engine.builder.support.FlowBuilderServices) Action(org.springframework.webflow.execution.Action) DecisionState(org.springframework.webflow.engine.DecisionState) RequestContext(org.springframework.webflow.execution.RequestContext) ModelAndView(org.springframework.web.servlet.ModelAndView) HttpServletRequest(javax.servlet.http.HttpServletRequest) ViewState(org.springframework.webflow.engine.ViewState) DelegatedClientAuthenticationAction(org.apereo.cas.support.pac4j.web.flow.DelegatedClientAuthenticationAction) Optional(java.util.Optional) WebUtils(org.apereo.cas.web.support.WebUtils) Event(org.springframework.webflow.execution.Event) Optional(java.util.Optional) Event(org.springframework.webflow.execution.Event) HttpServletResponse(javax.servlet.http.HttpServletResponse) ViewState(org.springframework.webflow.engine.ViewState) RequestContext(org.springframework.webflow.execution.RequestContext) AbstractAction(org.springframework.webflow.action.AbstractAction)

Example 13 with ViewState

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

the class PasswordManagementWebflowConfigurer method configure.

private void configure(final Flow flow, final String id) {
    createFlowVariable(flow, FLOW_VAR_ID_PASSWORD, PasswordChangeBean.class);
    final BinderConfiguration binder = createStateBinderConfiguration(Arrays.asList(FLOW_VAR_ID_PASSWORD, "confirmedPassword"));
    final ViewState viewState = createViewState(flow, id, id, binder);
    createStateModelBinding(viewState, FLOW_VAR_ID_PASSWORD, PasswordChangeBean.class);
    viewState.getEntryActionList().add(this.passwordChangeAction);
    final Transition transition = createTransitionForState(viewState, CasWebflowConstants.TRANSITION_ID_SUBMIT, PASSWORD_CHANGE_ACTION);
    transition.getAttributes().put("bind", Boolean.TRUE);
    transition.getAttributes().put("validate", Boolean.TRUE);
    createStateDefaultTransition(viewState, id);
    final ActionState pswChangeAction = createActionState(flow, PASSWORD_CHANGE_ACTION, createEvaluateAction(PASSWORD_CHANGE_ACTION));
    pswChangeAction.getTransitionSet().add(createTransition(PasswordChangeAction.PASSWORD_UPDATE_SUCCESS, "casPasswordUpdateSuccess"));
    pswChangeAction.getTransitionSet().add(createTransition(CasWebflowConstants.TRANSITION_ID_ERROR, id));
}
Also used : Transition(org.springframework.webflow.engine.Transition) ViewState(org.springframework.webflow.engine.ViewState) ActionState(org.springframework.webflow.engine.ActionState) BinderConfiguration(org.springframework.webflow.engine.builder.BinderConfiguration)

Example 14 with ViewState

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

the class SamlIdPMetadataUIWebflowConfigurer method doInitialize.

@Override
protected void doInitialize() {
    final Flow flow = getLoginFlow();
    if (flow != null) {
        final ViewState state = getTransitionableState(flow, CasWebflowConstants.STATE_ID_VIEW_LOGIN_FORM, ViewState.class);
        state.getEntryActionList().add(this.samlMetadataUIParserAction);
    }
}
Also used : ViewState(org.springframework.webflow.engine.ViewState) Flow(org.springframework.webflow.engine.Flow)

Example 15 with ViewState

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

the class WSFederationWebflowConfigurer method doInitialize.

@Override
protected void doInitialize() {
    final Flow loginFlow = getLoginFlow();
    if (loginFlow != null) {
        final ViewState state = getTransitionableState(loginFlow, CasWebflowConstants.STATE_ID_VIEW_LOGIN_FORM, ViewState.class);
        state.getEntryActionList().add(this.wsfedAction);
    }
}
Also used : ViewState(org.springframework.webflow.engine.ViewState) Flow(org.springframework.webflow.engine.Flow)

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