Skip to content
Permalink
Browse files

ensure event consumption is async where needed

  • Loading branch information...
mmoayyed committed Sep 21, 2019
1 parent e6d67f1 commit 58345b0fb651a8178aacb8bd165f4337b0f30197
Showing with 58 additions and 10 deletions.
  1. +2 −1 api/cas-server-core-api-webflow/src/main/java/org/apereo/cas/web/flow/CasWebflowConstants.java
  2. +2 −2 ...on-mfa-api/src/main/java/org/apereo/cas/authentication/MultifactorAuthenticationProviderBean.java
  3. +2 −0 ...r-core-configuration/src/main/java/org/apereo/cas/configuration/CasConfigurationWatchService.java
  4. +5 −0 ...core-events-api/src/main/java/org/apereo/cas/support/events/listener/DefaultCasEventListener.java
  5. +8 −0 ...core-events-api/src/main/java/org/apereo/cas/support/events/listener/LoggingCasEventListener.java
  6. +2 −0 ...s/src/main/java/org/apereo/cas/support/events/listener/CasCloudBusConfigurationEventListener.java
  7. +3 −0 ...iguration/src/main/java/org/apereo/cas/support/events/listener/CasConfigurationEventListener.java
  8. +3 −0 ...rver-core-services-api/src/main/java/org/apereo/cas/services/RegisteredServicesEventListener.java
  9. +3 −0 ...rc/main/java/org/apereo/cas/services/CasServiceRegistryInitializerConfigurationEventListener.java
  10. +2 −0 ...core-services/src/main/java/org/apereo/cas/config/CasCoreServicesAuthenticationConfiguration.java
  11. +4 −0 core/cas-server-core-services/src/main/java/org/apereo/cas/config/CasCoreServicesConfiguration.java
  12. +3 −1 ...e-services/src/main/java/org/apereo/cas/config/CasServiceRegistryInitializationConfiguration.java
  13. +1 −1 ...e-webflow-api/src/main/java/org/apereo/cas/web/flow/configurer/DefaultLoginWebflowConfigurer.java
  14. +1 −1 ...erver-support-actions/src/main/java/org/apereo/cas/web/config/CasSupportActionsConfiguration.java
  15. +0 −1 ...as-server-support-actions/src/main/java/org/apereo/cas/web/flow/login/InitialFlowSetupAction.java
  16. +0 −1 ...as-server-support-actions/src/main/java/org/apereo/cas/web/flow/logout/LogoutViewSetupAction.java
  17. +1 −1 ...ain/java/org/apereo/cas/adaptors/duo/web/flow/config/DuoSecurityMultifactorWebflowConfigurer.java
  18. +7 −0 ...port-pm-webflow/src/main/java/org/apereo/cas/pm/web/flow/PasswordManagementWebflowConfigurer.java
  19. +4 −0 ...istry-stream/src/main/java/org/apereo/cas/services/CasServicesRegistryStreamingEventListener.java
  20. +3 −0 ...ation/src/main/java/org/apereo/cas/authentication/event/SurrogateAuthenticationEventListener.java
  21. +2 −1 webapp/cas-server-webapp-resources/src/main/resources/templates/fragments/loginform.html
@@ -666,7 +666,8 @@
/**
* Action id 'initialFlowSetupAction'.
*/
String ACTION_ID_INIT_FLOW_SETUP = "initialFlowSetupAction";
String ACTION_ID_INITIAL_FLOW_SETUP = "initialFlowSetupAction";

/**
* Action id 'verifyRequiredServiceAction'.
*/
@@ -54,14 +54,14 @@ public T getProvider(final String id) {
/**
* Provider instances are not part of the {@link org.springframework.cloud.context.scope.refresh.RefreshScope}
* since they were not defined during initial auto-configuration. This class is
* usually not consulted after initial configuration. This listener is here so this bean is initialized after a
* usually not consulted after initial configuration. This listener is here so this bean is initialized after a
* refresh and the provider instances get recreated.
*
* @param event - the event.
*/
@EventListener
public void onRefreshScopeRefreshed(final RefreshScopeRefreshedEvent event) {
LOGGER.debug("Refreshing MFA Providers");
LOGGER.debug("Refreshing MFA Providers...");
}


@@ -14,6 +14,7 @@
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;

import java.io.Closeable;
import java.io.File;
@@ -49,6 +50,7 @@ public void close() {
* @param event the event
*/
@EventListener
@Async
public void runPathWatchServices(final ApplicationReadyEvent event) {
watchConfigurationDirectoryIfNeeded();
watchConfigurationFileIfNeeded();
@@ -17,6 +17,7 @@
import lombok.val;
import org.apereo.inspektr.common.web.ClientInfoHolder;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;

/**
* This is {@link DefaultCasEventListener} that attempts to consume CAS events
@@ -57,6 +58,7 @@ private static CasEvent prepareCasEvent(final AbstractCasEvent event) {
* @param event the event
*/
@EventListener
@Async
public void handleCasTicketGrantingTicketCreatedEvent(final CasTicketGrantingTicketCreatedEvent event) {
if (this.casEventRepository != null) {
val dto = prepareCasEvent(event);
@@ -73,6 +75,7 @@ public void handleCasTicketGrantingTicketCreatedEvent(final CasTicketGrantingTic
* @param event the event
*/
@EventListener
@Async
public void handleCasAuthenticationTransactionFailureEvent(final CasAuthenticationTransactionFailureEvent event) {
if (this.casEventRepository != null) {
val dto = prepareCasEvent(event);
@@ -88,6 +91,7 @@ public void handleCasAuthenticationTransactionFailureEvent(final CasAuthenticati
* @param event the event
*/
@EventListener
@Async
public void handleCasAuthenticationPolicyFailureEvent(final CasAuthenticationPolicyFailureEvent event) {
if (this.casEventRepository != null) {
val dto = prepareCasEvent(event);
@@ -103,6 +107,7 @@ public void handleCasAuthenticationPolicyFailureEvent(final CasAuthenticationPol
* @param event the event
*/
@EventListener
@Async
public void handleCasRiskyAuthenticationDetectedEvent(final CasRiskyAuthenticationDetectedEvent event) {
if (this.casEventRepository != null) {
val dto = prepareCasEvent(event);
@@ -11,6 +11,7 @@
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;

import static org.apereo.cas.util.serialization.TicketIdSanitizationUtils.sanitize;

@@ -48,6 +49,7 @@
* @param e the event
*/
@EventListener
@Async
public void logTicketGrantingTicketCreatedEvent(final CasTicketGrantingTicketCreatedEvent e) {
val tgtId = sanitize(e.getTgtId());
LOGGER.debug(GRANTED_TGT_MSG,
@@ -64,6 +66,7 @@ public void logTicketGrantingTicketCreatedEvent(final CasTicketGrantingTicketCre
* @param e the event
*/
@EventListener
@Async
public void logAuthenticationTransactionFailureEvent(final CasAuthenticationTransactionFailureEvent e) {
LOGGER.debug(AUTHN_TX_FAIL_MSG, e.getCredential(), e.getFailures());
}
@@ -74,6 +77,7 @@ public void logAuthenticationTransactionFailureEvent(final CasAuthenticationTran
* @param e the event
*/
@EventListener
@Async
public void logAuthenticationPrincipalResolvedEvent(final CasAuthenticationPrincipalResolvedEvent e) {
LOGGER.debug(PRINCIPAL_RESOLVED_MSG, e.getPrincipal().getId(), e.getPrincipal().getAttributes());
}
@@ -84,6 +88,7 @@ public void logAuthenticationPrincipalResolvedEvent(final CasAuthenticationPrinc
* @param e the event
*/
@EventListener
@Async
public void logTicketGrantingTicketDestroyedEvent(final CasTicketGrantingTicketDestroyedEvent e) {
val tgtId = sanitize(e.getTgtId());
LOGGER.debug(DESTROYED_TGT_MSG,
@@ -101,6 +106,7 @@ public void logTicketGrantingTicketDestroyedEvent(final CasTicketGrantingTicketD
* @param e the event
*/
@EventListener
@Async
public void logProxyTicketGrantedEvent(final CasProxyTicketGrantedEvent e) {
val pgt = e.getProxyGrantingTicket();
val pt = e.getProxyTicket();
@@ -124,6 +130,7 @@ public void logProxyTicketGrantedEvent(final CasProxyTicketGrantedEvent e) {
* @param e the event
*/
@EventListener
@Async
public void logServiceTicketGrantedEvent(final CasServiceTicketGrantedEvent e) {
val serviceTicket = e.getServiceTicket();
LOGGER.debug(CREATED_ST_MSG,
@@ -139,6 +146,7 @@ public void logServiceTicketGrantedEvent(final CasServiceTicketGrantedEvent e) {
* @param e the event
*/
@EventListener
@Async
public void logServiceTicketValidatedEvent(final CasServiceTicketValidatedEvent e) {
val serviceTicket = e.getServiceTicket();
val principal = serviceTicket.getTicketGrantingTicket().getAuthentication().getPrincipal();
@@ -7,6 +7,7 @@
import org.springframework.cloud.bus.event.RefreshRemoteApplicationEvent;
import org.springframework.context.ApplicationContext;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;

/**
* This is {@link CasCloudBusConfigurationEventListener}.
@@ -26,6 +27,7 @@
* @param event the event
*/
@EventListener
@Async
public void handleRefreshEvent(final RefreshRemoteApplicationEvent event) {
LOGGER.trace("Received event [{}]", event);
configurationPropertiesEnvironmentManager.rebindCasConfigurationProperties(this.applicationContext);
@@ -11,6 +11,7 @@
import org.springframework.cloud.context.refresh.ContextRefresher;
import org.springframework.context.ApplicationContext;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;

import java.util.ArrayList;
import java.util.Collection;
@@ -39,6 +40,7 @@
* @param event the event
*/
@EventListener
@Async
public void handleRefreshEvent(final EnvironmentChangeEvent event) {
LOGGER.trace("Received event [{}]", event);
rebind();
@@ -50,6 +52,7 @@ public void handleRefreshEvent(final EnvironmentChangeEvent event) {
* @param event the event
*/
@EventListener
@Async
public void handleConfigurationModifiedEvent(final CasConfigurationModifiedEvent event) {
if (this.contextRefresher == null) {
LOGGER.warn("Unable to refresh application context, since no refresher is available");
@@ -10,6 +10,7 @@
import lombok.val;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;

/**
* This is {@link RegisteredServicesEventListener}.
@@ -30,6 +31,7 @@
* @param event the event
*/
@EventListener
@Async
public void handleRefreshEvent(final CasRegisteredServicesRefreshEvent event) {
servicesManager.load();
}
@@ -40,6 +42,7 @@ public void handleRefreshEvent(final CasRegisteredServicesRefreshEvent event) {
* @param event the event
*/
@EventListener
@Async
public void handleRegisteredServiceExpiredEvent(final CasRegisteredServiceExpiredEvent event) {
val registeredService = event.getRegisteredService();
val contacts = registeredService.getContacts();
@@ -6,6 +6,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;

/**
* This is {@link CasServiceRegistryInitializerConfigurationEventListener}.
@@ -24,6 +25,7 @@
* @param event the event
*/
@EventListener
@Async
public void handleRefreshEvent(final EnvironmentChangeEvent event) {
LOGGER.trace("Received event [{}]", event);
rebind();
@@ -35,6 +37,7 @@ public void handleRefreshEvent(final EnvironmentChangeEvent event) {
* @param event the event
*/
@EventListener
@Async
public void handleConfigurationModifiedEvent(final CasConfigurationModifiedEvent event) {
if (event.isEligibleForContextRefresh()) {
rebind();
@@ -16,6 +16,7 @@
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;

/**
* This is {@link CasCoreServicesAuthenticationConfiguration}.
@@ -25,6 +26,7 @@
*/
@Configuration(value = "casCoreServicesAuthenticationConfiguration", proxyBeanMethods = false)
@EnableConfigurationProperties(CasConfigurationProperties.class)
@EnableAsync
public class CasCoreServicesAuthenticationConfiguration {

@Autowired
@@ -57,6 +57,8 @@
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.core.env.Environment;
import org.springframework.http.converter.AbstractHttpMessageConverter;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;

import java.util.ArrayList;
import java.util.Arrays;
@@ -74,6 +76,7 @@
@Configuration("casCoreServicesConfiguration")
@EnableConfigurationProperties(CasConfigurationProperties.class)
@Slf4j
@EnableAsync
public class CasCoreServicesConfiguration {
@Autowired
@Qualifier("communicationsManager")
@@ -233,6 +236,7 @@ public ServiceRegistry inMemoryServiceRegistry() {
* @param event the event
*/
@EventListener
@Async
public void refreshServicesManagerWhenReady(final ApplicationReadyEvent event) {
servicesManager().load();
}
@@ -33,6 +33,7 @@
import org.springframework.context.annotation.Lazy;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.scheduling.annotation.EnableAsync;

import java.util.Collection;

@@ -51,7 +52,8 @@
@ConditionalOnBean(ServicesManager.class)
@ConditionalOnProperty(prefix = "cas.serviceRegistry", name = "initFromJson", havingValue = "true")
@Slf4j
@EnableAspectJAutoProxy(proxyTargetClass=true)
@EnableAspectJAutoProxy(proxyTargetClass = true)
@EnableAsync
public class CasServiceRegistryInitializationConfiguration {

@Autowired
@@ -80,7 +80,7 @@ protected void doInitialize() {
*/
protected void createInitialFlowActions(final Flow flow) {
val startActionList = flow.getStartActionList();
startActionList.add(createEvaluateAction(CasWebflowConstants.ACTION_ID_INIT_FLOW_SETUP));
startActionList.add(createEvaluateAction(CasWebflowConstants.ACTION_ID_INITIAL_FLOW_SETUP));
startActionList.add(createEvaluateAction(CasWebflowConstants.ACTION_ID_VERIFY_REQUIRED_SERVICE));
}

@@ -236,7 +236,7 @@ public Action renderLoginFormAction() {
@RefreshScope
@Bean
@Autowired
@ConditionalOnMissingBean(name = CasWebflowConstants.ACTION_ID_INIT_FLOW_SETUP)
@ConditionalOnMissingBean(name = CasWebflowConstants.ACTION_ID_INITIAL_FLOW_SETUP)
public Action initialFlowSetupAction(@Qualifier("argumentExtractor") final ArgumentExtractor argumentExtractor) {
return new InitialFlowSetupAction(CollectionUtils.wrap(argumentExtractor),
servicesManager.getIfAvailable(),
@@ -147,7 +147,6 @@ private void configureWebflowContext(final RequestContext context) {
WebUtils.putWarningCookie(context, Boolean.valueOf(this.warnCookieGenerator.retrieveCookieValue(request)));

WebUtils.putGeoLocationTrackingIntoFlowScope(context, casProperties.getEvents().isTrackGeolocation());
WebUtils.putPasswordManagementEnabled(context, casProperties.getAuthn().getPm().isEnabled());
WebUtils.putRememberMeAuthenticationEnabled(context, casProperties.getTicket().getTgt().getRememberMe().isEnabled());
WebUtils.putStaticAuthenticationIntoFlowScope(context,
StringUtils.isNotBlank(casProperties.getAuthn().getAccept().getUsers())
@@ -24,7 +24,6 @@
protected Event doInternalExecute(final HttpServletRequest request, final HttpServletResponse response,
final RequestContext context) {
WebUtils.putGeoLocationTrackingIntoFlowScope(context, casProperties.getEvents().isTrackGeolocation());
WebUtils.putPasswordManagementEnabled(context, casProperties.getAuthn().getPm().isEnabled());
return null;
}
}
@@ -311,7 +311,7 @@ private static void createDuoDetermineUserAccountAction(final List<AbstractState

private static void createDuoFlowStartActions(final DynamicFlowModelBuilder modelBuilder) {
val starts = new ArrayList<AbstractActionModel>();
starts.add(new EvaluateModel(CasWebflowConstants.ACTION_ID_INIT_FLOW_SETUP));
starts.add(new EvaluateModel(CasWebflowConstants.ACTION_ID_INITIAL_FLOW_SETUP));
modelBuilder.setOnStartActions(starts);
}

@@ -7,6 +7,7 @@
import org.apereo.cas.web.flow.CasWebflowConfigurer;
import org.apereo.cas.web.flow.CasWebflowConstants;
import org.apereo.cas.web.flow.configurer.AbstractCasWebflowConfigurer;
import org.apereo.cas.web.support.WebUtils;

import lombok.val;
import org.springframework.context.ApplicationContext;
@@ -64,6 +65,12 @@ protected void doInitialize() {
}

private void createAccountStatusViewStates(final Flow flow) {
val initialAction = getState(flow, CasWebflowConstants.ACTION_ID_INITIAL_FLOW_SETUP, ActionState.class);

This comment has been minimized.

Copy link
@wsaca

wsaca Sep 25, 2019

Contributor

@mmoayyed This line returns null, password management is not working.

This comment has been minimized.

Copy link
@auxepaul

auxepaul Oct 15, 2019

Contributor

Yes, it breaks Password Management Module on 6.1.0-RC6

initialAction.getActionList().add(requestContext -> {
WebUtils.putPasswordManagementEnabled(requestContext, casProperties.getAuthn().getPm().isEnabled());
return null;
});

createViewState(flow, CasWebflowConstants.VIEW_ID_AUTHENTICATION_BLOCKED, CasWebflowConstants.VIEW_ID_AUTHENTICATION_BLOCKED);
createViewState(flow, CasWebflowConstants.VIEW_ID_INVALID_WORKSTATION, CasWebflowConstants.VIEW_ID_INVALID_WORKSTATION);
createViewState(flow, CasWebflowConstants.VIEW_ID_INVALID_AUTHENTICATION_HOURS, CasWebflowConstants.VIEW_ID_INVALID_AUTHENTICATION_HOURS);
@@ -8,6 +8,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;

/**
* This is {@link CasServicesRegistryStreamingEventListener}.
@@ -26,6 +27,7 @@
* @param event the event
*/
@EventListener
@Async
public void handleCasRegisteredServiceLoadedEvent(final CasRegisteredServiceLoadedEvent event) {
LOGGER.trace("Received event [{}]", event);
this.publisher.publish(event.getRegisteredService(), event);
@@ -37,6 +39,7 @@ public void handleCasRegisteredServiceLoadedEvent(final CasRegisteredServiceLoad
* @param event the event
*/
@EventListener
@Async
public void handleCasRegisteredServiceSavedEvent(final CasRegisteredServiceSavedEvent event) {
LOGGER.trace("Received event [{}]", event);
this.publisher.publish(event.getRegisteredService(), event);
@@ -48,6 +51,7 @@ public void handleCasRegisteredServiceSavedEvent(final CasRegisteredServiceSaved
* @param event the event
*/
@EventListener
@Async
public void handleCasRegisteredServiceDeletedEvent(final CasRegisteredServiceDeletedEvent event) {
LOGGER.trace("Received event [{}]", event);
this.publisher.publish(event.getRegisteredService(), event);

0 comments on commit 58345b0

Please sign in to comment.
You can’t perform that action at this time.