From c4e07c5bdb04e7eac1f83002a29be79230446b54 Mon Sep 17 00:00:00 2001 From: marwanehcine Date: Mon, 21 Aug 2023 00:10:03 +0100 Subject: [PATCH] Inform admins when new oauth2 account is created using spring rabbit --- .../gateway/events/RabbitmqEventsAutoConfiguration.java | 2 +- .../gateway/security/ldap/LdapConfigProperties.java | 2 ++ .../gateway/security/oauth2/OpenIdConnectUserMapper.java | 7 +++++-- 3 files changed, 8 insertions(+), 3 deletions(-) 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 3a3726e4..5d423ff5 100644 --- a/gateway/src/main/java/org/georchestra/gateway/events/RabbitmqEventsAutoConfiguration.java +++ b/gateway/src/main/java/org/georchestra/gateway/events/RabbitmqEventsAutoConfiguration.java @@ -14,7 +14,7 @@ @Configuration(proxyBeanMethods = false) @AutoConfigureAfter(GatewayAutoConfiguration.class) @ImportResource({ "classpath:rabbit-listener-context.xml", "classpath:rabbit-sender-context.xml" }) -@ConditionalOnExpression("${georchestra.gateway.security.createNonExistingUsersInLDAP:true}") +@ConditionalOnExpression("${georchestra.gateway.security.enableRabbitmqEvents:true}") 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 9c817ab0..a3159f0f 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,6 +65,8 @@ 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 870ddf28..c008ba91 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 @@ -195,8 +195,11 @@ public class OpenIdConnectUserMapper extends OAuth2UserMapper { accountDao.insert(newAccount); roleDao.addUser(Role.USER, newAccount); userOpt = usersApi.findByOAuth2ProviderId(oAuth2ProviderId); - eventsSender.sendNewOAuthAccountMessage(oidcUser.getGivenName() + " " + oidcUser.getFamilyName(), - oidcUser.getEmail(), token.getAuthorizedClientRegistrationId()); + if (config.isEnableRabbitmqEvents()) { + eventsSender.sendNewOAuthAccountMessage( + oidcUser.getGivenName() + " " + oidcUser.getFamilyName(), oidcUser.getEmail(), + token.getAuthorizedClientRegistrationId()); + } } catch (DuplicatedUidException e) { throw new IllegalStateException(e); } catch (DuplicatedEmailException e) {