diff --git a/src/main/scala/gitbucket/core/controller/PreProcessController.scala b/src/main/scala/gitbucket/core/controller/PreProcessController.scala index 50023c4..9e21ecc 100644 --- a/src/main/scala/gitbucket/core/controller/PreProcessController.scala +++ b/src/main/scala/gitbucket/core/controller/PreProcessController.scala @@ -1,5 +1,6 @@ package gitbucket.core.controller +import gitbucket.core.plugin.PluginRegistry import org.scalatra.MovedPermanently class PreProcessController extends PreProcessControllerBase @@ -30,7 +31,10 @@ */ get(!context.settings.allowAnonymousAccess, context.loginAccount.isEmpty) { if (!context.currentPath.startsWith("/assets") && !context.currentPath.startsWith("/signin") && - !context.currentPath.startsWith("/register") && !context.currentPath.endsWith("/info/refs")) { + !context.currentPath.startsWith("/register") && !context.currentPath.endsWith("/info/refs") && + !PluginRegistry().getAnonymousAccessiblePaths().exists { path => + context.currentPath.startsWith(path) + }) { Unauthorized() } else { pass() diff --git a/src/main/scala/gitbucket/core/plugin/Plugin.scala b/src/main/scala/gitbucket/core/plugin/Plugin.scala index 06355f2..30b3aa9 100644 --- a/src/main/scala/gitbucket/core/plugin/Plugin.scala +++ b/src/main/scala/gitbucket/core/plugin/Plugin.scala @@ -48,6 +48,20 @@ ): Seq[(String, ControllerBase)] = Nil /** + * Override to declare this plug-in provides anonymous accessible paths. + */ + val anonymousAccessiblePaths: Seq[String] = Nil + + /** + * Override to declare this plug-in provides anonymous accessible paths. + */ + def anonymousAccessiblePaths( + registry: PluginRegistry, + context: ServletContext, + settings: SystemSettings + ): Seq[String] = Nil + + /** * Override to declare this plug-in provides JavaScript. */ val javaScripts: Seq[(String, String)] = Nil diff --git a/src/main/scala/gitbucket/core/plugin/PluginRegistry.scala b/src/main/scala/gitbucket/core/plugin/PluginRegistry.scala index ebe93a6..a68a9b3 100644 --- a/src/main/scala/gitbucket/core/plugin/PluginRegistry.scala +++ b/src/main/scala/gitbucket/core/plugin/PluginRegistry.scala @@ -1,6 +1,6 @@ package gitbucket.core.plugin -import java.io.{File, FilenameFilter, InputStream} +import java.io.{File, FilenameFilter} import java.net.URLClassLoader import java.nio.file.{Files, Paths, StandardWatchEventKinds} import java.util.Base64 @@ -15,7 +15,6 @@ import gitbucket.core.service.RepositoryService.RepositoryInfo import gitbucket.core.service.SystemSettingsService import gitbucket.core.service.SystemSettingsService.SystemSettings -import gitbucket.core.util.SyntaxSugars._ import gitbucket.core.util.DatabaseConfig import gitbucket.core.util.Directory._ import gitbucket.core.util.HttpClientUtil._ @@ -35,6 +34,7 @@ private val plugins = new ConcurrentLinkedQueue[PluginInfo] private val javaScripts = new ConcurrentLinkedQueue[(String, String)] private val controllers = new ConcurrentLinkedQueue[(ControllerBase, String)] + private val anonymousAccessiblePaths = new ConcurrentLinkedQueue[String] private val images = new ConcurrentHashMap[String, String] private val renderers = new ConcurrentHashMap[String, Renderer] renderers.put("md", MarkdownRenderer) @@ -76,6 +76,10 @@ def getControllers(): Seq[(ControllerBase, String)] = controllers.asScala.toSeq + def addAnonymousAccessiblePath(path: String): Unit = anonymousAccessiblePaths.add(path) + + def getAnonymousAccessiblePaths(): Seq[String] = anonymousAccessiblePaths.asScala.toSeq + def addJavaScript(path: String, script: String): Unit = javaScripts.add((path, script)) //javaScripts += ((path, script))