]> source.dussan.org Git - gitblit.git/commitdiff
More flexible authentication. Anonymous view, authenticated admin.
authorJames Moger <james.moger@gitblit.com>
Sat, 16 Apr 2011 13:27:57 +0000 (09:27 -0400)
committerJames Moger <james.moger@gitblit.com>
Sat, 16 Apr 2011 13:27:57 +0000 (09:27 -0400)
gitblit.properties
src/com/gitblit/wicket/AuthorizationStrategy.java
src/com/gitblit/wicket/BasePage.java
src/com/gitblit/wicket/GitBlitWebApp.java
src/com/gitblit/wicket/pages/RepositoriesPage.java

index 1adadc8a4ac9f8cd279d3a04c260c82d2db7d803..a4828108d53d81f00bf291ad85d3d50774ab8bbe 100644 (file)
@@ -26,8 +26,11 @@ git.cloneUrl = https://localhost/git/
 # Require authentication for http/https push/pull access of git repositories\r
 git.authenticate = true\r
 \r
-# Require authentication to see the web ui\r
-web.authenticate = true\r
+# Require authentication to see everything but the admin pages\r
+web.authenticateViewPages = false\r
+\r
+# Require admin authentication for the admin functions and pages\r
+web.authenticateAdminPages = true\r
 \r
 # Simple user realm file to authenticate users\r
 server.realmFile = users.properties\r
index 0a9d652b31dbd95713058f67d28e5aa2e38c559f..3e7df36bfd642f15dc3f4ca2221963d44491feee 100644 (file)
@@ -5,6 +5,8 @@ import org.apache.wicket.RestartResponseAtInterceptPageException;
 import org.apache.wicket.authorization.IUnauthorizedComponentInstantiationListener;\r
 import org.apache.wicket.authorization.strategies.page.AbstractPageAuthorizationStrategy;\r
 \r
+import com.gitblit.GitBlit;\r
+import com.gitblit.Keys;\r
 import com.gitblit.wicket.pages.RepositoriesPage;\r
 \r
 public class AuthorizationStrategy extends AbstractPageAuthorizationStrategy implements IUnauthorizedComponentInstantiationListener {\r
@@ -16,12 +18,34 @@ public class AuthorizationStrategy extends AbstractPageAuthorizationStrategy imp
        @Override\r
        protected boolean isPageAuthorized(Class pageClass) {\r
                if (BasePage.class.isAssignableFrom(pageClass)) {\r
-                       GitBlitWebSession session = GitBlitWebSession.get();\r
-                       if (!session.isLoggedIn())\r
+                       boolean authenticateView = GitBlit.self().settings().getBoolean(Keys.web.authenticateViewPages, true);\r
+                       boolean authenticateAdmin = GitBlit.self().settings().getBoolean(Keys.web.authenticateAdminPages, true);\r
+                       boolean allowAdmin = GitBlit.self().settings().getBoolean(Keys.web.allowAdministration, true);\r
+                       \r
+                       GitBlitWebSession session = GitBlitWebSession.get();                    \r
+                       if (authenticateView && !session.isLoggedIn()) {\r
+                               // authentication required\r
                                return false;\r
+                       }\r
+                       \r
                        User user = session.getUser();\r
                        if (pageClass.isAnnotationPresent(AdminPage.class)) {\r
-                               return user.canAdmin();\r
+                               // admin page\r
+                               if (allowAdmin) {\r
+                                       if (authenticateAdmin) {\r
+                                               // authenticate admin\r
+                                               if (user != null) {\r
+                                                       return user.canAdmin();\r
+                                               }\r
+                                               return false;\r
+                                       } else {\r
+                                               // no admin authentication required\r
+                                               return true;\r
+                                       }\r
+                               } else {\r
+                                       //admin prohibited\r
+                                       return false;\r
+                               }\r
                        }\r
                }\r
                return true;\r
index 2540ce1870438a760debf546ccdd20d7db9b6b8f..33feacb34a7f5752c97580655d498430509c2c2b 100644 (file)
@@ -46,10 +46,15 @@ public abstract class BasePage extends WebPage {
                add(new Label("pageName", pageName));\r
 \r
                // footer\r
-               User user = null;\r
-               if (GitBlit.self().settings().getBoolean(Keys.web.authenticate, true)) {\r
-                       user = GitBlitWebSession.get().getUser();\r
-                       add(new LinkPanel("userPanel", null, getString("gb.logout") + " " + user.toString(), LogoutPage.class));\r
+               if (GitBlit.self().settings().getBoolean(Keys.web.authenticateViewPages, true)\r
+                               || GitBlit.self().settings().getBoolean(Keys.web.authenticateAdminPages, true)) {\r
+                       if (GitBlitWebSession.get().isLoggedIn()) {\r
+                               // logout\r
+                               add(new LinkPanel("userPanel", null, getString("gb.logout") + " " + GitBlitWebSession.get().getUser().toString(), LogoutPage.class));\r
+                       } else {\r
+                               // login\r
+                               add(new LinkPanel("userPanel", null, getString("gb.login"), LoginPage.class));                          \r
+                       }\r
                } else {\r
                        add(new Label("userPanel", ""));\r
                }\r
index b70c95f803810ef0aeec3593f64e0311bb6bcdb0..29d6b515eb992b307d282ef0bfcd6fbba5cfee67 100644 (file)
@@ -35,7 +35,8 @@ public class GitBlitWebApp extends WebApplication {
                super.init();\r
 \r
                // Setup page authorization mechanism\r
-               if (GitBlit.self().settings().getBoolean(Keys.web.authenticate, false)) {\r
+               boolean useAuthentication = GitBlit.self().settings().getBoolean(Keys.web.authenticateViewPages, false) || GitBlit.self().settings().getBoolean(Keys.web.authenticateAdminPages, false);\r
+               if (useAuthentication) {\r
                        AuthorizationStrategy authStrategy = new AuthorizationStrategy();\r
                        getSecuritySettings().setAuthorizationStrategy(authStrategy);\r
                        getSecuritySettings().setUnauthorizedComponentInstantiationListener(authStrategy);\r
@@ -65,7 +66,7 @@ public class GitBlitWebApp extends WebApplication {
                mount(new MixedParamUrlCodingStrategy("/ticgittkt", TicGitTicketPage.class, new String[] { "r", "h", "f" }));\r
 \r
                // setup login/logout urls, if we are using authentication\r
-               if (GitBlit.self().settings().getBoolean(Keys.web.authenticate, true)) {\r
+               if (useAuthentication) {\r
                        mount(new MixedParamUrlCodingStrategy("/login", LoginPage.class, new String[] {}));\r
                        mount(new MixedParamUrlCodingStrategy("/logout", LogoutPage.class, new String[] {}));\r
                }\r
index fd7ab52d3c76e941c131f72cd600eb5f49bbc0bf..a0f7299f59bf347d4c3fa8fff7b9ab5e9b98ceae 100644 (file)
@@ -33,7 +33,7 @@ public class RepositoriesPage extends BasePage {
                setupPage("", "");\r
 \r
                boolean showAdmin = false;\r
-               if (GitBlit.self().settings().getBoolean(Keys.web.authenticate, true)) {\r
+               if (GitBlit.self().settings().getBoolean(Keys.web.authenticateAdminPages, true)) {\r
                        boolean allowAdmin = GitBlit.self().settings().getBoolean(Keys.web.allowAdministration, false);\r
                        showAdmin = allowAdmin && GitBlitWebSession.get().canAdmin();\r
                } else {\r