From a9cabcc5535184ce6c9ed55e4783879a5cec920b Mon Sep 17 00:00:00 2001 From: marwanehcine Date: Wed, 27 Sep 2023 11:16:16 +0100 Subject: [PATCH] making rabbitmq optional for gateway --- .../autoconfigure/app/FiltersAutoConfiguration.java | 7 +++++++ .../gateway/events/RabbitmqEventsAutoConfiguration.java | 3 ++- .../gateway/security/ldap/LdapConfigProperties.java | 2 -- .../gateway/security/oauth2/OpenIdConnectUserMapper.java | 5 ++++- georchestra | 2 +- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/gateway/src/main/java/org/georchestra/gateway/autoconfigure/app/FiltersAutoConfiguration.java b/gateway/src/main/java/org/georchestra/gateway/autoconfigure/app/FiltersAutoConfiguration.java index 4a5fca33..16c96a89 100644 --- a/gateway/src/main/java/org/georchestra/gateway/autoconfigure/app/FiltersAutoConfiguration.java +++ b/gateway/src/main/java/org/georchestra/gateway/autoconfigure/app/FiltersAutoConfiguration.java @@ -25,7 +25,10 @@ import org.geoserver.cloud.gateway.filter.RouteProfileGatewayFilterFactory; import org.geoserver.cloud.gateway.filter.StripBasePathGatewayFilterFactory; import org.geoserver.cloud.gateway.predicate.RegExpQueryRoutePredicateFactory; +import org.springframework.boot.actuate.health.Health; +import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.gateway.config.GatewayAutoConfiguration; import org.springframework.cloud.gateway.filter.GlobalFilter; @@ -65,4 +68,8 @@ public class FiltersAutoConfiguration { return new StripBasePathGatewayFilterFactory(); } + @ConditionalOnProperty(name = "enableRabbitmqEvents", havingValue = "true", matchIfMissing = false) + public @Bean HealthIndicator rabbitHealthIndicator() { + return () -> Health.up().withDetail("version", "mock").build(); + } } diff --git a/gateway/src/main/java/org/georchestra/gateway/events/RabbitmqEventsAutoConfiguration.java b/gateway/src/main/java/org/georchestra/gateway/events/RabbitmqEventsAutoConfiguration.java index 5d423ff5..536b879a 100644 --- a/gateway/src/main/java/org/georchestra/gateway/events/RabbitmqEventsAutoConfiguration.java +++ b/gateway/src/main/java/org/georchestra/gateway/events/RabbitmqEventsAutoConfiguration.java @@ -7,6 +7,7 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.amqp.core.Queue; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.cloud.gateway.config.GatewayAutoConfiguration; import org.springframework.context.annotation.*; @@ -14,7 +15,7 @@ @Configuration(proxyBeanMethods = false) @AutoConfigureAfter(GatewayAutoConfiguration.class) @ImportResource({ "classpath:rabbit-listener-context.xml", "classpath:rabbit-sender-context.xml" }) -@ConditionalOnExpression("${georchestra.gateway.security.enableRabbitmqEvents:true}") +@ConditionalOnProperty(name = "enableRabbitmqEvents", havingValue = "true", matchIfMissing = false) public class RabbitmqEventsAutoConfiguration { @Bean diff --git a/gateway/src/main/java/org/georchestra/gateway/security/ldap/LdapConfigProperties.java b/gateway/src/main/java/org/georchestra/gateway/security/ldap/LdapConfigProperties.java index a3159f0f..9c817ab0 100644 --- a/gateway/src/main/java/org/georchestra/gateway/security/ldap/LdapConfigProperties.java +++ b/gateway/src/main/java/org/georchestra/gateway/security/ldap/LdapConfigProperties.java @@ -65,8 +65,6 @@ public class LdapConfigProperties implements Validator { private boolean createNonExistingUsersInLDAP = true; - private boolean enableRabbitmqEvents = true; - @Valid private Map ldap = Map.of(); diff --git a/gateway/src/main/java/org/georchestra/gateway/security/oauth2/OpenIdConnectUserMapper.java b/gateway/src/main/java/org/georchestra/gateway/security/oauth2/OpenIdConnectUserMapper.java index 646fe2fb..5af88485 100644 --- a/gateway/src/main/java/org/georchestra/gateway/security/oauth2/OpenIdConnectUserMapper.java +++ b/gateway/src/main/java/org/georchestra/gateway/security/oauth2/OpenIdConnectUserMapper.java @@ -40,6 +40,7 @@ import org.georchestra.security.model.GeorchestraUser; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.core.Ordered; import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken; @@ -145,6 +146,8 @@ @Slf4j(topic = "org.georchestra.gateway.security.oauth2") public class OpenIdConnectUserMapper extends OAuth2UserMapper { + private @Value("${enableRabbitmqEvents:false}") boolean enableRabbitmq; + @Autowired LdapConfigProperties config; @@ -195,7 +198,7 @@ public class OpenIdConnectUserMapper extends OAuth2UserMapper { accountDao.insert(newAccount); roleDao.addUser(Role.USER, newAccount); userOpt = usersApi.findByOAuth2ProviderId(oAuth2ProviderId); - if (config.isEnableRabbitmqEvents() && eventsSender != null) { + if (enableRabbitmq && eventsSender != null) { eventsSender.sendNewOAuthAccountMessage( oidcUser.getGivenName() + " " + oidcUser.getFamilyName(), oidcUser.getEmail(), token.getAuthorizedClientRegistrationId()); diff --git a/georchestra b/georchestra index d6854ddf..8e0a718f 160000 --- a/georchestra +++ b/georchestra @@ -1 +1 @@ -Subproject commit d6854ddfe2bcd704d503e7431a7ff876629add34 +Subproject commit 8e0a718f3f8362778afd13726215b4f3029135f3