Search in sources :

Example 51 with EventFactorySupport

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

the class SendForgotUsernameInstructionsAction method getErrorEvent.

/**
 * Locate and return the error event.
 *
 * @param code           the error code
 * @param defaultMessage the default message
 * @param requestContext the request context
 * @return the event
 */
protected Event getErrorEvent(final String code, final String defaultMessage, final RequestContext requestContext) {
    WebUtils.addErrorMessageToContext(requestContext, "screen.pm.forgotusername." + code, defaultMessage);
    LOGGER.error(defaultMessage);
    return new EventFactorySupport().event(this, CasWebflowConstants.VIEW_ID_ERROR);
}
Also used : EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

Example 52 with EventFactorySupport

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

the class WebAuthnAuthenticationWebflowEventResolverTests method verifyOperation.

@Test
public void verifyOperation() {
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    val context = mock(RequestContext.class);
    when(context.getRequestScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getConversationScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getRequestParameters()).thenReturn(new MockParameterMap());
    when(context.getFlowScope()).thenReturn(new LocalAttributeMap<>());
    when(context.getMessageContext()).thenReturn(mock(MessageContext.class));
    when(context.getExternalContext()).thenReturn(new ServletExternalContext(new MockServletContext(), request, response));
    RequestContextHolder.setRequestContext(context);
    ExternalContextHolder.setExternalContext(context.getExternalContext());
    WebUtils.putCredential(context, RegisteredServiceTestUtils.getCredentialsWithDifferentUsernameAndPassword("casuser", "123456"));
    val event = webAuthnAuthenticationWebflowEventResolver.resolveSingle(context);
    assertEquals(CasWebflowConstants.TRANSITION_ID_ERROR, event.getId());
    assertEquals(HttpStatus.UNAUTHORIZED.value(), response.getStatus());
    val support = new EventFactorySupport();
    assertTrue(event.getAttributes().contains(support.getExceptionAttributeName()));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockParameterMap(org.springframework.webflow.test.MockParameterMap) MessageContext(org.springframework.binding.message.MessageContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 53 with EventFactorySupport

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

the class OneTimeTokenAccountCreateRegistrationAction method doExecute.

@Override
protected Event doExecute(final RequestContext requestContext) {
    val principal = resolvePrincipal(WebUtils.getAuthentication(requestContext).getPrincipal());
    val uid = principal.getId();
    val keyAccount = this.repository.create(uid);
    val keyUri = "otpauth://totp/" + this.label + ':' + uid + "?secret=" + keyAccount.getSecretKey() + "&issuer=" + this.issuer;
    val flowScope = requestContext.getFlowScope();
    flowScope.put(FLOW_SCOPE_ATTR_ACCOUNT, keyAccount);
    val qrCodeBase64 = QRUtils.generateQRCode(keyUri, QRUtils.WIDTH_LARGE, QRUtils.WIDTH_LARGE);
    flowScope.put(FLOW_SCOPE_ATTR_QR_IMAGE_BASE64, qrCodeBase64);
    LOGGER.debug("Registration key URI is [{}]", keyUri);
    return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_REGISTER);
}
Also used : lombok.val(lombok.val) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

Example 54 with EventFactorySupport

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

the class RadiusAuthenticationWebflowEventResolver method getAuthenticationFailureErrorEvent.

@Override
protected Event getAuthenticationFailureErrorEvent(final RequestContext context, final Exception exception) {
    if (allowedAuthenticationAttempts <= 0) {
        return super.getAuthenticationFailureErrorEvent(context, exception);
    }
    val attempts = context.getFlowScope().getLong(FLOW_SCOPE_ATTR_TOTAL_AUTHENTICATION_ATTEMPTS, 0L) + 1;
    if (attempts >= allowedAuthenticationAttempts) {
        context.getFlowScope().remove(FLOW_SCOPE_ATTR_TOTAL_AUTHENTICATION_ATTEMPTS);
        return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_CANCEL);
    }
    context.getFlowScope().put(FLOW_SCOPE_ATTR_TOTAL_AUTHENTICATION_ATTEMPTS, attempts + 1);
    return super.getAuthenticationFailureErrorEvent(context, exception);
}
Also used : lombok.val(lombok.val) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

Example 55 with EventFactorySupport

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

the class WsFederationRequestBuilder method buildAuthenticationRequestEvent.

/**
 * Build authentication request event event.
 *
 * @param context the context
 * @return the event
 */
public Event buildAuthenticationRequestEvent(final RequestContext context) {
    val clients = new ArrayList<WsFedClient>(this.configurations.size());
    val request = WebUtils.getHttpServletRequestFromExternalWebflowContext(context);
    val service = (WebApplicationService) context.getFlowScope().get(CasProtocolConstants.PARAMETER_SERVICE);
    configurations.forEach(Unchecked.consumer(cfg -> {
        val c = new WsFedClient();
        c.setName(cfg.getName());
        val id = UUID.randomUUID().toString();
        val rpId = wsFederationHelper.getRelyingPartyIdentifier(service, cfg);
        c.setAuthorizationUrl(cfg.getAuthorizationUrl(rpId, id));
        c.setReplyingPartyId(rpId);
        c.setId(id);
        c.setRedirectUrl(getRelativeRedirectUrlFor(cfg, service, request));
        c.setAutoRedirectType(cfg.getAutoRedirectType());
        clients.add(c);
        if (cfg.getAutoRedirectType() != DelegationAutoRedirectTypes.NONE) {
            WebUtils.putDelegatedAuthenticationProviderPrimary(context, cfg);
        }
    }));
    WebUtils.putWsFederationDelegatedClients(context, clients);
    return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_PROCEED);
}
Also used : lombok.val(lombok.val) WsFederationHelper(org.apereo.cas.support.wsfederation.WsFederationHelper) CasProtocolConstants(org.apereo.cas.CasProtocolConstants) Unchecked(org.jooq.lambda.Unchecked) URIBuilder(org.apache.http.client.utils.URIBuilder) DelegationAutoRedirectTypes(org.apereo.cas.configuration.model.support.delegation.DelegationAutoRedirectTypes) Collection(java.util.Collection) RequiredArgsConstructor(lombok.RequiredArgsConstructor) lombok.val(lombok.val) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) UUID(java.util.UUID) StringUtils(org.apache.commons.lang3.StringUtils) RequestContext(org.springframework.webflow.execution.RequestContext) ArrayList(java.util.ArrayList) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) HttpServletRequest(javax.servlet.http.HttpServletRequest) WsFederationConfiguration(org.apereo.cas.support.wsfederation.WsFederationConfiguration) WebUtils(org.apereo.cas.web.support.WebUtils) WsFederationNavigationController(org.apereo.cas.support.wsfederation.web.WsFederationNavigationController) Event(org.springframework.webflow.execution.Event) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) ArrayList(java.util.ArrayList) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport)

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