From: James Moger Date: Sat, 16 Nov 2013 14:46:55 +0000 (-0500) Subject: Refactor access to home page class X-Git-Tag: v1.4.0~191 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a7a0b8ea01dca14602fdb49047d987c36461e861;p=gitblit.git Refactor access to home page class Change-Id: Ice5706dc0659a44f54e5bf29ca66580e3be22418 --- diff --git a/src/main/java/com/gitblit/wicket/AuthorizationStrategy.java b/src/main/java/com/gitblit/wicket/AuthorizationStrategy.java index e3774d82..a00e2e2f 100644 --- a/src/main/java/com/gitblit/wicket/AuthorizationStrategy.java +++ b/src/main/java/com/gitblit/wicket/AuthorizationStrategy.java @@ -19,6 +19,7 @@ import org.apache.wicket.Component; import org.apache.wicket.RestartResponseException; import org.apache.wicket.authorization.IUnauthorizedComponentInstantiationListener; import org.apache.wicket.authorization.strategies.page.AbstractPageAuthorizationStrategy; +import org.apache.wicket.markup.html.WebPage; import com.gitblit.GitBlit; import com.gitblit.Keys; @@ -28,13 +29,16 @@ import com.gitblit.wicket.pages.BasePage; public class AuthorizationStrategy extends AbstractPageAuthorizationStrategy implements IUnauthorizedComponentInstantiationListener { - public AuthorizationStrategy() { + Class homepageClass; + + public AuthorizationStrategy(Class homepageClass) { + this.homepageClass = homepageClass; } @SuppressWarnings({ "unchecked", "rawtypes" }) @Override protected boolean isPageAuthorized(Class pageClass) { - if (GitBlitWebApp.HOME_PAGE_CLASS.equals(pageClass)) { + if (homepageClass.equals(pageClass)) { // allow all requests to get to the HomePage with its inline // authentication form return true; @@ -79,7 +83,7 @@ public class AuthorizationStrategy extends AbstractPageAuthorizationStrategy imp public void onUnauthorizedInstantiation(Component component) { if (component instanceof BasePage) { - throw new RestartResponseException(GitBlitWebApp.HOME_PAGE_CLASS); + throw new RestartResponseException(homepageClass); } } } diff --git a/src/main/java/com/gitblit/wicket/GitBlitWebApp.java b/src/main/java/com/gitblit/wicket/GitBlitWebApp.java index 70aa1a6a..8cbda461 100644 --- a/src/main/java/com/gitblit/wicket/GitBlitWebApp.java +++ b/src/main/java/com/gitblit/wicket/GitBlitWebApp.java @@ -20,7 +20,6 @@ import java.util.Locale; import java.util.Map; import org.apache.wicket.Application; -import org.apache.wicket.Page; import org.apache.wicket.Request; import org.apache.wicket.Response; import org.apache.wicket.Session; @@ -31,7 +30,6 @@ import com.gitblit.GitBlit; import com.gitblit.Keys; import com.gitblit.utils.StringUtils; import com.gitblit.wicket.pages.ActivityPage; -import com.gitblit.wicket.pages.BasePage; import com.gitblit.wicket.pages.BlamePage; import com.gitblit.wicket.pages.BlobDiffPage; import com.gitblit.wicket.pages.BlobPage; @@ -69,7 +67,7 @@ import com.gitblit.wicket.pages.UsersPage; public class GitBlitWebApp extends WebApplication { - public final static Class HOME_PAGE_CLASS = MyDashboardPage.class; + private final Class homePageClass = MyDashboardPage.class; private final Map cacheablePages = new HashMap(); @@ -81,7 +79,7 @@ public class GitBlitWebApp extends WebApplication { boolean useAuthentication = GitBlit.getBoolean(Keys.web.authenticateViewPages, false) || GitBlit.getBoolean(Keys.web.authenticateAdminPages, false); if (useAuthentication) { - AuthorizationStrategy authStrategy = new AuthorizationStrategy(); + AuthorizationStrategy authStrategy = new AuthorizationStrategy(homePageClass); getSecuritySettings().setAuthorizationStrategy(authStrategy); getSecuritySettings().setUnauthorizedComponentInstantiationListener(authStrategy); } @@ -158,8 +156,8 @@ public class GitBlitWebApp extends WebApplication { } @Override - public Class getHomePage() { - return HOME_PAGE_CLASS; + public Class getHomePage() { + return homePageClass; } public boolean isCacheablePage(String mountPoint) { diff --git a/src/main/java/com/gitblit/wicket/pages/BasePage.java b/src/main/java/com/gitblit/wicket/pages/BasePage.java index ec69a719..9bae3783 100644 --- a/src/main/java/com/gitblit/wicket/pages/BasePage.java +++ b/src/main/java/com/gitblit/wicket/pages/BasePage.java @@ -212,7 +212,7 @@ public abstract class BasePage extends SessionPage { add(new Label("title", siteName)); } - String rootLinkUrl = GitBlit.getString(Keys.web.rootLink, urlFor(GitBlitWebApp.HOME_PAGE_CLASS, null).toString()); + String rootLinkUrl = GitBlit.getString(Keys.web.rootLink, urlFor(GitBlitWebApp.get().getHomePage(), null).toString()); ExternalLink rootLink = new ExternalLink("rootLink", rootLinkUrl); WicketUtils.setHtmlTooltip(rootLink, GitBlit.getString(Keys.web.siteName, Constants.NAME)); add(rootLink); diff --git a/src/main/java/com/gitblit/wicket/pages/DashboardPage.java b/src/main/java/com/gitblit/wicket/pages/DashboardPage.java index 5c72b8bd..46adcffe 100644 --- a/src/main/java/com/gitblit/wicket/pages/DashboardPage.java +++ b/src/main/java/com/gitblit/wicket/pages/DashboardPage.java @@ -146,7 +146,7 @@ public abstract class DashboardPage extends RootPage { PageParameters params = getPageParameters(); DropDownMenuRegistration menu = new DropDownMenuRegistration("gb.filters", - GitBlitWebApp.HOME_PAGE_CLASS); + GitBlitWebApp.get().getHomePage()); // preserve repository filter option on time choices menu.menuItems.addAll(getTimeFilterItems(params));