Search in sources :

Example 26 with EventFactorySupport

use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.

the class SpnegoKnownClientSystemsFilterActionTests method ensureRemoteIpShouldNotBeChecked.

@Test
public void ensureRemoteIpShouldNotBeChecked() throws Exception {
    val action = new BaseSpnegoKnownClientSystemsFilterAction(RegexUtils.createPattern("^192\\.158\\..+"), StringUtils.EMPTY, 0);
    val ctx = new MockRequestContext();
    val req = new MockHttpServletRequest();
    req.setRemoteAddr("193.158.5.781");
    val extCtx = new ServletExternalContext(new MockServletContext(), req, new MockHttpServletResponse());
    ctx.setExternalContext(extCtx);
    val ev = action.doExecute(ctx);
    assertNotEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Test(org.junit.jupiter.api.Test)

Example 27 with EventFactorySupport

use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.

the class AuthenticationExceptionHandlerAction method doExecute.

@Override
protected Event doExecute(final RequestContext requestContext) {
    val currentEvent = requestContext.getCurrentEvent();
    LOGGER.debug("Located current event [{}]", currentEvent);
    val error = currentEvent.getAttributes().get(CasWebflowConstants.TRANSITION_ID_ERROR, Exception.class);
    if (error != null) {
        LOGGER.debug("Located error attribute [{}] with message [{}] from the current event", error.getClass(), error.getMessage());
        val event = handle(error, requestContext);
        LOGGER.debug("Final event id resolved from the error is [{}]", event);
        return new EventFactorySupport().event(this, event, currentEvent.getAttributes());
    }
    return error();
}
Also used : lombok.val(lombok.val) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

Example 28 with EventFactorySupport

use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.

the class AcceptableUsagePolicyVerifyAction method verify.

/**
 * Verify whether the policy is accepted.
 *
 * @param context the context
 * @return {@link CasWebflowConstants#TRANSITION_ID_AUP_ACCEPTED} if policy is
 * accepted. {@link CasWebflowConstants#TRANSITION_ID_AUP_MUST_ACCEPT} otherwise.
 */
private Event verify(final RequestContext context) {
    val authentication = WebUtils.getAuthentication(context);
    val res = ObjectUtils.defaultIfNull(repository.verify(context), AcceptableUsagePolicyStatus.skipped(authentication.getPrincipal()));
    WebUtils.putPrincipal(context, res.getPrincipal());
    WebUtils.putAcceptableUsagePolicyStatusIntoFlowScope(context, res);
    val eventFactorySupport = new EventFactorySupport();
    val registeredService = WebUtils.getRegisteredService(context);
    if (registeredService != null) {
        val service = WebUtils.getService(context);
        val audit = AuditableContext.builder().service(service).authentication(authentication).registeredService(registeredService).build();
        val accessResult = registeredServiceAccessStrategyEnforcer.execute(audit);
        accessResult.throwExceptionIfNeeded();
        val aupEnabled = registeredService.getAcceptableUsagePolicy() != null && registeredService.getAcceptableUsagePolicy().isEnabled();
        if (!aupEnabled) {
            return eventFactorySupport.event(this, CasWebflowConstants.TRANSITION_ID_AUP_ACCEPTED);
        }
    }
    switch(res.getStatus()) {
        case TRUE:
            return eventFactorySupport.event(this, CasWebflowConstants.TRANSITION_ID_AUP_ACCEPTED);
        case FALSE:
            return eventFactorySupport.event(this, CasWebflowConstants.TRANSITION_ID_AUP_MUST_ACCEPT);
        case UNDEFINED:
        default:
            return eventFactorySupport.event(this, CasWebflowConstants.TRANSITION_ID_SKIP);
    }
}
Also used : lombok.val(lombok.val) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

Example 29 with EventFactorySupport

use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.

the class AcceptableUsagePolicyVerifyServiceAction method verify.

/**
 * Verify whether the policy is accepted.
 *
 * @param context the context
 * @return success if policy is accepted. {@link CasWebflowConstants#TRANSITION_ID_AUP_MUST_ACCEPT} otherwise.
 */
private Event verify(final RequestContext context) {
    val registeredService = WebUtils.getRegisteredService(context);
    if (registeredService != null) {
        val authentication = WebUtils.getAuthentication(context);
        val service = WebUtils.getService(context);
        val eventFactorySupport = new EventFactorySupport();
        val audit = AuditableContext.builder().service(service).authentication(authentication).registeredService(registeredService).build();
        val accessResult = registeredServiceAccessStrategyEnforcer.execute(audit);
        accessResult.throwExceptionIfNeeded();
        val aupEnabled = registeredService.getAcceptableUsagePolicy() != null && registeredService.getAcceptableUsagePolicy().isEnabled();
        val res = ObjectUtils.defaultIfNull(aupEnabled ? repository.verify(context) : null, AcceptableUsagePolicyStatus.skipped(authentication.getPrincipal()));
        if (res.isDenied()) {
            return eventFactorySupport.event(this, CasWebflowConstants.TRANSITION_ID_AUP_MUST_ACCEPT);
        }
    }
    return null;
}
Also used : lombok.val(lombok.val) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

Example 30 with EventFactorySupport

use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.

the class SelectiveMultifactorAuthenticationProviderWebflowEventResolverTests method verifyOperation.

@Test
public void verifyOperation() {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val service = RegisteredServiceTestUtils.getRegisteredService();
    servicesManager.save(service);
    WebUtils.putRegisteredService(context, service);
    WebUtils.putAuthentication(RegisteredServiceTestUtils.getAuthentication(), context);
    WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService());
    val targetResolver = new DefaultTargetStateResolver(TestMultifactorAuthenticationProvider.ID);
    val transition = new Transition(new DefaultTransitionCriteria(new LiteralExpression(TestMultifactorAuthenticationProvider.ID)), targetResolver);
    context.getRootFlow().getGlobalTransitionSet().add(transition);
    val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
    val resolvedEvents = CollectionUtils.wrapHashSet(new EventFactorySupport().event(this, provider.getId()));
    WebUtils.putResolvedEventsAsAttribute(context, resolvedEvents);
    val result = selectiveAuthenticationProviderWebflowEventResolver.resolve(context);
    assertNotNull(result);
    assertNotNull(WebUtils.getResolvedMultifactorAuthenticationProviders(context));
    assertEquals(provider.getId(), result.iterator().next().getId());
}
Also used : lombok.val(lombok.val) 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) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Test(org.junit.jupiter.api.Test)

Aggregations

EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)78 lombok.val (lombok.val)61 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)26 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)26 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)26 MockServletContext (org.springframework.mock.web.MockServletContext)25 MockRequestContext (org.springframework.webflow.test.MockRequestContext)23 Test (org.junit.jupiter.api.Test)21 Event (org.springframework.webflow.execution.Event)12 Test (org.junit.Test)7 LocalAttributeMap (org.springframework.webflow.core.collection.LocalAttributeMap)7 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 HashMap (java.util.HashMap)4 Authentication (org.apereo.cas.authentication.Authentication)4 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 WebUtils (org.apereo.cas.web.support.WebUtils)3 LiteralExpression (org.springframework.binding.expression.support.LiteralExpression)3 MessageContext (org.springframework.binding.message.MessageContext)3 Transition (org.springframework.webflow.engine.Transition)3