Merge pull request #2199 from gitbucket/anonymous-accessible-paths

Add new extension point: anonymousAccessiblePaths
This commit is contained in:
Naoki Takezoe
2018-11-16 08:12:23 +09:00
committed by GitHub
3 changed files with 25 additions and 3 deletions

View File

@@ -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 @@ trait PreProcessControllerBase extends ControllerBase {
*/
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()

View File

@@ -47,6 +47,20 @@ abstract class Plugin {
settings: SystemSettings
): 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.
*/

View File

@@ -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.ProtectedBranchService.ProtectedBranchReceiveHook
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 @@ class PluginRegistry {
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 @@ class PluginRegistry {
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))