mirror of
https://github.com/gitbucket/gitbucket.git
synced 2026-01-06 23:52:18 +01:00
Merge pull request #2199 from gitbucket/anonymous-accessible-paths
Add new extension point: anonymousAccessiblePaths
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user