From d5ee557ef1370b5b9953dca1c8d3b14d0bd68a98 Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Thu, 02 May 2013 22:31:58 -0400 Subject: [PATCH] Do not use problematic WicketUtils fluid api --- src/main/java/com/gitblit/GitBlit.java | 108 +++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 74 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/gitblit/GitBlit.java b/src/main/java/com/gitblit/GitBlit.java index 566a917..377a7b3 100644 --- a/src/main/java/com/gitblit/GitBlit.java +++ b/src/main/java/com/gitblit/GitBlit.java @@ -71,7 +71,6 @@ import org.eclipse.jgit.lib.RepositoryCache.FileKey; import org.eclipse.jgit.lib.StoredConfig; import org.eclipse.jgit.storage.file.FileBasedConfig; -import org.eclipse.jgit.storage.file.WindowCache; import org.eclipse.jgit.storage.file.WindowCacheConfig; import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.FileUtils; @@ -90,6 +89,7 @@ import com.gitblit.fanout.FanoutNioService; import com.gitblit.fanout.FanoutService; import com.gitblit.fanout.FanoutSocketService; +import com.gitblit.git.GitDaemon; import com.gitblit.models.FederationModel; import com.gitblit.models.FederationProposal; import com.gitblit.models.FederationSet; @@ -190,6 +190,8 @@ private FanoutService fanoutService; + private GitDaemon gitDaemon; + public GitBlit() { if (gitblit == null) { // set the static singleton reference @@ -633,15 +635,18 @@ // try to authenticate by servlet container principal Principal principal = httpRequest.getUserPrincipal(); if (principal != null) { - UserModel user = getUserModel(principal.getName()); - if (user != null) { - flagWicketSession(AuthenticationType.CONTAINER); - logger.debug(MessageFormat.format("{0} authenticated by servlet container principal from {1}", - user.username, httpRequest.getRemoteAddr())); - return user; - } else { - logger.warn(MessageFormat.format("Failed to find UserModel for {0}, attempted servlet container authentication from {1}", - principal.getName(), httpRequest.getRemoteAddr())); + String username = principal.getName(); + if (StringUtils.isEmpty(username)) { + UserModel user = getUserModel(username); + if (user != null) { + flagWicketSession(AuthenticationType.CONTAINER); + logger.debug(MessageFormat.format("{0} authenticated by servlet container principal from {1}", + user.username, httpRequest.getRemoteAddr())); + return user; + } else { + logger.warn(MessageFormat.format("Failed to find UserModel for {0}, attempted servlet container authentication from {1}", + principal.getName(), httpRequest.getRemoteAddr())); + } } } @@ -1289,7 +1294,15 @@ for (String repo : list) { RepositoryModel model = getRepositoryModel(user, repo); if (model != null) { - repositories.add(model); + if (!model.hasCommits) { + // only add empty repositories that user can push to + if (UserModel.ANONYMOUS.canPush(model) + || user != null && user.canPush(model)) { + repositories.add(model); + } + } else { + repositories.add(model); + } } } if (getBoolean(Keys.web.showRepositorySizes, true)) { @@ -1376,7 +1389,7 @@ FileBasedConfig config = (FileBasedConfig) getRepositoryConfig(r); if (config.isOutdated()) { // reload model - logger.info(MessageFormat.format("Config for \"{0}\" has changed. Reloading model and updating cache.", repositoryName)); + logger.debug(MessageFormat.format("Config for \"{0}\" has changed. Reloading model and updating cache.", repositoryName)); model = loadRepositoryModel(model.name); removeFromCachedRepositoryList(model.name); addToCachedRepositoryList(model); @@ -3115,18 +3128,34 @@ projectConfigs = new FileBasedConfig(getFileOrFolder(Keys.web.projectsFile, "${baseFolder}/projects.conf"), FS.detect()); getProjectConfigs(); - // schedule mail engine + configureMailExecutor(); + configureLuceneIndexing(); + configureGarbageCollector(); + if (startFederation) { + configureFederation(); + } + configureJGit(); + configureFanout(); + configureGitDaemon(); + + ContainerUtils.CVE_2007_0450.test(); + } + + protected void configureMailExecutor() { if (mailExecutor.isReady()) { logger.info("Mail executor is scheduled to process the message queue every 2 minutes."); scheduledExecutor.scheduleAtFixedRate(mailExecutor, 1, 2, TimeUnit.MINUTES); } else { logger.warn("Mail server is not properly configured. Mail services disabled."); } - - // schedule lucene engine - enableLuceneIndexing(); - - + } + + protected void configureLuceneIndexing() { + scheduledExecutor.scheduleAtFixedRate(luceneExecutor, 1, 2, TimeUnit.MINUTES); + logger.info("Lucene executor is scheduled to process indexed branches every 2 minutes."); + } + + protected void configureGarbageCollector() { // schedule gc engine if (gcExecutor.isReady()) { logger.info("GC executor is scheduled to scan repositories every 24 hours."); @@ -3150,23 +3179,21 @@ logger.info(MessageFormat.format("Next scheculed GC scan is in {0}", when)); scheduledExecutor.scheduleAtFixedRate(gcExecutor, delay, 60*24, TimeUnit.MINUTES); } - - if (startFederation) { - configureFederation(); - } - + } + + protected void configureJGit() { // Configure JGit WindowCacheConfig cfg = new WindowCacheConfig(); - + cfg.setPackedGitWindowSize(settings.getFilesize(Keys.git.packedGitWindowSize, cfg.getPackedGitWindowSize())); cfg.setPackedGitLimit(settings.getFilesize(Keys.git.packedGitLimit, cfg.getPackedGitLimit())); cfg.setDeltaBaseCacheLimit(settings.getFilesize(Keys.git.deltaBaseCacheLimit, cfg.getDeltaBaseCacheLimit())); cfg.setPackedGitOpenFiles(settings.getFilesize(Keys.git.packedGitOpenFiles, cfg.getPackedGitOpenFiles())); cfg.setStreamFileThreshold(settings.getFilesize(Keys.git.streamFileThreshold, cfg.getStreamFileThreshold())); cfg.setPackedGitMMAP(settings.getBoolean(Keys.git.packedGitMmap, cfg.isPackedGitMMAP())); - + try { - WindowCache.reconfigure(cfg); + cfg.install(); logger.debug(MessageFormat.format("{0} = {1,number,0}", Keys.git.packedGitWindowSize, cfg.getPackedGitWindowSize())); logger.debug(MessageFormat.format("{0} = {1,number,0}", Keys.git.packedGitLimit, cfg.getPackedGitLimit())); logger.debug(MessageFormat.format("{0} = {1,number,0}", Keys.git.deltaBaseCacheLimit, cfg.getDeltaBaseCacheLimit())); @@ -3176,16 +3203,16 @@ } catch (IllegalArgumentException e) { logger.error("Failed to configure JGit parameters!", e); } - - ContainerUtils.CVE_2007_0450.test(); - + } + + protected void configureFanout() { // startup Fanout PubSub service if (settings.getInteger(Keys.fanout.port, 0) > 0) { String bindInterface = settings.getString(Keys.fanout.bindInterface, null); int port = settings.getInteger(Keys.fanout.port, FanoutService.DEFAULT_PORT); boolean useNio = settings.getBoolean(Keys.fanout.useNio, true); int limit = settings.getInteger(Keys.fanout.connectionLimit, 0); - + if (useNio) { if (StringUtils.isEmpty(bindInterface)) { fanoutService = new FanoutNioService(port); @@ -3199,16 +3226,26 @@ fanoutService = new FanoutSocketService(bindInterface, port); } } - + fanoutService.setConcurrentConnectionLimit(limit); fanoutService.setAllowAllChannelAnnouncements(false); fanoutService.start(); } } - protected void enableLuceneIndexing() { - scheduledExecutor.scheduleAtFixedRate(luceneExecutor, 1, 2, TimeUnit.MINUTES); - logger.info("Lucene executor is scheduled to process indexed branches every 2 minutes."); + protected void configureGitDaemon() { + String bindInterface = settings.getString(Keys.git.daemonBindInterface, "localhost"); + int port = settings.getInteger(Keys.git.daemonPort, 0); + if (port > 0) { + try { + gitDaemon = new GitDaemon(bindInterface, port, getRepositoriesFolder()); + gitDaemon.start(); + logger.info(MessageFormat.format("Git daemon is listening on {0}:{1,number,0}", bindInterface, port)); + } catch (IOException e) { + gitDaemon = null; + logger.error(MessageFormat.format("Failed to start Git daemon on {0}:{1,number,0}", bindInterface, port), e); + } + } } protected final Logger getLogger() { @@ -3319,6 +3356,9 @@ if (fanoutService != null) { fanoutService.stop(); } + if (gitDaemon != null) { + gitDaemon.stop(); + } } /** -- Gitblit v1.9.1