Skip to content

Commit

Permalink
making rabbitmq optional for gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
marwanehcine committed Oct 23, 2023
1 parent 8180e6a commit 73ad10e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
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.ConditionalOnExpression;
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;
Expand Down Expand Up @@ -65,4 +69,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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
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.*;

@Profile("!test && !it")
@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ public class LdapConfigProperties implements Validator {

private boolean createNonExistingUsersInLDAP = true;

private boolean enableRabbitmqEvents = true;

@Valid
private Map<String, Server> ldap = Map.of();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 73ad10e

Please sign in to comment.