mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 13:35:50 +01:00
Bug fix caused by path splitting.
This commit is contained in:
@@ -37,6 +37,7 @@ trait WebHookService {
|
||||
import org.apache.http.impl.client.DefaultHttpClient
|
||||
import scala.concurrent._
|
||||
import ExecutionContext.Implicits.global
|
||||
|
||||
logger.debug("start callWebHook")
|
||||
implicit val formats = Serialization.formats(NoTypeHints)
|
||||
|
||||
@@ -48,16 +49,16 @@ trait WebHookService {
|
||||
|
||||
webHookURLs.foreach { webHookUrl =>
|
||||
val f = future {
|
||||
logger.debug("start web hook invocation for %s", webHookUrl)
|
||||
logger.debug(s"start web hook invocation for ${webHookUrl}")
|
||||
val httpPost = new HttpPost(webHookUrl.url)
|
||||
|
||||
val params: java.util.List[NameValuePair] = new java.util.ArrayList()
|
||||
params.add(new BasicNameValuePair("payload", json))
|
||||
httpPost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8))
|
||||
httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"))
|
||||
|
||||
httpClient.execute(httpPost)
|
||||
httpPost.releaseConnection()
|
||||
logger.debug("end web hook invocation for %s", webHookUrl)
|
||||
logger.debug(s"end web hook invocation for ${webHookUrl}")
|
||||
}
|
||||
f.onSuccess {
|
||||
case s => logger.debug(s"Success: web hook request to ${webHookUrl.url}")
|
||||
|
||||
@@ -28,8 +28,8 @@ class BasicAuthenticationFilter extends Filter with RepositoryService with Accou
|
||||
}
|
||||
|
||||
try {
|
||||
defining(request.paths.toSeq){ case (repositoryOwner :: repositoryName :: _) =>
|
||||
getRepository(repositoryOwner, repositoryName.replaceFirst("\\.wiki", ""), "") match {
|
||||
defining(request.paths){ case Array(_, repositoryOwner, repositoryName, _*) =>
|
||||
getRepository(repositoryOwner, repositoryName.replaceFirst("\\.wiki\\.git$|\\.git$", ""), "") match {
|
||||
case Some(repository) => {
|
||||
if(!request.getRequestURI.endsWith("/git-receive-pack") &&
|
||||
!"service=git-receive-pack".equals(request.getQueryString) && !repository.repository.isPrivate){
|
||||
@@ -47,7 +47,10 @@ class BasicAuthenticationFilter extends Filter with RepositoryService with Accou
|
||||
}
|
||||
}
|
||||
}
|
||||
case None => response.sendError(HttpServletResponse.SC_NOT_FOUND)
|
||||
case None => {
|
||||
logger.debug(s"Repository ${repositoryOwner}/${repositoryName} is not found.")
|
||||
response.sendError(HttpServletResponse.SC_NOT_FOUND)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
|
||||
@@ -61,8 +61,8 @@ class GitBucketReceivePackFactory extends ReceivePackFactory[HttpServletRequest]
|
||||
logger.debug("userName:" + userName)
|
||||
|
||||
defining(request.paths){ paths =>
|
||||
val owner = paths(2)
|
||||
val repository = paths(3).replaceFirst("\\.git$", "")
|
||||
val owner = paths(1)
|
||||
val repository = paths(2).replaceFirst("\\.git$", "")
|
||||
val baseURL = request.getRequestURL.toString.replaceFirst("/git/.*", "")
|
||||
|
||||
logger.debug("repository:" + owner + "/" + repository)
|
||||
|
||||
@@ -18,7 +18,7 @@ trait OneselfAuthenticator { self: ControllerBase =>
|
||||
defining(request.paths){ paths =>
|
||||
context.loginAccount match {
|
||||
case Some(x) if(x.isAdmin) => action
|
||||
case Some(x) if(paths(1) == x.userName) => action
|
||||
case Some(x) if(paths(0) == x.userName) => action
|
||||
case _ => Unauthorized()
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ trait OwnerAuthenticator { self: ControllerBase with RepositoryService =>
|
||||
private def authenticate(action: (RepositoryInfo) => Any) = {
|
||||
{
|
||||
defining(request.paths){ paths =>
|
||||
getRepository(paths(1), paths(2), baseUrl).map { repository =>
|
||||
getRepository(paths(0), paths(1), baseUrl).map { repository =>
|
||||
context.loginAccount match {
|
||||
case Some(x) if(x.isAdmin) => action(repository)
|
||||
case Some(x) if(repository.owner == x.userName) => action(repository)
|
||||
@@ -92,11 +92,11 @@ trait CollaboratorsAuthenticator { self: ControllerBase with RepositoryService =
|
||||
private def authenticate(action: (RepositoryInfo) => Any) = {
|
||||
{
|
||||
defining(request.paths){ paths =>
|
||||
getRepository(paths(1), paths(2), baseUrl).map { repository =>
|
||||
getRepository(paths(0), paths(1), baseUrl).map { repository =>
|
||||
context.loginAccount match {
|
||||
case Some(x) if(x.isAdmin) => action(repository)
|
||||
case Some(x) if(paths(1) == x.userName) => action(repository)
|
||||
case Some(x) if(getCollaborators(paths(1), paths(2)).contains(x.userName)) => action(repository)
|
||||
case Some(x) if(paths(0) == x.userName) => action(repository)
|
||||
case Some(x) if(getCollaborators(paths(0), paths(1)).contains(x.userName)) => action(repository)
|
||||
case _ => Unauthorized()
|
||||
}
|
||||
} getOrElse NotFound()
|
||||
@@ -115,14 +115,14 @@ trait ReferrerAuthenticator { self: ControllerBase with RepositoryService =>
|
||||
private def authenticate(action: (RepositoryInfo) => Any) = {
|
||||
{
|
||||
defining(request.paths){ paths =>
|
||||
getRepository(paths(1), paths(2), baseUrl).map { repository =>
|
||||
getRepository(paths(0), paths(1), baseUrl).map { repository =>
|
||||
if(!repository.repository.isPrivate){
|
||||
action(repository)
|
||||
} else {
|
||||
context.loginAccount match {
|
||||
case Some(x) if(x.isAdmin) => action(repository)
|
||||
case Some(x) if(paths(1) == x.userName) => action(repository)
|
||||
case Some(x) if(getCollaborators(paths(1), paths(2)).contains(x.userName)) => action(repository)
|
||||
case Some(x) if(paths(0) == x.userName) => action(repository)
|
||||
case Some(x) if(getCollaborators(paths(0), paths(1)).contains(x.userName)) => action(repository)
|
||||
case _ => Unauthorized()
|
||||
}
|
||||
}
|
||||
@@ -142,12 +142,12 @@ trait ReadableUsersAuthenticator { self: ControllerBase with RepositoryService =
|
||||
private def authenticate(action: (RepositoryInfo) => Any) = {
|
||||
{
|
||||
defining(request.paths){ paths =>
|
||||
getRepository(paths(1), paths(2), baseUrl).map { repository =>
|
||||
getRepository(paths(0), paths(1), baseUrl).map { repository =>
|
||||
context.loginAccount match {
|
||||
case Some(x) if(x.isAdmin) => action(repository)
|
||||
case Some(x) if(!repository.repository.isPrivate) => action(repository)
|
||||
case Some(x) if(paths(1) == x.userName) => action(repository)
|
||||
case Some(x) if(getCollaborators(paths(1), paths(2)).contains(x.userName)) => action(repository)
|
||||
case Some(x) if(paths(0) == x.userName) => action(repository)
|
||||
case Some(x) if(getCollaborators(paths(0), paths(1)).contains(x.userName)) => action(repository)
|
||||
case _ => Unauthorized()
|
||||
}
|
||||
} getOrElse NotFound()
|
||||
|
||||
@@ -45,7 +45,7 @@ object Implicits {
|
||||
|
||||
implicit class RichRequest(request: HttpServletRequest){
|
||||
|
||||
def paths: Array[String] = request.getRequestURI.substring(request.getContextPath.length).split("/")
|
||||
def paths: Array[String] = request.getRequestURI.substring(request.getContextPath.length + 1).split("/")
|
||||
|
||||
def hasQueryString: Boolean = request.getQueryString != null
|
||||
|
||||
|
||||
Reference in New Issue
Block a user