Search in sources :

Example 11 with EventFactorySupport

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

the class CreateTicketGrantingTicketAction method doExecute.

@Override
public Event doExecute(final RequestContext context) throws Exception {
    val service = WebUtils.getService(context);
    val registeredService = WebUtils.getRegisteredService(context);
    val authenticationResultBuilder = WebUtils.getAuthenticationResultBuilder(context);
    LOGGER.trace("Finalizing authentication transactions and issuing ticket-granting ticket");
    val authenticationResult = configurationContext.getAuthenticationSystemSupport().finalizeAllAuthenticationTransactions(authenticationResultBuilder, service);
    LOGGER.trace("Finalizing authentication event...");
    val authentication = buildFinalAuthentication(authenticationResult);
    val ticketGrantingTicket = determineTicketGrantingTicketId(context);
    LOGGER.debug("Creating ticket-granting ticket, potentially based on [{}]", ticketGrantingTicket);
    val tgt = createOrUpdateTicketGrantingTicket(authenticationResult, authentication, ticketGrantingTicket);
    if (registeredService != null && registeredService.getAccessStrategy() != null) {
        WebUtils.putUnauthorizedRedirectUrlIntoFlowScope(context, registeredService.getAccessStrategy().getUnauthorizedRedirectUrl());
    }
    WebUtils.putTicketGrantingTicketInScopes(context, tgt);
    WebUtils.putAuthenticationResult(authenticationResult, context);
    WebUtils.putAuthentication(tgt.getAuthentication(), context);
    LOGGER.trace("Calculating authentication warning messages...");
    val warnings = calculateAuthenticationWarningMessages(tgt, context.getMessageContext());
    if (!warnings.isEmpty()) {
        val attributes = new LocalAttributeMap<Object>(CasWebflowConstants.ATTRIBUTE_ID_AUTHENTICATION_WARNINGS, warnings);
        return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_SUCCESS_WITH_WARNINGS, attributes);
    }
    return success();
}
Also used : lombok.val(lombok.val) LocalAttributeMap(org.springframework.webflow.core.collection.LocalAttributeMap) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

Example 12 with EventFactorySupport

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

the class FinishLogoutAction method doInternalExecute.

@Override
protected Event doInternalExecute(final HttpServletRequest request, final HttpServletResponse response, final RequestContext context) {
    val logoutRedirect = WebUtils.getLogoutRedirectUrl(context, String.class);
    if (StringUtils.isNotBlank(logoutRedirect)) {
        return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_REDIRECT);
    }
    val logoutPostUrl = WebUtils.getLogoutPostUrl(context);
    val logoutPostData = WebUtils.getLogoutPostData(context);
    if (StringUtils.isNotBlank(logoutPostUrl) && logoutPostData != null) {
        val flowScope = context.getFlowScope();
        flowScope.put("originalUrl", logoutPostUrl);
        flowScope.put("parameters", logoutPostData);
        return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_POST);
    }
    return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_FINISH);
}
Also used : lombok.val(lombok.val) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

Example 13 with EventFactorySupport

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

the class FrontChannelLogoutAction method doInternalExecute.

@Override
protected Event doInternalExecute(final HttpServletRequest request, final HttpServletResponse response, final RequestContext context) {
    val logoutRequests = WebUtils.getLogoutRequests(context);
    if (logoutRequests == null || logoutRequests.isEmpty()) {
        return getFinishLogoutEvent();
    }
    if (casProperties.getSlo().isDisabled()) {
        LOGGER.debug("Single logout callbacks are disabled");
        return getFinishLogoutEvent();
    }
    val logoutUrls = new HashMap<SingleLogoutRequestContext, LogoutHttpMessage>();
    logoutRequests.stream().filter(r -> r.getStatus() == LogoutRequestStatus.NOT_ATTEMPTED).forEach(r -> {
        LOGGER.debug("Using logout url [{}] for front-channel logout requests", r.getLogoutUrl().toExternalForm());
        logoutExecutionPlan.getSingleLogoutServiceMessageHandlers().stream().sorted(Comparator.comparing(SingleLogoutServiceMessageHandler::getOrder)).filter(handler -> handler.supports(r.getExecutionRequest(), r.getService())).forEach(handler -> {
            val logoutMessage = handler.createSingleLogoutMessage(r);
            LOGGER.debug("Front-channel logout message to send to [{}] is [{}]", r.getLogoutUrl(), logoutMessage);
            val msg = new LogoutHttpMessage(r.getLogoutUrl(), logoutMessage.getPayload(), true);
            logoutUrls.put(r, msg);
            r.setStatus(LogoutRequestStatus.SUCCESS);
            r.getService().setLoggedOutAlready(true);
        });
    });
    if (!logoutUrls.isEmpty()) {
        WebUtils.putLogoutUrls(context, logoutUrls);
        return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_PROPAGATE);
    }
    return getFinishLogoutEvent();
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) ArgumentExtractor(org.apereo.cas.web.support.ArgumentExtractor) lombok.val(lombok.val) HttpServletResponse(javax.servlet.http.HttpServletResponse) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) LogoutRequestStatus(org.apereo.cas.logout.LogoutRequestStatus) SingleLogoutServiceMessageHandler(org.apereo.cas.logout.slo.SingleLogoutServiceMessageHandler) HashMap(java.util.HashMap) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) RequestContext(org.springframework.webflow.execution.RequestContext) LogoutExecutionPlan(org.apereo.cas.logout.LogoutExecutionPlan) Slf4j(lombok.extern.slf4j.Slf4j) HttpServletRequest(javax.servlet.http.HttpServletRequest) CasCookieBuilder(org.apereo.cas.web.cookie.CasCookieBuilder) CasWebflowConstants(org.apereo.cas.web.flow.CasWebflowConstants) LogoutHttpMessage(org.apereo.cas.logout.LogoutHttpMessage) SingleLogoutRequestContext(org.apereo.cas.logout.slo.SingleLogoutRequestContext) WebUtils(org.apereo.cas.web.support.WebUtils) Comparator(java.util.Comparator) Event(org.springframework.webflow.execution.Event) ServicesManager(org.apereo.cas.services.ServicesManager) HashMap(java.util.HashMap) LogoutHttpMessage(org.apereo.cas.logout.LogoutHttpMessage) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

Example 14 with EventFactorySupport

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

the class ConfirmConsentAction method doExecute.

@Override
public Event doExecute(final RequestContext requestContext) throws Exception {
    val request = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
    val webService = WebUtils.getService(requestContext);
    val service = this.authenticationRequestServiceSelectionStrategies.resolveService(webService);
    val registeredService = getRegisteredServiceForConsent(requestContext, service);
    val authentication = WebUtils.getAuthentication(requestContext);
    val optionValue = Integer.parseInt(request.getParameter("option"));
    val option = ConsentReminderOptions.valueOf(optionValue);
    val reminder = Long.parseLong(request.getParameter("reminder"));
    val reminderTimeUnit = request.getParameter("reminderTimeUnit");
    val unit = ChronoUnit.valueOf(reminderTimeUnit.toUpperCase());
    LOGGER.debug("Storing consent decision for service [{}]", service);
    consentEngine.storeConsentDecision(service, registeredService, authentication, reminder, unit, option);
    return new EventFactorySupport().success(this);
}
Also used : lombok.val(lombok.val) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

Example 15 with EventFactorySupport

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

the class OneTimeTokenAuthenticationWebflowActionTests method verifyAction.

@Test
public void verifyAction() {
    val resolver = mock(CasWebflowEventResolver.class);
    when(resolver.resolveSingle(any())).thenReturn(new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_SUCCESS));
    val action = new OneTimeTokenAuthenticationWebflowAction(resolver);
    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());
    assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, action.doExecute(context).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) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.apereo.cas.util.MockServletContext) 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