From 9cd87b167ed6f53e6287d6dbe30a612d250e9ca2 Mon Sep 17 00:00:00 2001 From: jusabatier Date: Wed, 11 Sep 2024 16:59:18 +0200 Subject: [PATCH] Corrections proprties url + missing annotations --- .../cadastrapp/configuration/LdapConfig.java | 10 +++++++++- .../cadastrapp/cron/LDAPGroupsAutorisationsSync.java | 9 +++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/configuration/LdapConfig.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/configuration/LdapConfig.java index 486ab113..d7360369 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/configuration/LdapConfig.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/configuration/LdapConfig.java @@ -5,16 +5,19 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.core.env.Environment; +import org.springframework.ldap.core.LdapTemplate; import org.springframework.ldap.core.support.LdapContextSource; +import org.springframework.scheduling.annotation.EnableScheduling; @Configuration @PropertySource( value = { "file:${georchestra.datadir}/default.properties", - "file:${georchestra.datadir}/cadastrapp/cadastrapp.properties}" + "file:${georchestra.datadir}/cadastrapp/cadastrapp.properties" }, ignoreResourceNotFound = true ) +@EnableScheduling public class LdapConfig { @Autowired private Environment env; @@ -30,4 +33,9 @@ public LdapContextSource contextSource() { return contextSource; } + + @Bean + public LdapTemplate ldapTemplate() { + return new LdapTemplate(contextSource()); + } } diff --git a/cadastrapp/src/main/java/org/georchestra/cadastrapp/cron/LDAPGroupsAutorisationsSync.java b/cadastrapp/src/main/java/org/georchestra/cadastrapp/cron/LDAPGroupsAutorisationsSync.java index 89863cc8..a6dbd2ca 100644 --- a/cadastrapp/src/main/java/org/georchestra/cadastrapp/cron/LDAPGroupsAutorisationsSync.java +++ b/cadastrapp/src/main/java/org/georchestra/cadastrapp/cron/LDAPGroupsAutorisationsSync.java @@ -3,6 +3,8 @@ import java.util.ArrayList; import java.util.List; +import javax.annotation.PostConstruct; + import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -13,12 +15,14 @@ import org.springframework.core.env.Environment; import org.springframework.ldap.core.LdapTemplate; import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; +@Component public class LDAPGroupsAutorisationsSync { private static final Logger LOGGER = LogManager.getLogger( LDAPGroupsAutorisationsSync.class ); @Autowired - private Environment env; + Environment env; @Autowired LdapTemplate lt; @@ -26,9 +30,10 @@ public class LDAPGroupsAutorisationsSync { @Autowired GroupeAutorisationRepository gar; + @PostConstruct @Scheduled(cron = "${ldapAreas.cronExpression}") public void refreshOrganisationsPermissions() { - if( env.containsProperty("ldapAreas.enable") && env.getProperty("ldapAreas.enable") == "true" ) { + if( env.containsProperty("ldapAreas.enable") && env.getProperty("ldapAreas.enable").contentEquals("true") ) { List lstOrg = lt.findAll(Organisation.class); List lstGA = new ArrayList<>(); for (Organisation o : lstOrg) {