mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-15 09:55:49 +01:00
Fix plugin controller handling
This commit is contained in:
Binary file not shown.
@@ -3,6 +3,7 @@ package gitbucket.core.servlet
|
||||
import javax.servlet._
|
||||
import javax.servlet.http.HttpServletRequest
|
||||
|
||||
import gitbucket.core.controller.ControllerBase
|
||||
import gitbucket.core.plugin.PluginRegistry
|
||||
|
||||
class PluginControllerFilter extends Filter {
|
||||
@@ -20,18 +21,25 @@ class PluginControllerFilter extends Filter {
|
||||
}
|
||||
|
||||
override def doFilter(request: ServletRequest, response: ServletResponse, chain: FilterChain): Unit = {
|
||||
val controller = PluginRegistry().getControllers().find { case (_, path) =>
|
||||
val controller = PluginRegistry().getControllers().filter { case (_, path) =>
|
||||
val requestUri = request.asInstanceOf[HttpServletRequest].getRequestURI
|
||||
path.endsWith("/*") && requestUri.startsWith(path.replaceFirst("/\\*$", "/"))
|
||||
val start = path.replaceFirst("/\\*$", "/")
|
||||
path.endsWith("/*") && (requestUri + "/").startsWith(start)
|
||||
}
|
||||
|
||||
controller.map { case (controller, _) =>
|
||||
val filterChainWrapper = controller.foldLeft(chain){ case (chain, (controller, _)) =>
|
||||
new FilterChainWrapper(controller, chain)
|
||||
}
|
||||
filterChainWrapper.doFilter(request, response)
|
||||
}
|
||||
|
||||
class FilterChainWrapper(controller: ControllerBase, chain: FilterChain) extends FilterChain {
|
||||
override def doFilter(request: ServletRequest, response: ServletResponse): Unit = {
|
||||
if(controller.config == null){
|
||||
controller.init(filterConfig)
|
||||
}
|
||||
controller.doFilter(request, response, chain)
|
||||
}.getOrElse{
|
||||
chain.doFilter(request, response)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user