use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.
the class SelectiveMultifactorAuthenticationProviderWebflowEventResolverTests method verifyEmptyOperation.
@Test
public void verifyEmptyOperation() {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
val service = RegisteredServiceTestUtils.getRegisteredService();
servicesManager.save(service);
WebUtils.putRegisteredService(context, service);
WebUtils.putAuthentication(RegisteredServiceTestUtils.getAuthentication(), context);
WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService());
val targetResolver = new DefaultTargetStateResolver(TestMultifactorAuthenticationProvider.ID);
val transition = new Transition(new DefaultTransitionCriteria(new LiteralExpression(TestMultifactorAuthenticationProvider.ID)), targetResolver);
context.getRootFlow().getGlobalTransitionSet().add(transition);
val resolvedEvents = CollectionUtils.wrapHashSet(new EventFactorySupport().event(this, "mfa-something"));
WebUtils.putResolvedEventsAsAttribute(context, resolvedEvents);
val result = selectiveAuthenticationProviderWebflowEventResolver.resolve(context);
assertNotNull(result);
assertTrue(WebUtils.getResolvedMultifactorAuthenticationProviders(context).isEmpty());
}
use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.
the class SelectiveMultifactorAuthenticationProviderWebflowEventResolverTests method verifyNoProvider.
@Test
public void verifyNoProvider() {
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
val service = RegisteredServiceTestUtils.getRegisteredService();
servicesManager.save(service);
WebUtils.putRegisteredService(context, service);
WebUtils.putAuthentication(RegisteredServiceTestUtils.getAuthentication(), context);
WebUtils.putServiceIntoFlowScope(context, RegisteredServiceTestUtils.getService());
val targetResolver = new DefaultTargetStateResolver(TestMultifactorAuthenticationProvider.ID);
val transition = new Transition(new DefaultTransitionCriteria(new LiteralExpression(TestMultifactorAuthenticationProvider.ID)), targetResolver);
context.getRootFlow().getGlobalTransitionSet().add(transition);
val resolvedEvents = CollectionUtils.wrapHashSet(new EventFactorySupport().event(this, "mfa-something"));
WebUtils.putResolvedEventsAsAttribute(context, resolvedEvents);
val result = selectiveAuthenticationProviderWebflowEventResolver.resolve(context);
assertNotNull(result);
assertFalse(result.isEmpty());
}
use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.
the class PrepareMultifactorProviderSelectionActionTests method verifyOperation.
@Test
public void verifyOperation() throws Exception {
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
val flowSession = new MockFlowSession(new Flow(CasWebflowConfigurer.FLOW_ID_LOGIN));
flowSession.setState(new ViewState(flowSession.getDefinitionInternal(), "viewState", mock(ViewFactory.class)));
val exec = new MockFlowExecutionContext(flowSession);
val context = new MockRequestContext(exec);
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
RequestContextHolder.setRequestContext(context);
ExternalContextHolder.setExternalContext(context.getExternalContext());
val chain = new DefaultChainingMultifactorAuthenticationProvider(new DefaultMultifactorAuthenticationFailureModeEvaluator(casProperties));
val provider = new TestMultifactorAuthenticationProvider();
provider.setBypassEvaluator(new DefaultChainingMultifactorAuthenticationBypassProvider());
chain.addMultifactorAuthenticationProvider(provider);
val attributes = new LocalAttributeMap(RegisteredService.class.getName(), RegisteredServiceTestUtils.getRegisteredService());
attributes.put(MultifactorAuthenticationProvider.class.getName(), chain);
val event = new EventFactorySupport().event(this, ChainingMultifactorAuthenticationProvider.DEFAULT_IDENTIFIER, attributes);
context.setCurrentEvent(event);
assertNull(action.execute(context));
assertNotNull(WebUtils.getSelectableMultifactorAuthenticationProviders(context));
}
use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.
the class VerifyPasswordResetRequestAction method doExecute.
@Override
protected Event doExecute(final RequestContext requestContext) throws Exception {
val request = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
val transientTicket = request.getParameter(PasswordManagementWebflowUtils.REQUEST_PARAMETER_NAME_PASSWORD_RESET_TOKEN);
if (StringUtils.isBlank(transientTicket)) {
LOGGER.error("Password reset token is missing");
return error();
}
var passwordResetTicket = (TransientSessionTicket) null;
try {
passwordResetTicket = centralAuthenticationService.getTicket(transientTicket, TransientSessionTicket.class);
passwordResetTicket.update();
val token = passwordResetTicket.getProperties().get(PasswordManagementWebflowUtils.FLOWSCOPE_PARAMETER_NAME_TOKEN).toString();
val username = passwordManagementService.parseToken(token);
val query = PasswordManagementQuery.builder().username(username).build();
PasswordManagementWebflowUtils.putPasswordResetToken(requestContext, token);
val pm = casProperties.getAuthn().getPm();
if (pm.getReset().isSecurityQuestionsEnabled()) {
val questions = canonicalizeSecurityQuestions(passwordManagementService.getSecurityQuestions(query));
if (questions.isEmpty()) {
LOGGER.warn("No security questions could be found for [{}]", username);
return error();
}
PasswordManagementWebflowUtils.putPasswordResetSecurityQuestions(requestContext, questions);
} else {
LOGGER.debug("Security questions are not enabled");
}
PasswordManagementWebflowUtils.putPasswordResetUsername(requestContext, username);
PasswordManagementWebflowUtils.putPasswordResetSecurityQuestionsEnabled(requestContext, pm.getReset().isSecurityQuestionsEnabled());
if (pm.getReset().isSecurityQuestionsEnabled()) {
LOGGER.trace("Security questions are enabled; proceeding...");
return success();
}
return new EventFactorySupport().event(this, EVENT_ID_SECURITY_QUESTIONS_DISABLED);
} catch (final Exception e) {
LoggingUtils.error(LOGGER, "Password reset token could not be located or verified", e);
return error();
} finally {
if (passwordResetTicket != null && passwordResetTicket.isExpired()) {
centralAuthenticationService.deleteTicket(passwordResetTicket);
}
}
}
use of org.springframework.webflow.action.EventFactorySupport in project cas by apereo.
the class SendPasswordResetInstructionsAction method getErrorEvent.
/**
* Gets error event.
*
* @param code the code
* @param defaultMessage the default message
* @param requestContext the request context
* @return the error event
*/
protected Event getErrorEvent(final String code, final String defaultMessage, final RequestContext requestContext) {
WebUtils.addErrorMessageToContext(requestContext, "screen.pm.reset." + code, defaultMessage);
LOGGER.error(defaultMessage);
return new EventFactorySupport().event(this, CasWebflowConstants.TRANSITION_ID_ERROR);
}
Aggregations