diff options
author | Alfred Schmid <A.Schmid@ff-muenchen.de> | 2014-01-31 12:29:55 +0100 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2014-02-19 11:04:16 -0500 |
commit | eb1264b0944cfc0ac951c62239cc5a85428088e0 (patch) | |
tree | f7662b0a64e85c47de68daf3a2f0e7abd44470e5 /src/main/java/com/gitblit/auth/LdapAuthProvider.java | |
parent | b2775fefaafb0ce89094bdd4bb5308dbb90f487b (diff) | |
download | gitblit-eb1264b0944cfc0ac951c62239cc5a85428088e0.tar.gz gitblit-eb1264b0944cfc0ac951c62239cc5a85428088e0.zip |
Basic implementation of feature for ldap user synchronization as
background service. Introduced configuration property to configure the
synchronization period.
Diffstat (limited to 'src/main/java/com/gitblit/auth/LdapAuthProvider.java')
-rw-r--r-- | src/main/java/com/gitblit/auth/LdapAuthProvider.java | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/src/main/java/com/gitblit/auth/LdapAuthProvider.java b/src/main/java/com/gitblit/auth/LdapAuthProvider.java index 8fef620d..58fb8219 100644 --- a/src/main/java/com/gitblit/auth/LdapAuthProvider.java +++ b/src/main/java/com/gitblit/auth/LdapAuthProvider.java @@ -23,6 +23,8 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; @@ -32,8 +34,10 @@ import com.gitblit.Keys; import com.gitblit.auth.AuthenticationProvider.UsernamePasswordAuthenticationProvider; import com.gitblit.models.TeamModel; import com.gitblit.models.UserModel; +import com.gitblit.service.LdapSyncService; import com.gitblit.utils.ArrayUtils; import com.gitblit.utils.StringUtils; +import com.gitblit.utils.TimeUtils; import com.unboundid.ldap.sdk.Attribute; import com.unboundid.ldap.sdk.DereferencePolicy; import com.unboundid.ldap.sdk.ExtendedResult; @@ -57,7 +61,7 @@ import com.unboundid.util.ssl.TrustAllTrustManager; */ public class LdapAuthProvider extends UsernamePasswordAuthenticationProvider { - private AtomicLong lastLdapUserSync = new AtomicLong(0L); + private final AtomicLong lastLdapUserSync = new AtomicLong(0L); public LdapAuthProvider() { super("ldap"); @@ -78,6 +82,11 @@ public class LdapAuthProvider extends UsernamePasswordAuthenticationProvider { @Override public void setup() { synchronizeLdapUsers(); + configureLdapSyncService(); + } + + public void synchronizeWithLdapService() { + synchronizeLdapUsers(); } protected synchronized void synchronizeLdapUsers() { @@ -519,4 +528,24 @@ public class LdapAuthProvider extends UsernamePasswordAuthenticationProvider { } return sb.toString(); } + + private void configureLdapSyncService() { + logger.info("Start configuring ldap sync service"); + LdapSyncService ldapSyncService = new LdapSyncService(settings, this); + if (ldapSyncService.isReady()) { + int mins = TimeUtils.convertFrequencyToMinutes(settings.getString(Keys.realm.ldap.synchronizeUsers.ldapSyncPeriod, "5 mins")); + if (mins < 5) { + mins = 5; + } + int delay = 1; + ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); + scheduledExecutorService.scheduleAtFixedRate(ldapSyncService, delay, mins, TimeUnit.MINUTES); + logger.info("Ldap sync service will update user and groups every {} minutes.", mins); + logger.info("Next scheduled ldap sync is in {} minutes", delay); + } else { + logger.info("Ldap sync service is disabled."); + } + logger.info("Finished configuring ldap sync service"); + } + } |