use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.
the class DetermineDuoUserAccountAction method doExecute.
@Override
protected Event doExecute(final RequestContext requestContext) {
final Authentication authentication = WebUtils.getAuthentication(requestContext);
final Principal p = authentication.getPrincipal();
final Collection<MultifactorAuthenticationProvider> providers = WebUtils.getResolvedMultifactorAuthenticationProviders(requestContext);
for (final MultifactorAuthenticationProvider pr : providers) {
final DuoMultifactorAuthenticationProvider duoProvider = this.provider.findProvider(pr.getId(), DuoMultifactorAuthenticationProvider.class);
final DuoSecurityAuthenticationService duoAuthenticationService = duoProvider.getDuoAuthenticationService();
final DuoUserAccount account = duoAuthenticationService.getDuoUserAccount(p.getId());
if (account.getStatus() == DuoUserAccountAuthStatus.ENROLL && StringUtils.isNotBlank(duoProvider.getRegistrationUrl())) {
requestContext.getFlowScope().put("duoRegistrationUrl", duoProvider.getRegistrationUrl());
return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_ENROLL);
}
}
return success();
}
use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.
the class CasSimpleMultifactorSendTokenAction method doExecute.
@Override
protected Event doExecute(final RequestContext requestContext) {
val authentication = WebUtils.getInProgressAuthentication();
val principal = resolvePrincipal(authentication.getPrincipal());
val token = getOrCreateToken(requestContext, principal);
LOGGER.debug("Using token [{}] created at [{}]", token.getId(), token.getCreationTime());
val strategy = tokenCommunicationStrategy.determineStrategy(token);
val smsSent = strategy.contains(CasSimpleMultifactorTokenCommunicationStrategy.TokenSharingStrategyOptions.SMS) && isSmsSent(communicationsManager, properties, principal, token);
val emailSent = strategy.contains(CasSimpleMultifactorTokenCommunicationStrategy.TokenSharingStrategyOptions.EMAIL) && isMailSent(communicationsManager, properties, principal, token, requestContext);
val notificationSent = strategy.contains(CasSimpleMultifactorTokenCommunicationStrategy.TokenSharingStrategyOptions.NOTIFICATION) && isNotificationSent(communicationsManager, principal, token);
if (smsSent || emailSent || notificationSent) {
addOrUpdateToken(token);
LOGGER.debug("Successfully submitted token via strategy option [{}] to [{}]", strategy, principal.getId());
WebUtils.addInfoMessageToContext(requestContext, MESSAGE_MFA_TOKEN_SENT);
val attributes = new LocalAttributeMap<Object>("token", token.getId());
WebUtils.putSimpleMultifactorAuthenticationToken(requestContext, token);
return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_SUCCESS, attributes);
}
LOGGER.error("Communication strategies failed to submit token [{}] to user", token.getId());
return error();
}
use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.
the class AccepttoMultifactorValidateChannelAction method doExecute.
@Override
protected Event doExecute(final RequestContext requestContext) {
val eventAttributes = new LocalAttributeMap<>();
try {
val request = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
val response = WebUtils.getHttpServletResponseFromExternalWebflowContext(requestContext);
val webContext = new JEEContext(request, response);
val channel = AccepttoWebflowUtils.getChannel(webContext, sessionStore);
if (channel.isEmpty()) {
LOGGER.debug("Unable to determine channel from session store; not a validation attempt");
return null;
}
val authentication = AccepttoWebflowUtils.getAuthentication(webContext, sessionStore);
if (authentication == null) {
LOGGER.debug("Unable to determine the original authentication attempt the session store");
throw new AuthenticationException("Unable to determine authentication from session store");
}
WebUtils.putAuthentication(authentication, requestContext);
val credential = new AccepttoMultifactorTokenCredential(channel.toString());
val service = WebUtils.getService(requestContext);
LOGGER.debug("Cleaning up session store to remove [{}]", credential);
AccepttoWebflowUtils.resetChannelAndAuthentication(webContext, sessionStore);
AccepttoWebflowUtils.setChannel(requestContext, null);
LOGGER.debug("Attempting to authenticate channel [{}] with authentication [{}] and service [{}]", credential, authentication, service);
var resultBuilder = authenticationSystemSupport.establishAuthenticationContextFromInitial(authentication);
resultBuilder = authenticationSystemSupport.handleAuthenticationTransaction(service, resultBuilder, credential);
WebUtils.putAuthenticationResultBuilder(resultBuilder, requestContext);
return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_FINALIZE);
} catch (final Exception e) {
eventAttributes.put("error", e);
LoggingUtils.error(LOGGER, e);
}
return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, eventAttributes);
}
use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.
the class AccepttoMultifactorDetermineUserAccountStatusAction method doExecute.
@Override
public Event doExecute(final RequestContext requestContext) {
val eventFactorySupport = new EventFactorySupport();
val acceptto = casProperties.getAuthn().getMfa().getAcceptto();
val authentication = WebUtils.getInProgressAuthentication();
val email = AccepttoApiUtils.getUserEmail(authentication, acceptto);
try {
LOGGER.trace("Contacting authentication API to inquire for account status of [{}]", email);
val results = AccepttoApiUtils.authenticate(authentication, acceptto, requestContext, this.apiPublicKey);
val responseCode = ObjectUtils.defaultIfNull(results.get("response_code"), StringUtils.EMPTY).toString();
val isApproved = results.containsKey("status") && responseCode.equalsIgnoreCase("approved");
if (isApproved) {
LOGGER.trace("Account status is approved for [{}]. Moving on...", email);
val credential = new AccepttoEmailCredential(email);
WebUtils.putCredential(requestContext, credential);
return eventFactorySupport.event(this, CasWebflowConstants.TRANSITION_ID_APPROVE);
}
if (results.isEmpty()) {
LOGGER.warn("No API response could be found for [{}]. Denying access...", email);
return eventFactorySupport.event(this, CasWebflowConstants.TRANSITION_ID_DENY);
}
val success = BooleanUtils.toBoolean(results.get("success").toString());
if (!success) {
LOGGER.warn("API response did not return successfully for [{}]. Denying access...", email);
return eventFactorySupport.event(this, CasWebflowConstants.TRANSITION_ID_DENY);
}
val shouldPairDevice = responseCode.equalsIgnoreCase("pair_device");
if (shouldPairDevice && results.containsKey("invite_token")) {
val originalToken = results.get("invite_token").toString();
LOGGER.trace("Located invitation token as [{}] for [{}].", originalToken, email);
val invitationToken = AccepttoApiUtils.decodeInvitationToken(originalToken);
LOGGER.trace("Decoded invitation token as [{}] for [{}].", invitationToken, email);
AccepttoWebflowUtils.setApplicationId(requestContext, acceptto.getApplicationId());
AccepttoWebflowUtils.setInvitationToken(requestContext, invitationToken);
if (results.containsKey("eguardian_user_id")) {
val eguardianUserId = CollectionUtils.firstElement(results.get("eguardian_user_id")).get();
AccepttoWebflowUtils.setEGuardianUserId(requestContext, eguardianUserId.toString());
}
val qrHash = AccepttoApiUtils.generateQRCodeHash(authentication, acceptto, invitationToken);
LOGGER.trace("Generated QR hash [{}] for [{}] to register/pair device.", qrHash, email);
AccepttoWebflowUtils.setInvitationTokenQRCode(requestContext, qrHash);
return eventFactorySupport.event(this, CasWebflowConstants.TRANSITION_ID_REGISTER);
}
val isSuccessResponseCode = responseCode.equalsIgnoreCase("success");
if (isSuccessResponseCode && results.containsKey("channel")) {
val channel = results.get("channel").toString();
AccepttoWebflowUtils.setChannel(requestContext, channel);
if (results.containsKey("eguardian_user_id")) {
val eguardianUserId = CollectionUtils.firstElement(results.get("eguardian_user_id")).get();
AccepttoWebflowUtils.setEGuardianUserId(requestContext, eguardianUserId.toString());
}
}
} catch (final Exception e) {
LoggingUtils.error(LOGGER, e);
return eventFactorySupport.event(this, CasWebflowConstants.TRANSITION_ID_DENY);
}
LOGGER.trace("Account status is verified for [{}]. Proceeding to MFA flow...", email);
return eventFactorySupport.event(this, CasWebflowConstants.TRANSITION_ID_SUCCESS);
}
use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.
the class YubiKeyAuthenticationWebflowActionTests method verifyOperation.
@Test
public void verifyOperation() throws Exception {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
WebUtils.putAuthentication(CoreAuthenticationTestUtils.getAuthentication(), context);
val resolver = mock(CasWebflowEventResolver.class);
when(resolver.resolve(any())).thenReturn(Set.of(new EventFactorySupport().success(this)));
when(resolver.resolveSingle(any())).thenReturn(new EventFactorySupport().success(this));
val action = new YubiKeyAuthenticationWebflowAction(resolver);
assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, action.execute(context).getId());
}
Aggregations