use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.
the class OneTimeTokenAccountCheckRegistrationAction method doExecute.
@Override
protected Event doExecute(final RequestContext requestContext) {
val principal = resolvePrincipal(WebUtils.getAuthentication(requestContext).getPrincipal());
val uid = principal.getId();
val accounts = repository.get(uid);
if (accounts == null || accounts.isEmpty()) {
return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_REGISTER);
}
if (accounts.size() > 1) {
WebUtils.putOneTimeTokenAccounts(requestContext, accounts);
return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_CONFIRM);
}
WebUtils.putOneTimeTokenAccount(requestContext, accounts.iterator().next());
return success();
}
use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.
the class DuoSecurityDetermineUserAccountAction method doExecute.
@Override
protected Event doExecute(final RequestContext requestContext) {
val authentication = WebUtils.getAuthentication(requestContext);
val principal = resolvePrincipal(authentication.getPrincipal());
val duoAuthenticationService = provider.getDuoAuthenticationService();
val account = duoAuthenticationService.getUserAccount(principal.getId());
val eventFactorySupport = new EventFactorySupport();
if (account.getStatus() == DuoSecurityUserAccountStatus.ENROLL) {
if (StringUtils.isNotBlank(provider.getRegistrationUrl())) {
requestContext.getFlowScope().put("duoRegistrationUrl", provider.getRegistrationUrl());
return eventFactorySupport.event(this, CasWebflowConstants.TRANSITION_ID_ENROLL);
}
}
if (account.getStatus() == DuoSecurityUserAccountStatus.ALLOW) {
return eventFactorySupport.event(this, CasWebflowConstants.TRANSITION_ID_BYPASS);
}
if (account.getStatus() == DuoSecurityUserAccountStatus.DENY) {
return eventFactorySupport.event(this, CasWebflowConstants.TRANSITION_ID_DENY);
}
if (account.getStatus() == DuoSecurityUserAccountStatus.UNAVAILABLE) {
return eventFactorySupport.event(this, CasWebflowConstants.TRANSITION_ID_UNAVAILABLE);
}
return success();
}
use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.
the class InquireInterruptAction method doExecute.
@Override
protected Event doExecute(final RequestContext requestContext) {
if (WebUtils.isInterruptAuthenticationFlowFinalized(requestContext)) {
WebUtils.removeInterruptAuthenticationFlowFinalized(requestContext);
return getInterruptSkippedEvent();
}
val httpRequest = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
val authentication = WebUtils.getAuthentication(requestContext);
val service = WebUtils.getService(requestContext);
val registeredService = WebUtils.getRegisteredService(requestContext);
val credential = WebUtils.getCredential(requestContext);
val eventFactorySupport = new EventFactorySupport();
val forceInquiry = casProperties.getInterrupt().getCore().isForceExecution() || (registeredService != null && registeredService.getWebflowInterruptPolicy().getForceExecution().isTrue());
if (!forceInquiry && isAuthenticationFlowInterruptedAlready(authentication, httpRequest)) {
LOGGER.debug("Authentication event has already finalized interrupt. Skipping...");
return getInterruptSkippedEvent();
}
for (val inquirer : this.interruptInquirers) {
LOGGER.debug("Invoking interrupt inquirer using [{}]", inquirer.getName());
val response = inquirer.inquire(authentication, registeredService, service, credential, requestContext);
if (response != null && response.isInterrupt()) {
LOGGER.debug("Interrupt inquiry is required since inquirer produced a response [{}]", response);
InterruptUtils.putInterruptIn(requestContext, response);
InterruptUtils.putInterruptTriggerMode(requestContext, casProperties.getInterrupt().getCore().getTriggerMode());
WebUtils.putPrincipal(requestContext, authentication.getPrincipal());
return eventFactorySupport.event(this, CasWebflowConstants.TRANSITION_ID_INTERRUPT_REQUIRED);
}
}
LOGGER.debug("Webflow interrupt is skipped since no inquirer produced a response");
return getInterruptSkippedEvent();
}
use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.
the class FinalizeInterruptFlowAction method doExecute.
/**
* An authentication attempt can only contain {@link InquireInterruptAction#AUTHENTICATION_ATTRIBUTE_FINALIZED_INTERRUPT}
* if the attribute was added to the authentication object prior to creating the SSO session.
* If interrupt checking is set to execute after SSO sessions, then this attribute cannot be retrieved.
*
* @param requestContext request context
* @return the final event
* @throws Exception the exception
*/
@Override
protected Event doExecute(final RequestContext requestContext) throws Exception {
val response = InterruptUtils.getInterruptFrom(requestContext);
if (response.isBlock()) {
val registeredService = WebUtils.getRegisteredService(requestContext);
val accessUrl = Optional.ofNullable(registeredService).map(service -> service.getAccessStrategy().getUnauthorizedRedirectUrl()).orElse(null);
if (accessUrl != null) {
val url = accessUrl.toURL().toExternalForm();
val externalContext = requestContext.getExternalContext();
externalContext.requestExternalRedirect(url);
externalContext.recordResponseComplete();
return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_STOP);
}
throw new UnauthorizedServiceException(UnauthorizedServiceException.CODE_UNAUTHZ_SERVICE, "Denied");
}
val authentication = WebUtils.getAuthentication(requestContext);
authentication.addAttribute(InquireInterruptAction.AUTHENTICATION_ATTRIBUTE_FINALIZED_INTERRUPT, Boolean.TRUE);
WebUtils.putAuthentication(authentication, requestContext);
WebUtils.putInterruptAuthenticationFlowFinalized(requestContext);
val httpRequest = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
val httpResponse = WebUtils.getHttpServletResponseFromExternalWebflowContext(requestContext);
casCookieBuilder.addCookie(httpRequest, httpResponse, Boolean.TRUE.toString());
return success();
}
use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.
the class AcceptPasswordlessAuthenticationAction method doExecute.
@Override
protected Event doExecute(final RequestContext requestContext) {
val principal = WebUtils.getPasswordlessAuthenticationAccount(requestContext, PasswordlessUserAccount.class);
try {
val token = requestContext.getRequestParameters().getRequired("token");
val currentToken = passwordlessTokenRepository.findToken(principal.getUsername());
if (currentToken.isPresent() && token.equalsIgnoreCase(currentToken.get())) {
val credential = new OneTimePasswordCredential(principal.getUsername(), token);
val service = WebUtils.getService(requestContext);
val authenticationResult = authenticationSystemSupport.finalizeAuthenticationTransaction(service, credential);
WebUtils.putAuthenticationResult(authenticationResult, requestContext);
WebUtils.putAuthentication(authenticationResult.getAuthentication(), requestContext);
WebUtils.putCredential(requestContext, credential);
val finalEvent = super.doExecute(requestContext);
passwordlessTokenRepository.deleteToken(principal.getUsername(), currentToken.get());
return finalEvent;
}
} catch (final Exception e) {
LoggingUtils.error(LOGGER, e);
val attributes = new LocalAttributeMap<>();
attributes.put("error", e);
var account = principal != null ? passwordlessUserAccountStore.findUser(principal.getUsername()) : Optional.empty();
if (account.isPresent()) {
attributes.put("passwordlessAccount", account.get());
return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, attributes);
}
}
LOGGER.error("Unable to locate token for user [{}]", principal.getUsername());
val attributes = new LocalAttributeMap<>();
attributes.put("error", new AuthenticationException("Invalid token"));
return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, attributes);
}
Aggregations