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);
}
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()));
}
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);
}
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);
}
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);
}
Aggregations