mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-07 05:55:51 +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 org.apache.http.impl.client.DefaultHttpClient
|
||||||
import scala.concurrent._
|
import scala.concurrent._
|
||||||
import ExecutionContext.Implicits.global
|
import ExecutionContext.Implicits.global
|
||||||
|
|
||||||
logger.debug("start callWebHook")
|
logger.debug("start callWebHook")
|
||||||
implicit val formats = Serialization.formats(NoTypeHints)
|
implicit val formats = Serialization.formats(NoTypeHints)
|
||||||
|
|
||||||
@@ -48,16 +49,16 @@ trait WebHookService {
|
|||||||
|
|
||||||
webHookURLs.foreach { webHookUrl =>
|
webHookURLs.foreach { webHookUrl =>
|
||||||
val f = future {
|
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 httpPost = new HttpPost(webHookUrl.url)
|
||||||
|
|
||||||
val params: java.util.List[NameValuePair] = new java.util.ArrayList()
|
val params: java.util.List[NameValuePair] = new java.util.ArrayList()
|
||||||
params.add(new BasicNameValuePair("payload", json))
|
params.add(new BasicNameValuePair("payload", json))
|
||||||
httpPost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8))
|
httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"))
|
||||||
|
|
||||||
httpClient.execute(httpPost)
|
httpClient.execute(httpPost)
|
||||||
httpPost.releaseConnection()
|
httpPost.releaseConnection()
|
||||||
logger.debug("end web hook invocation for %s", webHookUrl)
|
logger.debug(s"end web hook invocation for ${webHookUrl}")
|
||||||
}
|
}
|
||||||
f.onSuccess {
|
f.onSuccess {
|
||||||
case s => logger.debug(s"Success: web hook request to ${webHookUrl.url}")
|
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 {
|
try {
|
||||||
defining(request.paths.toSeq){ case (repositoryOwner :: repositoryName :: _) =>
|
defining(request.paths){ case Array(_, repositoryOwner, repositoryName, _*) =>
|
||||||
getRepository(repositoryOwner, repositoryName.replaceFirst("\\.wiki", ""), "") match {
|
getRepository(repositoryOwner, repositoryName.replaceFirst("\\.wiki\\.git$|\\.git$", ""), "") match {
|
||||||
case Some(repository) => {
|
case Some(repository) => {
|
||||||
if(!request.getRequestURI.endsWith("/git-receive-pack") &&
|
if(!request.getRequestURI.endsWith("/git-receive-pack") &&
|
||||||
!"service=git-receive-pack".equals(request.getQueryString) && !repository.repository.isPrivate){
|
!"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 {
|
} catch {
|
||||||
|
|||||||
@@ -61,8 +61,8 @@ class GitBucketReceivePackFactory extends ReceivePackFactory[HttpServletRequest]
|
|||||||
logger.debug("userName:" + userName)
|
logger.debug("userName:" + userName)
|
||||||
|
|
||||||
defining(request.paths){ paths =>
|
defining(request.paths){ paths =>
|
||||||
val owner = paths(2)
|
val owner = paths(1)
|
||||||
val repository = paths(3).replaceFirst("\\.git$", "")
|
val repository = paths(2).replaceFirst("\\.git$", "")
|
||||||
val baseURL = request.getRequestURL.toString.replaceFirst("/git/.*", "")
|
val baseURL = request.getRequestURL.toString.replaceFirst("/git/.*", "")
|
||||||
|
|
||||||
logger.debug("repository:" + owner + "/" + repository)
|
logger.debug("repository:" + owner + "/" + repository)
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ trait OneselfAuthenticator { self: ControllerBase =>
|
|||||||
defining(request.paths){ paths =>
|
defining(request.paths){ paths =>
|
||||||
context.loginAccount match {
|
context.loginAccount match {
|
||||||
case Some(x) if(x.isAdmin) => action
|
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()
|
case _ => Unauthorized()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,7 +36,7 @@ trait OwnerAuthenticator { self: ControllerBase with RepositoryService =>
|
|||||||
private def authenticate(action: (RepositoryInfo) => Any) = {
|
private def authenticate(action: (RepositoryInfo) => Any) = {
|
||||||
{
|
{
|
||||||
defining(request.paths){ paths =>
|
defining(request.paths){ paths =>
|
||||||
getRepository(paths(1), paths(2), baseUrl).map { repository =>
|
getRepository(paths(0), paths(1), baseUrl).map { repository =>
|
||||||
context.loginAccount match {
|
context.loginAccount match {
|
||||||
case Some(x) if(x.isAdmin) => action(repository)
|
case Some(x) if(x.isAdmin) => action(repository)
|
||||||
case Some(x) if(repository.owner == x.userName) => 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) = {
|
private def authenticate(action: (RepositoryInfo) => Any) = {
|
||||||
{
|
{
|
||||||
defining(request.paths){ paths =>
|
defining(request.paths){ paths =>
|
||||||
getRepository(paths(1), paths(2), baseUrl).map { repository =>
|
getRepository(paths(0), paths(1), baseUrl).map { repository =>
|
||||||
context.loginAccount match {
|
context.loginAccount match {
|
||||||
case Some(x) if(x.isAdmin) => action(repository)
|
case Some(x) if(x.isAdmin) => action(repository)
|
||||||
case Some(x) if(paths(1) == x.userName) => action(repository)
|
case Some(x) if(paths(0) == x.userName) => action(repository)
|
||||||
case Some(x) if(getCollaborators(paths(1), paths(2)).contains(x.userName)) => action(repository)
|
case Some(x) if(getCollaborators(paths(0), paths(1)).contains(x.userName)) => action(repository)
|
||||||
case _ => Unauthorized()
|
case _ => Unauthorized()
|
||||||
}
|
}
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
@@ -115,14 +115,14 @@ trait ReferrerAuthenticator { self: ControllerBase with RepositoryService =>
|
|||||||
private def authenticate(action: (RepositoryInfo) => Any) = {
|
private def authenticate(action: (RepositoryInfo) => Any) = {
|
||||||
{
|
{
|
||||||
defining(request.paths){ paths =>
|
defining(request.paths){ paths =>
|
||||||
getRepository(paths(1), paths(2), baseUrl).map { repository =>
|
getRepository(paths(0), paths(1), baseUrl).map { repository =>
|
||||||
if(!repository.repository.isPrivate){
|
if(!repository.repository.isPrivate){
|
||||||
action(repository)
|
action(repository)
|
||||||
} else {
|
} else {
|
||||||
context.loginAccount match {
|
context.loginAccount match {
|
||||||
case Some(x) if(x.isAdmin) => action(repository)
|
case Some(x) if(x.isAdmin) => action(repository)
|
||||||
case Some(x) if(paths(1) == x.userName) => action(repository)
|
case Some(x) if(paths(0) == x.userName) => action(repository)
|
||||||
case Some(x) if(getCollaborators(paths(1), paths(2)).contains(x.userName)) => action(repository)
|
case Some(x) if(getCollaborators(paths(0), paths(1)).contains(x.userName)) => action(repository)
|
||||||
case _ => Unauthorized()
|
case _ => Unauthorized()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -142,12 +142,12 @@ trait ReadableUsersAuthenticator { self: ControllerBase with RepositoryService =
|
|||||||
private def authenticate(action: (RepositoryInfo) => Any) = {
|
private def authenticate(action: (RepositoryInfo) => Any) = {
|
||||||
{
|
{
|
||||||
defining(request.paths){ paths =>
|
defining(request.paths){ paths =>
|
||||||
getRepository(paths(1), paths(2), baseUrl).map { repository =>
|
getRepository(paths(0), paths(1), baseUrl).map { repository =>
|
||||||
context.loginAccount match {
|
context.loginAccount match {
|
||||||
case Some(x) if(x.isAdmin) => action(repository)
|
case Some(x) if(x.isAdmin) => action(repository)
|
||||||
case Some(x) if(!repository.repository.isPrivate) => 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(paths(0) == x.userName) => action(repository)
|
||||||
case Some(x) if(getCollaborators(paths(1), paths(2)).contains(x.userName)) => action(repository)
|
case Some(x) if(getCollaborators(paths(0), paths(1)).contains(x.userName)) => action(repository)
|
||||||
case _ => Unauthorized()
|
case _ => Unauthorized()
|
||||||
}
|
}
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ object Implicits {
|
|||||||
|
|
||||||
implicit class RichRequest(request: HttpServletRequest){
|
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
|
def hasQueryString: Boolean = request.getQueryString != null
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user