]> source.dussan.org Git - gitblit.git/commitdiff
Refactor access to home page class
authorJames Moger <james.moger@gitblit.com>
Sat, 16 Nov 2013 14:46:55 +0000 (09:46 -0500)
committerJames Moger <james.moger@gitblit.com>
Tue, 26 Nov 2013 21:07:04 +0000 (16:07 -0500)
Change-Id: Ice5706dc0659a44f54e5bf29ca66580e3be22418

src/main/java/com/gitblit/wicket/AuthorizationStrategy.java
src/main/java/com/gitblit/wicket/GitBlitWebApp.java
src/main/java/com/gitblit/wicket/pages/BasePage.java
src/main/java/com/gitblit/wicket/pages/DashboardPage.java

index e3774d82fd5f0fa6c8f9916aab1f84b8f1889819..a00e2e2f5249cb18246cc6c69ebd9b46ceb6252d 100644 (file)
@@ -19,6 +19,7 @@ import org.apache.wicket.Component;
 import org.apache.wicket.RestartResponseException;\r
 import org.apache.wicket.authorization.IUnauthorizedComponentInstantiationListener;\r
 import org.apache.wicket.authorization.strategies.page.AbstractPageAuthorizationStrategy;\r
+import org.apache.wicket.markup.html.WebPage;\r
 \r
 import com.gitblit.GitBlit;\r
 import com.gitblit.Keys;\r
@@ -28,13 +29,16 @@ import com.gitblit.wicket.pages.BasePage;
 public class AuthorizationStrategy extends AbstractPageAuthorizationStrategy implements\r
                IUnauthorizedComponentInstantiationListener {\r
 \r
-       public AuthorizationStrategy() {\r
+       Class<? extends WebPage> homepageClass;\r
+\r
+       public AuthorizationStrategy(Class<? extends WebPage> homepageClass) {\r
+               this.homepageClass = homepageClass;\r
        }\r
 \r
        @SuppressWarnings({ "unchecked", "rawtypes" })\r
        @Override\r
        protected boolean isPageAuthorized(Class pageClass) {\r
-               if (GitBlitWebApp.HOME_PAGE_CLASS.equals(pageClass)) {\r
+               if (homepageClass.equals(pageClass)) {\r
                        // allow all requests to get to the HomePage with its inline\r
                        // authentication form\r
                        return true;\r
@@ -79,7 +83,7 @@ public class AuthorizationStrategy extends AbstractPageAuthorizationStrategy imp
        public void onUnauthorizedInstantiation(Component component) {\r
 \r
                if (component instanceof BasePage) {\r
-                       throw new RestartResponseException(GitBlitWebApp.HOME_PAGE_CLASS);\r
+                       throw new RestartResponseException(homepageClass);\r
                }\r
        }\r
 }\r
index 70aa1a6a7174ccd5a893e9d64159d7f1409279a7..8cbda461453f32ef58c0aec1d9de8b7b2018ca87 100644 (file)
@@ -20,7 +20,6 @@ import java.util.Locale;
 import java.util.Map;\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
@@ -31,7 +30,6 @@ import com.gitblit.GitBlit;
 import com.gitblit.Keys;\r
 import com.gitblit.utils.StringUtils;\r
 import com.gitblit.wicket.pages.ActivityPage;\r
-import com.gitblit.wicket.pages.BasePage;\r
 import com.gitblit.wicket.pages.BlamePage;\r
 import com.gitblit.wicket.pages.BlobDiffPage;\r
 import com.gitblit.wicket.pages.BlobPage;\r
@@ -69,7 +67,7 @@ import com.gitblit.wicket.pages.UsersPage;
 \r
 public class GitBlitWebApp extends WebApplication {\r
 \r
-       public final static Class<? extends BasePage> HOME_PAGE_CLASS = MyDashboardPage.class;\r
+       private final Class<? extends WebPage> homePageClass = MyDashboardPage.class;\r
 \r
        private final Map<String, CacheControl> cacheablePages = new HashMap<String, CacheControl>();\r
 \r
@@ -81,7 +79,7 @@ public class GitBlitWebApp extends WebApplication {
                boolean useAuthentication = GitBlit.getBoolean(Keys.web.authenticateViewPages, false)\r
                                || GitBlit.getBoolean(Keys.web.authenticateAdminPages, false);\r
                if (useAuthentication) {\r
-                       AuthorizationStrategy authStrategy = new AuthorizationStrategy();\r
+                       AuthorizationStrategy authStrategy = new AuthorizationStrategy(homePageClass);\r
                        getSecuritySettings().setAuthorizationStrategy(authStrategy);\r
                        getSecuritySettings().setUnauthorizedComponentInstantiationListener(authStrategy);\r
                }\r
@@ -158,8 +156,8 @@ public class GitBlitWebApp extends WebApplication {
        }\r
 \r
        @Override\r
-       public Class<? extends Page> getHomePage() {\r
-               return HOME_PAGE_CLASS;\r
+       public Class<? extends WebPage> getHomePage() {\r
+               return homePageClass;\r
        }\r
 \r
        public boolean isCacheablePage(String mountPoint) {\r
index ec69a7198cf69ae77ffc2099169d9963cc94e7b4..9bae378364e5a14869d3610392d0c20a3f4bbb1d 100644 (file)
@@ -212,7 +212,7 @@ public abstract class BasePage extends SessionPage {
                        add(new Label("title", siteName));\r
                }\r
 \r
-               String rootLinkUrl = GitBlit.getString(Keys.web.rootLink, urlFor(GitBlitWebApp.HOME_PAGE_CLASS, null).toString());\r
+               String rootLinkUrl = GitBlit.getString(Keys.web.rootLink, urlFor(GitBlitWebApp.get().getHomePage(), null).toString());\r
                ExternalLink rootLink = new ExternalLink("rootLink", rootLinkUrl);\r
                WicketUtils.setHtmlTooltip(rootLink, GitBlit.getString(Keys.web.siteName, Constants.NAME));\r
                add(rootLink);\r
index 5c72b8bd09815e16df94f2ecb9196dbd392a0145..46adcffeaeb5933e8e1485376e7cbd72545b137f 100644 (file)
@@ -146,7 +146,7 @@ public abstract class DashboardPage extends RootPage {
                PageParameters params = getPageParameters();\r
 \r
                DropDownMenuRegistration menu = new DropDownMenuRegistration("gb.filters",\r
-                               GitBlitWebApp.HOME_PAGE_CLASS);\r
+                               GitBlitWebApp.get().getHomePage());\r
 \r
                // preserve repository filter option on time choices\r
                menu.menuItems.addAll(getTimeFilterItems(params));\r