diff --git a/src/main/java/JettyLauncher.java b/src/main/java/JettyLauncher.java index 36c28e7..05abf4d 100644 --- a/src/main/java/JettyLauncher.java +++ b/src/main/java/JettyLauncher.java @@ -4,6 +4,10 @@ import org.eclipse.jetty.server.HttpConnectionFactory; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.StatisticsHandler; +import org.eclipse.jetty.server.session.DefaultSessionCache; +import org.eclipse.jetty.server.session.FileSessionDataStore; +import org.eclipse.jetty.server.session.SessionCache; +import org.eclipse.jetty.server.session.SessionHandler; import org.eclipse.jetty.webapp.WebAppContext; import java.io.File; @@ -21,6 +25,7 @@ String contextPath = "/"; String tmpDirPath=""; boolean forceHttps = false; + boolean saveSessions = false; host = getEnvironmentVariable("gitbucket.host"); port = getEnvironmentVariable("gitbucket.port"); @@ -28,6 +33,9 @@ tmpDirPath = getEnvironmentVariable("gitbucket.tempDir"); for(String arg: args) { + if(arg.equals("--save_sessions")) { + saveSessions = true; + } if(arg.startsWith("--") && arg.contains("=")) { String[] dim = arg.split("="); if(dim.length >= 2) { @@ -87,6 +95,19 @@ WebAppContext context = new WebAppContext(); + if(saveSessions) { + File sessDir = new File(getGitBucketHome(), "sessions"); + if(!sessDir.exists()){ + sessDir.mkdirs(); + } + SessionHandler sessions = context.getSessionHandler(); + SessionCache cache = new DefaultSessionCache(sessions); + FileSessionDataStore fsds = new FileSessionDataStore(); + fsds.setStoreDir(sessDir); + cache.setSessionDataStore(fsds); + sessions.setSessionCache(cache); + } + File tmpDir; if(tmpDirPath == null || tmpDirPath.equals("")){ tmpDir = new File(getGitBucketHome(), "tmp");