From 27ae9095639bb228a1b7ff86a3ebe4264abf05be Mon Sep 17 00:00:00 2001
From: mschaefers <mschaefers@scoop-gmbh.de>
Date: Thu, 29 Nov 2012 12:33:09 -0500
Subject: [PATCH] feature: when using LdapUserService one can configure Gitblit to fetch all users from ldap that can possibly login. This allows to see newly generated LDAP users instantly in Gitblit. By now an LDAP user had to log in once to appear in GitBlit.
---
src/com/gitblit/client/GitblitManager.java | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 55 insertions(+), 1 deletions(-)
diff --git a/src/com/gitblit/client/GitblitManager.java b/src/com/gitblit/client/GitblitManager.java
index 22f98eb..dd0315f 100644
--- a/src/com/gitblit/client/GitblitManager.java
+++ b/src/com/gitblit/client/GitblitManager.java
@@ -25,7 +25,10 @@
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
+import java.io.BufferedReader;
import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
import java.io.IOException;
import java.net.ConnectException;
import java.text.MessageFormat;
@@ -34,6 +37,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
@@ -310,7 +314,13 @@
} else {
password = new String(Base64.decode(pw)).toCharArray();
}
- GitblitRegistration reg = new GitblitRegistration(server, url, account, password);
+ GitblitRegistration reg = new GitblitRegistration(server, url, account, password) {
+ private static final long serialVersionUID = 1L;
+
+ protected void cacheFeeds() {
+ writeFeedCache(this);
+ }
+ };
String[] feeds = config.getStringList(SERVER, server, FEED);
if (feeds != null) {
// deserialize the field definitions
@@ -320,6 +330,7 @@
}
}
reg.lastLogin = lastLogin;
+ loadFeedCache(reg);
registrations.put(reg.name, reg);
}
} catch (Throwable t) {
@@ -388,6 +399,49 @@
return config;
}
+ private void loadFeedCache(GitblitRegistration reg) {
+ File feedCache = new File(configFile.getParentFile(), StringUtils.getSHA1(reg.toString())
+ + ".cache");
+ if (!feedCache.exists()) {
+ // no cache for this registration
+ return;
+ }
+ try {
+ BufferedReader reader = new BufferedReader(new FileReader(feedCache));
+ Map<String, Date> cache = new HashMap<String, Date>();
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
+ String line = null;
+ while ((line = reader.readLine()) != null) {
+ String[] kvp = line.split("=");
+ cache.put(kvp[0], df.parse(kvp[1]));
+ }
+ reader.close();
+ for (FeedModel feed : reg.feeds) {
+ String name = feed.toString();
+ if (cache.containsKey(name)) {
+ feed.currentRefreshDate = cache.get(name);
+ }
+ }
+ } catch (Exception e) {
+ Utils.showException(GitblitManager.this, e);
+ }
+ }
+
+ private void writeFeedCache(GitblitRegistration reg) {
+ try {
+ File feedCache = new File(configFile.getParentFile(), StringUtils.getSHA1(reg
+ .toString()) + ".cache");
+ FileWriter writer = new FileWriter(feedCache);
+ for (FeedModel feed : reg.feeds) {
+ writer.append(MessageFormat.format("{0}={1,date,yyyy-MM-dd'T'HH:mm:ss}\n",
+ feed.toString(), feed.currentRefreshDate));
+ }
+ writer.close();
+ } catch (Exception e) {
+ Utils.showException(GitblitManager.this, e);
+ }
+ }
+
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
--
Gitblit v1.9.1