]> source.dussan.org Git - gitblit.git/commitdiff
Authenticate the webapp against the same realm as the git servlet.
authorJames Moger <james.moger@gitblit.com>
Thu, 14 Apr 2011 22:29:10 +0000 (18:29 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 14 Apr 2011 22:29:10 +0000 (18:29 -0400)
Right now the implementation is hard-coded to pass the realm into a
singleton.  This won't work for a WAR distribution so I will
need to figure out how to properly authenticate the webapp using form
authentication and the git servlet using basic authentication - host
against the same realm.

15 files changed:
gitblit.properties
src/com/gitblit/Constants.java
src/com/gitblit/GitBlit.java [new file with mode: 0644]
src/com/gitblit/GitBlitServer.java
src/com/gitblit/ILoginService.java [new file with mode: 0644]
src/com/gitblit/JettyLoginService.java [new file with mode: 0644]
src/com/gitblit/wicket/GitBlitWebApp.java
src/com/gitblit/wicket/GitBlitWebSession.java
src/com/gitblit/wicket/LoginPage.java
src/com/gitblit/wicket/RepositoryPage.java
src/com/gitblit/wicket/User.java
src/com/gitblit/wicket/pages/PatchPage.java
src/com/gitblit/wicket/pages/RawPage.java
src/com/gitblit/wicket/pages/RepositoriesPage.java
users.properties

index a2e9ab6661db9b766c6d1427aade29602e36591e..65f44d170d6748c533ef4a3a4af5efacc0f1d4ca 100644 (file)
@@ -32,22 +32,13 @@ authenticateWebUI = true
 # Simple user realm file to authenticate users for push/pull\r
 realmFile = users.properties\r
 \r
-# User roles for push/pull git repository access\r
-# (* is the wildcard for any role)\r
-gitRoles = *\r
-\r
-# User roles for administrative features such\r
-# as create repository, edit repository description,\r
-# and set repository owner. \r
-# (* is the wildcard for any role)\r
-adminRoles = *\r
-\r
 #\r
 # Server Settings\r
 #\r
-debug = true\r
+debugMode = true\r
 tempFolder = temp\r
 log4jPattern = %-5p %d{MM-dd HH:mm:ss.SSS}  %-20.20c{1}  %m%n\r
+\r
 # Aggressive heap management will run the garbage collector on every generated\r
 # page.  This slows down page generation but improves heap consumption. \r
 aggressiveHeapManagement = true\r
@@ -56,7 +47,13 @@ aggressiveHeapManagement = true
 # Git:Blit UI Settings\r
 #\r
 siteName =\r
+\r
+# If authenticateWebUI=true, users with "admin" role can create repositories,\r
+# create users, and edit repository metadata (owner, description, etc)\r
+#\r
+# If authenticateWebUI=false, any user can execute the aforementioned functions.  \r
 allowAdministration = true\r
+\r
 repositoriesMessage = Welcome to Git:Blit!<br>A quick and easy way to host your own Git repositories.<br>Built with <a href="http://eclipse.org/jgit">JGit</a>, <a href="http://wicket.apache.org">Wicket</a>, <a href="http://code.google.com/p/google-code-prettify/">google-code-prettify</a>, <a href="http://eclipse.org/jetty">Jetty</a>, <a href="http://www.slf4j.org">SLF4J</a>, <a href="http://logging.apache.org/log4j">Log4j</a>, and <a href="http://jcommander.org">JCommander</a>.\r
 \r
 # Use the client timezone when formatting dates.\r
index 052055a95284779c7a23e406f50009086fd22304..186193eb818eb4b1079dc597f97ca71cce57cc96 100644 (file)
@@ -5,6 +5,12 @@ public class Constants {
        public final static String NAME = "Git:Blit";\r
 \r
        public final static String VERSION = "0.0.1";\r
+       \r
+       public final static String ADMIN_ROLE = "admin";\r
+       \r
+       public final static String PULL_ROLE = "pull";\r
+       \r
+       public final static String PUSH_ROLE = "push";\r
 \r
        public static String getGitBlitVersion() {\r
                return NAME + " v" + VERSION;\r
diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java
new file mode 100644 (file)
index 0000000..2764143
--- /dev/null
@@ -0,0 +1,127 @@
+package com.gitblit;\r
+\r
+import java.io.File;\r
+import java.util.ArrayList;\r
+import java.util.Date;\r
+import java.util.List;\r
+\r
+import javax.servlet.http.Cookie;\r
+import javax.servlet.http.HttpServletRequest;\r
+\r
+import org.apache.wicket.Request;\r
+import org.apache.wicket.protocol.http.WebResponse;\r
+import org.apache.wicket.protocol.http.servlet.ServletWebRequest;\r
+import org.eclipse.jgit.errors.RepositoryNotFoundException;\r
+import org.eclipse.jgit.http.server.resolver.FileResolver;\r
+import org.eclipse.jgit.http.server.resolver.ServiceNotEnabledException;\r
+import org.eclipse.jgit.lib.Repository;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+import com.gitblit.utils.JGitUtils;\r
+import com.gitblit.wicket.User;\r
+import com.gitblit.wicket.models.RepositoryModel;\r
+\r
+public class GitBlit {\r
+\r
+       private static GitBlit gitblit;\r
+\r
+       private final Logger logger = LoggerFactory.getLogger(GitBlit.class);\r
+\r
+       private final boolean debugMode;\r
+\r
+       private final FileResolver repositoryResolver;\r
+\r
+       private final File repositories;\r
+\r
+       private final boolean exportAll;\r
+\r
+       private ILoginService loginService;\r
+\r
+       public static GitBlit self() {\r
+               if (gitblit == null) {\r
+                       gitblit = new GitBlit();\r
+               }\r
+               return gitblit;\r
+       }\r
+\r
+       private GitBlit() {\r
+               repositories = new File(StoredSettings.getString("repositoriesFolder", "repos"));\r
+               exportAll = StoredSettings.getBoolean("exportAll", true);\r
+               repositoryResolver = new FileResolver(repositories, exportAll);\r
+               debugMode = StoredSettings.getBoolean("debugMode", false);\r
+       }\r
+       \r
+       public boolean isDebugMode() {\r
+               return debugMode;\r
+       }\r
+\r
+       public void setLoginService(ILoginService loginService) {\r
+               this.loginService = loginService;\r
+       }\r
+\r
+       public User authenticate(String username, char[] password) {\r
+               if (loginService == null) {\r
+                       return null;\r
+               }\r
+               return loginService.authenticate(username, password);\r
+       }\r
+\r
+       public User authenticate(Cookie[] cookies) {\r
+               if (loginService == null) {\r
+                       return null;\r
+               }\r
+               if (cookies != null && cookies.length > 0) {\r
+                       for (Cookie cookie : cookies) {\r
+                               if (cookie.getName().equals(Constants.NAME)) {\r
+                                       String value = cookie.getValue();\r
+                                       return loginService.authenticate(value.toCharArray());\r
+                               }\r
+                       }\r
+               }\r
+               return null;\r
+       }\r
+\r
+       public void setCookie(WebResponse response, User user) {\r
+               Cookie userCookie = new Cookie(Constants.NAME, user.getCookie());\r
+               userCookie.setMaxAge(Integer.MAX_VALUE);\r
+               userCookie.setPath("/");\r
+               response.addCookie(userCookie);\r
+       }\r
+       \r
+       public List<String> getRepositoryList() {\r
+               return JGitUtils.getRepositoryList(repositories, exportAll, StoredSettings.getBoolean("nestedRepositories", true));\r
+       }\r
+\r
+       public List<RepositoryModel> getRepositories(Request request) {\r
+               List<String> list = getRepositoryList();\r
+               ServletWebRequest servletWebRequest = (ServletWebRequest) request;\r
+               HttpServletRequest req = servletWebRequest.getHttpServletRequest();\r
+\r
+               List<RepositoryModel> repositories = new ArrayList<RepositoryModel>();\r
+               for (String repo : list) {\r
+                       Repository r = getRepository(req, repo);\r
+                       String description = JGitUtils.getRepositoryDescription(r);\r
+                       String owner = JGitUtils.getRepositoryOwner(r);\r
+                       Date lastchange = JGitUtils.getLastChange(r);\r
+                       r.close();\r
+                       repositories.add(new RepositoryModel(repo, description, owner, lastchange));\r
+               }\r
+               return repositories;\r
+       }\r
+\r
+       public Repository getRepository(HttpServletRequest req, String repositoryName) {\r
+               Repository r = null;\r
+               try {\r
+                       r = repositoryResolver.open(req, repositoryName);\r
+               } catch (RepositoryNotFoundException e) {\r
+                       r = null;\r
+                       logger.error("Failed to find repository " + repositoryName);\r
+                       e.printStackTrace();\r
+               } catch (ServiceNotEnabledException e) {\r
+                       r = null;\r
+                       e.printStackTrace();\r
+               }\r
+               return r;\r
+       }\r
+}\r
index 9991a75d5160a862682be3c8997d89c289cbbcad..4f1aeccc30f727478c1154d401717734846b01ac 100644 (file)
@@ -21,7 +21,7 @@ import org.apache.wicket.protocol.http.WicketFilter;
 import org.eclipse.jetty.http.security.Constraint;\r
 import org.eclipse.jetty.security.ConstraintMapping;\r
 import org.eclipse.jetty.security.ConstraintSecurityHandler;\r
-import org.eclipse.jetty.security.HashLoginService;\r
+import org.eclipse.jetty.security.LoginService;\r
 import org.eclipse.jetty.security.authentication.BasicAuthenticator;\r
 import org.eclipse.jetty.server.Connector;\r
 import org.eclipse.jetty.server.Handler;\r
@@ -50,11 +50,6 @@ public class GitBlitServer {
 \r
        private final static Logger logger = Log.getLogger(GitBlitServer.class.getSimpleName());\r
        private final static String border_star = "***********************************************************";\r
-       private static boolean debugMode = false;\r
-\r
-       public static boolean isDebugMode() {\r
-               return debugMode;\r
-       }\r
 \r
        public static void main(String[] args) {\r
                Params params = new Params();\r
@@ -111,6 +106,9 @@ public class GitBlitServer {
         * Start Server.\r
         */\r
        private static void start(Params params) {\r
+               // instantiate GitBlit\r
+               GitBlit.self();\r
+               \r
                PatternLayout layout = new PatternLayout(StoredSettings.getString("log4jPattern", "%-5p %d{MM-dd HH:mm:ss.SSS}  %-20.20c{1}  %m%n"));\r
                org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger();\r
                rootLogger.addAppender(new ConsoleAppender(layout));\r
@@ -123,7 +121,7 @@ public class GitBlitServer {
                String osversion = System.getProperty("os.version");\r
                logger.info("Running on " + osname + " (" + osversion + ")");\r
 \r
-               if (params.debug) {\r
+               if (StoredSettings.getBoolean("debugMode", false)) {\r
                        logger.warn("DEBUG Mode");\r
                }\r
 \r
@@ -173,10 +171,9 @@ public class GitBlitServer {
                FilterHolder wicketFilter = new FilterHolder(WicketFilter.class);\r
                wicketFilter.setInitParameter(ContextParamWebApplicationFactory.APP_CLASS_PARAM, GitBlitWebApp.class.getName());\r
                wicketFilter.setInitParameter(WicketFilter.FILTER_MAPPING_PARAM, wicketPathSpec);\r
+               wicketFilter.setInitParameter(WicketFilter.IGNORE_PATHS_PARAM, "git/");\r
                rootContext.addFilter(wicketFilter, wicketPathSpec, FilterMapping.DEFAULT);\r
 \r
-               Handler handler;\r
-\r
                // Git Servlet\r
                ServletHolder gitServlet = null;\r
                String gitServletPathSpec = "/git/*";\r
@@ -184,20 +181,25 @@ public class GitBlitServer {
                        gitServlet = rootContext.addServlet(GitServlet.class, gitServletPathSpec);\r
                        gitServlet.setInitParameter("base-path", params.repositoriesFolder);\r
                        gitServlet.setInitParameter("export-all", params.exportAll ? "1" : "0");\r
-                       String realmUsers = params.realmFile;\r
-\r
-                       if (realmUsers != null && new File(realmUsers).exists() && params.authenticatePushPull) {\r
+               }\r
+               \r
+               // Login Service\r
+               LoginService loginService = null;\r
+               String realmUsers = params.realmFile;\r
+               if (realmUsers != null && new File(realmUsers).exists()) {\r
+                       logger.info("Setting up login service from " + realmUsers);\r
+                       JettyLoginService jettyLoginService = new JettyLoginService(realmUsers);\r
+                       GitBlit.self().setLoginService(jettyLoginService);\r
+                       loginService = jettyLoginService;\r
+               }\r
+               \r
+               // Determine what handler to use\r
+               Handler handler;\r
+               if (gitServlet != null) {\r
+                       if (loginService != null && params.authenticatePushPull) {\r
                                // Authenticate Pull/Push\r
-                               List<String> list = StoredSettings.getStrings("gitRoles");\r
-                               String[] roles;\r
-                               if (list.size() == 0) {\r
-                                       roles = new String[] { "*" };\r
-                               } else {\r
-                                       roles = list.toArray(new String[list.size()]);\r
-                               }\r
+                               String[] roles = new String[] { Constants.PULL_ROLE, Constants.PUSH_ROLE };\r
                                logger.info("Authentication required for git servlet pull/push access");\r
-                               logger.info("Setting up realm from " + realmUsers);\r
-                               HashLoginService loginService = new HashLoginService(Constants.NAME, realmUsers);\r
 \r
                                Constraint constraint = new Constraint();\r
                                constraint.setName("auth");\r
@@ -356,9 +358,6 @@ public class GitBlitServer {
                @Parameter(names = { "--temp" }, description = "Server temp folder")\r
                public String temp = StoredSettings.getString("tempFolder", "temp");\r
 \r
-               @Parameter(names = { "--debug" }, description = "Run server in DEBUG mode")\r
-               public Boolean debug = StoredSettings.getBoolean("debug", false);\r
-\r
                /*\r
                 * GIT Servlet Parameters\r
                 */\r
diff --git a/src/com/gitblit/ILoginService.java b/src/com/gitblit/ILoginService.java
new file mode 100644 (file)
index 0000000..ee98d8e
--- /dev/null
@@ -0,0 +1,10 @@
+package com.gitblit;\r
+\r
+import com.gitblit.wicket.User;\r
+\r
+public interface ILoginService {\r
+\r
+       User authenticate(String username, char [] password);\r
+       \r
+       User authenticate(char [] cookie);\r
+}\r
diff --git a/src/com/gitblit/JettyLoginService.java b/src/com/gitblit/JettyLoginService.java
new file mode 100644 (file)
index 0000000..93e9a19
--- /dev/null
@@ -0,0 +1,32 @@
+package com.gitblit;\r
+\r
+import org.eclipse.jetty.security.HashLoginService;\r
+import org.eclipse.jetty.server.UserIdentity;\r
+\r
+import com.gitblit.wicket.User;\r
+\r
+public class JettyLoginService extends HashLoginService implements ILoginService {\r
+\r
+       public JettyLoginService(String realmFile) {\r
+               super(Constants.NAME, realmFile);\r
+       }\r
+       \r
+       @Override\r
+       public User authenticate(String username, char[] password) {\r
+               UserIdentity identity = login(username, new String(password));\r
+               if (identity == null || identity.equals(UserIdentity.UNAUTHENTICATED_IDENTITY)) {\r
+                       return null;\r
+               }\r
+               User user = new User(username, password);\r
+               user.canAdmin(identity.isUserInRole(Constants.ADMIN_ROLE, null));\r
+               user.canClone(identity.isUserInRole(Constants.PULL_ROLE, null));\r
+               user.canPush(identity.isUserInRole(Constants.PUSH_ROLE, null));\r
+               return user;\r
+       }\r
+\r
+       @Override\r
+       public User authenticate(char [] cookie) {\r
+               // TODO cookie login\r
+               return null;\r
+       }\r
+}\r
index 2bd3179d469674c16dd2b67e6799330f4486976b..658ae67a68498c26a31587652cef52e11341da26 100644 (file)
@@ -1,36 +1,17 @@
 package com.gitblit.wicket;\r
 \r
-import java.io.File;\r
-import java.util.ArrayList;\r
-import java.util.Date;\r
-import java.util.List;\r
-\r
-import javax.servlet.http.Cookie;\r
-import javax.servlet.http.HttpServletRequest;\r
-\r
 import org.apache.wicket.Application;\r
 import org.apache.wicket.Page;\r
 import org.apache.wicket.Request;\r
 import org.apache.wicket.Response;\r
 import org.apache.wicket.Session;\r
 import org.apache.wicket.protocol.http.WebApplication;\r
-import org.apache.wicket.protocol.http.WebResponse;\r
 import org.apache.wicket.protocol.http.request.urlcompressing.UrlCompressingWebRequestProcessor;\r
-import org.apache.wicket.protocol.http.servlet.ServletWebRequest;\r
 import org.apache.wicket.request.IRequestCycleProcessor;\r
 import org.apache.wicket.request.target.coding.MixedParamUrlCodingStrategy;\r
-import org.eclipse.jgit.errors.RepositoryNotFoundException;\r
-import org.eclipse.jgit.http.server.resolver.FileResolver;\r
-import org.eclipse.jgit.http.server.resolver.ServiceNotEnabledException;\r
-import org.eclipse.jgit.lib.Repository;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
 \r
-import com.gitblit.Constants;\r
-import com.gitblit.GitBlitServer;\r
+import com.gitblit.GitBlit;\r
 import com.gitblit.StoredSettings;\r
-import com.gitblit.utils.JGitUtils;\r
-import com.gitblit.wicket.models.RepositoryModel;\r
 import com.gitblit.wicket.pages.BlobDiffPage;\r
 import com.gitblit.wicket.pages.BlobPage;\r
 import com.gitblit.wicket.pages.BranchesPage;\r
@@ -49,14 +30,6 @@ import com.gitblit.wicket.pages.TreePage;
 \r
 public class GitBlitWebApp extends WebApplication {\r
 \r
-       Logger logger = LoggerFactory.getLogger(GitBlitWebApp.class);\r
-\r
-       FileResolver repositoryResolver;\r
-\r
-       private File repositories;\r
-\r
-       private boolean exportAll;\r
-\r
        @Override\r
        public void init() {\r
                super.init();\r
@@ -92,10 +65,6 @@ public class GitBlitWebApp extends WebApplication {
                mount(new MixedParamUrlCodingStrategy("/ticgittkt", TicGitTicketPage.class, new String[] { "r", "h", "f" }));\r
 \r
                mount(new MixedParamUrlCodingStrategy("/login", LoginPage.class, new String[] {}));\r
-\r
-               repositories = new File(StoredSettings.getString("repositoriesFolder", "repos"));\r
-               exportAll = StoredSettings.getBoolean("exportAll", true);\r
-               repositoryResolver = new FileResolver(repositories, exportAll);\r
        }\r
 \r
        @Override\r
@@ -115,69 +84,11 @@ public class GitBlitWebApp extends WebApplication {
 \r
        @Override\r
        public final String getConfigurationType() {\r
-               if (GitBlitServer.isDebugMode())\r
+               if (GitBlit.self().isDebugMode())\r
                        return Application.DEVELOPMENT;\r
                return Application.DEPLOYMENT;\r
        }\r
 \r
-       public User authenticate(String username, char [] password) {\r
-               return new User(username, password);\r
-       }\r
-\r
-       public User authenticate(Cookie[] cookies) {\r
-               if (cookies != null && cookies.length > 0) {\r
-                       for (Cookie cookie:cookies) {\r
-                               if (cookie.getName().equals(Constants.NAME)) {\r
-                                       String value = cookie.getValue();\r
-                               }\r
-                       }\r
-               }\r
-               return null;\r
-       }\r
-       \r
-       public void setCookie(WebResponse response, User user) {\r
-               Cookie userCookie = new Cookie(Constants.NAME, user.getCookie());\r
-               userCookie.setMaxAge(Integer.MAX_VALUE);\r
-               userCookie.setPath("/");\r
-               response.addCookie(userCookie);\r
-       }\r
-\r
-       public List<String> getRepositoryList() {\r
-               return JGitUtils.getRepositoryList(repositories, exportAll, StoredSettings.getBoolean("nestedRepositories", true));\r
-       }\r
-\r
-       public List<RepositoryModel> getRepositories(Request request) {\r
-               List<String> list = getRepositoryList();\r
-               ServletWebRequest servletWebRequest = (ServletWebRequest) request;\r
-               HttpServletRequest req = servletWebRequest.getHttpServletRequest();\r
-\r
-               List<RepositoryModel> repositories = new ArrayList<RepositoryModel>();\r
-               for (String repo : list) {\r
-                       Repository r = getRepository(req, repo);\r
-                       String description = JGitUtils.getRepositoryDescription(r);\r
-                       String owner = JGitUtils.getRepositoryOwner(r);\r
-                       Date lastchange = JGitUtils.getLastChange(r);\r
-                       r.close();\r
-                       repositories.add(new RepositoryModel(repo, description, owner, lastchange));\r
-               }\r
-               return repositories;\r
-       }\r
-\r
-       public Repository getRepository(HttpServletRequest req, String repositoryName) {\r
-               Repository r = null;\r
-               try {\r
-                       r = repositoryResolver.open(req, repositoryName);\r
-               } catch (RepositoryNotFoundException e) {\r
-                       r = null;\r
-                       logger.error("Failed to find repository " + repositoryName);\r
-                       e.printStackTrace();\r
-               } catch (ServiceNotEnabledException e) {\r
-                       r = null;\r
-                       e.printStackTrace();\r
-               }\r
-               return r;\r
-       }\r
-\r
        public String getCloneUrl(String repositoryName) {\r
                return StoredSettings.getString("cloneUrl", "https://localhost/git/") + repositoryName;\r
        }\r
index b2106e7bb62785e11a63ff1c991cd74b3b0fafd4..34e597f049c4dbaddf4c3653c60af6372af873f0 100644 (file)
@@ -28,6 +28,13 @@ public final class GitBlitWebSession extends WebSession {
                return user != null;\r
        }\r
        \r
+       public boolean canAdmin() {\r
+               if (user == null) {\r
+                       return false;                   \r
+               }\r
+               return user.canAdmin();\r
+       }\r
+       \r
        public User getUser() {\r
                return user;\r
        }\r
index 39b428523be2be0e4a3d88b41b81f57eb05a8272..e27adc316668e65b0974dd854ac5ec012f6a2ca1 100644 (file)
@@ -18,6 +18,7 @@ import org.apache.wicket.protocol.http.WebResponse;
 import org.apache.wicket.protocol.http.servlet.ServletWebRequest;\r
 \r
 import com.gitblit.Constants;\r
+import com.gitblit.GitBlit;\r
 \r
 public class LoginPage extends WebPage {\r
 \r
@@ -58,7 +59,7 @@ public class LoginPage extends WebPage {
                        String username = LoginPage.this.username.getObject();\r
                        char [] password = LoginPage.this.password.getObject().toCharArray();\r
 \r
-                       User user = GitBlitWebApp.get().authenticate(username, password);\r
+                       User user = GitBlit.self().authenticate(username, password);\r
                        if (user == null)\r
                                error("Invalid username or password!");\r
                        else\r
@@ -72,7 +73,7 @@ public class LoginPage extends WebPage {
                // Grab cookie from Browser Session\r
                Cookie[] cookies = ((WebRequest) getRequestCycle().getRequest()).getCookies();\r
                if (cookies != null && cookies.length > 0) {\r
-                       user = GitBlitWebApp.get().authenticate(cookies);\r
+                       user = GitBlit.self().authenticate(cookies);\r
                }\r
 \r
                // Login the user\r
@@ -85,7 +86,7 @@ public class LoginPage extends WebPage {
 \r
                        // Set Cookie\r
                        WebResponse response = (WebResponse) getRequestCycle().getResponse();\r
-                       GitBlitWebApp.get().setCookie(response, user);\r
+                       GitBlit.self().setCookie(response, user);\r
                        \r
                        // track user object so that we do not have to continue\r
                        // re-authenticating on each request.\r
index 05617718be3afd95781947514babb0b0e50ea50e..8dc485a5227d8e5f5a59b62c1f603e3ed66fc52f 100644 (file)
@@ -12,6 +12,7 @@ import org.apache.wicket.protocol.http.servlet.ServletWebRequest;
 import org.eclipse.jgit.lib.Repository;\r
 import org.eclipse.jgit.revwalk.RevCommit;\r
 \r
+import com.gitblit.GitBlit;\r
 import com.gitblit.StoredSettings;\r
 import com.gitblit.utils.JGitUtils;\r
 import com.gitblit.wicket.pages.RepositoriesPage;\r
@@ -51,7 +52,7 @@ public abstract class RepositoryPage extends BasePage {
                        HttpServletRequest req = servletWebRequest.getHttpServletRequest();\r
                        req.getServerName();\r
 \r
-                       Repository r = GitBlitWebApp.get().getRepository(req, repositoryName);\r
+                       Repository r = GitBlit.self().getRepository(req, repositoryName);\r
                        if (r == null) {\r
                                error("Can not load repository " + repositoryName);\r
                                redirectToInterceptPage(new RepositoriesPage());\r
index fb49b404b11977a1f0a127416e168dff54dd687e..c23b849ca41aa5e85b55f9da8c30eca467ca415d 100644 (file)
@@ -7,12 +7,39 @@ public class User {
        \r
        private String username;\r
        private char [] password;\r
+       private boolean canAdmin = false;\r
+       private boolean canClone = false;\r
+       private boolean canPush = false;\r
        \r
        public User(String username, char [] password) {\r
                this.username = username;\r
                this.password = password;\r
        }\r
        \r
+       public void canAdmin(boolean value) {\r
+               canAdmin = value;\r
+       }\r
+       \r
+       public boolean canAdmin() {\r
+               return canAdmin;\r
+       }\r
+\r
+       public void canClone(boolean value) {\r
+               canClone = value;\r
+       }\r
+       \r
+       public boolean canClone() {\r
+               return canClone;\r
+       }\r
+       \r
+       public void canPush(boolean value) {\r
+               canPush = value;\r
+       }\r
+       \r
+       public boolean canPush() {\r
+               return canPush;\r
+       }\r
+\r
        public String getCookie() {\r
                return Build.getSHA1((Constants.NAME + username + new String(password)).getBytes());\r
        }\r
index 52790d6882c5cf3b6318dde264441c86df769ad5..c877bb6d83039a5461cfaed13fa3e439e76a4a22 100644 (file)
@@ -9,8 +9,8 @@ import org.apache.wicket.protocol.http.servlet.ServletWebRequest;
 import org.eclipse.jgit.lib.Repository;\r
 import org.eclipse.jgit.revwalk.RevCommit;\r
 \r
+import com.gitblit.GitBlit;\r
 import com.gitblit.utils.JGitUtils;\r
-import com.gitblit.wicket.GitBlitWebApp;\r
 import com.gitblit.wicket.WicketUtils;\r
 \r
 \r
@@ -31,7 +31,7 @@ public class PatchPage extends WebPage {
                HttpServletRequest req = servletWebRequest.getHttpServletRequest();\r
                req.getServerName();\r
 \r
-               Repository r = GitBlitWebApp.get().getRepository(req, repositoryName);\r
+               Repository r = GitBlit.self().getRepository(req, repositoryName);\r
                if (r == null) {\r
                        error("Can not load repository " + repositoryName);\r
                        redirectToInterceptPage(new RepositoriesPage());\r
index 18b91bcb443527f4ee64e79215ec371d515b1c1c..dc58b20880f882f4dc6106e5dd28fccb67734600 100644 (file)
@@ -13,9 +13,9 @@ import org.apache.wicket.protocol.http.servlet.ServletWebRequest;
 import org.eclipse.jgit.lib.Repository;\r
 import org.eclipse.jgit.revwalk.RevCommit;\r
 \r
+import com.gitblit.GitBlit;\r
 import com.gitblit.StoredSettings;\r
 import com.gitblit.utils.JGitUtils;\r
-import com.gitblit.wicket.GitBlitWebApp;\r
 import com.gitblit.wicket.WicketUtils;\r
 \r
 \r
@@ -36,7 +36,7 @@ public class RawPage extends WebPage {
                HttpServletRequest req = servletWebRequest.getHttpServletRequest();\r
                req.getServerName();\r
 \r
-               Repository r = GitBlitWebApp.get().getRepository(req, repositoryName);\r
+               Repository r = GitBlit.self().getRepository(req, repositoryName);\r
                if (r == null) {\r
                        error("Can not load repository " + repositoryName);\r
                        redirectToInterceptPage(new RepositoriesPage());\r
index 47d4512282c55110ef7510615cc1dfa5e55a91e6..3a43b0d9aa4e1c28d7aac818488d76cf52cd18ae 100644 (file)
@@ -17,10 +17,11 @@ import org.apache.wicket.markup.repeater.data.DataView;
 import org.apache.wicket.model.IModel;\r
 import org.apache.wicket.model.Model;\r
 \r
+import com.gitblit.GitBlit;\r
 import com.gitblit.StoredSettings;\r
 import com.gitblit.utils.Utils;\r
 import com.gitblit.wicket.BasePage;\r
-import com.gitblit.wicket.GitBlitWebApp;\r
+import com.gitblit.wicket.GitBlitWebSession;\r
 import com.gitblit.wicket.LinkPanel;\r
 import com.gitblit.wicket.WicketUtils;\r
 import com.gitblit.wicket.models.RepositoryModel;\r
@@ -32,14 +33,22 @@ public class RepositoriesPage extends BasePage {
                super();\r
                setupPage("", "");\r
                \r
+               boolean showAdmin = false;\r
+               if (StoredSettings.getBoolean("authenticateWebUI", true)) {\r
+                       boolean allowAdmin = StoredSettings.getBoolean("allowAdministration", false);\r
+                       showAdmin = allowAdmin && GitBlitWebSession.get().canAdmin(); \r
+               } else {\r
+                       showAdmin = StoredSettings.getBoolean("allowAdministration", false);\r
+               }\r
+               \r
                Fragment adminLinks = new Fragment("adminPanel", "adminLinks", this);\r
                adminLinks.add(new BookmarkablePageLink<Void>("newRepository", RepositoriesPage.class));\r
-               adminLinks.add(new BookmarkablePageLink<Void>("newUser", RepositoriesPage.class));\r
-               add(adminLinks.setVisible(StoredSettings.getBoolean("allowAdministration", false)));\r
+               adminLinks.add(new BookmarkablePageLink<Void>("newUser", RepositoriesPage.class));              \r
+               add(adminLinks.setVisible(showAdmin));\r
                \r
                add(new Label("repositoriesMessage", StoredSettings.getString("repositoriesMessage", "")).setEscapeModelStrings(false));\r
 \r
-               List<RepositoryModel> rows = GitBlitWebApp.get().getRepositories(getRequest());\r
+               List<RepositoryModel> rows = GitBlit.self().getRepositories(getRequest());\r
                DataProvider dp = new DataProvider(rows);\r
                DataView<RepositoryModel> dataView = new DataView<RepositoryModel>("repository", dp) {\r
                        private static final long serialVersionUID = 1L;\r
index 7f4fd7462c4407a9f1c0d9808b502591eb9a358d..eddad82585007750eb240aa788694f366c8bc8b6 100644 (file)
@@ -1 +1,2 @@
-test: test\r
+test: test,pull\r
+admin: admin,pull,push,admin\r