|
1 | 1 | import javax.servlet.http.{HttpServletResponse, HttpServletRequest} |
2 | 2 |
|
| 3 | +import gitbucket.core.model._ |
3 | 4 | import gitbucket.core.service.AccountService |
4 | 5 | import gitbucket.core.service.SystemSettingsService.SystemSettings |
5 | 6 | import gitbucket.gist.controller.GistController |
6 | 7 | import gitbucket.core.plugin._ |
7 | 8 | import gitbucket.core.util.Version |
8 | | -import gitbucket.core.util.Implicits._ |
9 | 9 | import java.io.File |
10 | 10 | import javax.servlet.ServletContext |
11 | 11 | import gitbucket.gist.util.Configurations._ |
@@ -64,33 +64,16 @@ class Plugin extends gitbucket.core.plugin.Plugin { |
64 | 64 |
|
65 | 65 | class GistRepositoryFilter extends GitRepositoryFilter with AccountService { |
66 | 66 |
|
67 | | - override def filter(request: HttpServletRequest, response: HttpServletResponse, |
68 | | - settings: SystemSettings, isUpdating: Boolean): Boolean = { |
69 | | - implicit val r = request |
70 | | - |
| 67 | + override def filter(path: String, userName: Option[String], settings: SystemSettings, isUpdating: Boolean) |
| 68 | + (implicit session: Session): Boolean = { |
71 | 69 | if(isUpdating){ |
72 | | - // Allow updating to self repository only |
73 | | - val passed = for { |
74 | | - auth <- Option(request.getHeader("Authorization")) |
75 | | - Array(username, password) = decodeAuthHeader(auth).split(":", 2) |
76 | | - account <- authenticate(settings, username, password) |
77 | | - } yield { |
78 | | - request.paths match { |
79 | | - case Array(_, _, owner, _*) => owner == username || account.isAdmin |
80 | | - } |
81 | | - } |
82 | | - |
83 | | - passed getOrElse false |
| 70 | + (for { |
| 71 | + userName <- userName |
| 72 | + account <- getAccountByUserName(userName) |
| 73 | + } yield |
| 74 | + path.startsWith(userName + "/") || account.isAdmin |
| 75 | + ).getOrElse(false) |
84 | 76 | } else true |
85 | 77 | } |
86 | 78 |
|
87 | | - // TODO This method shoud be provided by gitbucket-core |
88 | | - private def decodeAuthHeader(header: String): String = { |
89 | | - try { |
90 | | - new String(new sun.misc.BASE64Decoder().decodeBuffer(header.substring(6))) |
91 | | - } catch { |
92 | | - case _: Throwable => "" |
93 | | - } |
94 | | - } |
95 | | - |
96 | 79 | } |
0 commit comments