summaryrefslogtreecommitdiffstats
path: root/src/com/gitblit/wicket/pages
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2011-06-25 08:57:29 -0400
committerJames Moger <james.moger@gitblit.com>2011-06-25 08:57:29 -0400
commit85c2e6eb34215e2242e388a8f8b7173a14b96ad3 (patch)
treeb3d3d0b5f4b9c57d99be39ebda3e944aa22e98d4 /src/com/gitblit/wicket/pages
parent0fe70c1cf434f492286e01e8528322134a10281a (diff)
downloadgitblit-85c2e6eb34215e2242e388a8f8b7173a14b96ad3.tar.gz
gitblit-85c2e6eb34215e2242e388a8f8b7173a14b96ad3.zip
Big push for first release.
* Build script overhaul including building & publishing GO, WAR, Docs, and Site. * Restored JGit 0.12.1 dependency and backported Blame. Got tired of waiting for JGit 1.0.0 Maven artifacts. * Changed Summary Page layout * Optional cookie authentication * Added icons for log, tags, and branches panels. * Show last commit author and short message on branches panel. * Unit testing. * Documentation.
Diffstat (limited to 'src/com/gitblit/wicket/pages')
-rw-r--r--src/com/gitblit/wicket/pages/BasePage.java46
-rw-r--r--src/com/gitblit/wicket/pages/CommitPage.java4
-rw-r--r--src/com/gitblit/wicket/pages/DocsPage.java4
-rw-r--r--src/com/gitblit/wicket/pages/EditUserPage.java3
-rw-r--r--src/com/gitblit/wicket/pages/LogPage.java2
-rw-r--r--src/com/gitblit/wicket/pages/LoginPage.java31
-rw-r--r--src/com/gitblit/wicket/pages/LogoutPage.java7
-rw-r--r--src/com/gitblit/wicket/pages/RepositoryPage.java9
-rw-r--r--src/com/gitblit/wicket/pages/SummaryPage.html12
-rw-r--r--src/com/gitblit/wicket/pages/SummaryPage.java17
10 files changed, 100 insertions, 35 deletions
diff --git a/src/com/gitblit/wicket/pages/BasePage.java b/src/com/gitblit/wicket/pages/BasePage.java
index 5a0eb90f..06d54837 100644
--- a/src/com/gitblit/wicket/pages/BasePage.java
+++ b/src/com/gitblit/wicket/pages/BasePage.java
@@ -19,13 +19,17 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TimeZone;
+import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import org.apache.wicket.PageParameters;
import org.apache.wicket.RestartResponseAtInterceptPageException;
+import org.apache.wicket.RestartResponseException;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
+import org.apache.wicket.protocol.http.WebRequest;
+import org.apache.wicket.protocol.http.WebResponse;
import org.apache.wicket.protocol.http.servlet.ServletWebRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,6 +38,7 @@ import com.gitblit.Constants;
import com.gitblit.Constants.AccessRestrictionType;
import com.gitblit.GitBlit;
import com.gitblit.Keys;
+import com.gitblit.models.UserModel;
import com.gitblit.wicket.GitBlitWebSession;
import com.gitblit.wicket.WicketUtils;
import com.gitblit.wicket.panels.LinkPanel;
@@ -45,14 +50,40 @@ public abstract class BasePage extends WebPage {
public BasePage() {
super();
logger = LoggerFactory.getLogger(getClass());
+ loginByCookie();
}
public BasePage(PageParameters params) {
super(params);
logger = LoggerFactory.getLogger(getClass());
+ loginByCookie();
+ }
+
+ private void loginByCookie() {
+ if (!GitBlit.getBoolean(Keys.web.allowCookieAuthentication, false)) {
+ return;
+ }
+ UserModel user = null;
+
+ // Grab cookie from Browser Session
+ Cookie[] cookies = ((WebRequest) getRequestCycle().getRequest()).getCookies();
+ if (cookies != null && cookies.length > 0) {
+ user = GitBlit.self().authenticate(cookies);
+ }
+
+ // Login the user
+ if (user != null) {
+ // Set the user into the session
+ GitBlitWebSession.get().setUser(user);
+
+ // Set Cookie
+ WebResponse response = (WebResponse) getRequestCycle().getResponse();
+ GitBlit.self().setCookie(response, user);
+ }
}
protected void setupPage(String repositoryName, String pageName) {
+
if (repositoryName != null && repositoryName.trim().length() > 0) {
add(new Label("title", getServerName() + " - " + repositoryName));
} else {
@@ -122,7 +153,7 @@ public abstract class BasePage extends WebPage {
HttpServletRequest req = servletWebRequest.getHttpServletRequest();
return req.getServerName();
}
-
+
public void warn(String message, Throwable t) {
logger.warn(message, t);
}
@@ -131,7 +162,7 @@ public abstract class BasePage extends WebPage {
logger.error(message);
if (redirect) {
GitBlitWebSession.get().cacheErrorMessage(message);
- throw new RestartResponseAtInterceptPageException(getApplication().getHomePage());
+ throw new RestartResponseException(getApplication().getHomePage());
} else {
super.error(message);
}
@@ -141,9 +172,18 @@ public abstract class BasePage extends WebPage {
logger.error(message, t);
if (redirect) {
GitBlitWebSession.get().cacheErrorMessage(message);
- throw new RestartResponseAtInterceptPageException(getApplication().getHomePage());
+ throw new RestartResponseException(getApplication().getHomePage());
} else {
super.error(message);
}
}
+
+ public void authenticationError(String message) {
+ logger.error(message);
+ if (GitBlitWebSession.get().isLoggedIn()) {
+ error(message, true);
+ } else {
+ throw new RestartResponseAtInterceptPageException(LoginPage.class);
+ }
+ }
}
diff --git a/src/com/gitblit/wicket/pages/CommitPage.java b/src/com/gitblit/wicket/pages/CommitPage.java
index a34917b6..3e3dcb8b 100644
--- a/src/com/gitblit/wicket/pages/CommitPage.java
+++ b/src/com/gitblit/wicket/pages/CommitPage.java
@@ -128,8 +128,8 @@ public class CommitPage extends RepositoryPage {
SearchType.AUTHOR));
item.add(WicketUtils.createTimestampLabel("authorDate", entry.notesRef
.getAuthorIdent().getWhen(), getTimeZone()));
- item.add(new Label("noteContent", GitBlit.self().processCommitMessage(repositoryName, entry.content))
- .setEscapeModelStrings(false));
+ item.add(new Label("noteContent", GitBlit.self().processCommitMessage(
+ repositoryName, entry.content)).setEscapeModelStrings(false));
}
};
add(notesView.setVisible(notes.size() > 0));
diff --git a/src/com/gitblit/wicket/pages/DocsPage.java b/src/com/gitblit/wicket/pages/DocsPage.java
index 2f899bbe..40518b5c 100644
--- a/src/com/gitblit/wicket/pages/DocsPage.java
+++ b/src/com/gitblit/wicket/pages/DocsPage.java
@@ -64,8 +64,8 @@ public class DocsPage extends RepositoryPage {
.newPathParameter(repositoryName, entry.commitId, entry.path)));
item.add(new BookmarkablePageLink<Void>("raw", RawPage.class, WicketUtils
.newPathParameter(repositoryName, entry.commitId, entry.path)));
- item.add(new BookmarkablePageLink<Void>("blame", BlamePage.class,
- WicketUtils.newPathParameter(repositoryName, entry.commitId, entry.path)));
+ item.add(new BookmarkablePageLink<Void>("blame", BlamePage.class, WicketUtils
+ .newPathParameter(repositoryName, entry.commitId, entry.path)));
item.add(new BookmarkablePageLink<Void>("history", HistoryPage.class, WicketUtils
.newPathParameter(repositoryName, entry.commitId, entry.path)));
WicketUtils.setAlternatingBackground(item, counter);
diff --git a/src/com/gitblit/wicket/pages/EditUserPage.java b/src/com/gitblit/wicket/pages/EditUserPage.java
index 63916276..8f68ac28 100644
--- a/src/com/gitblit/wicket/pages/EditUserPage.java
+++ b/src/com/gitblit/wicket/pages/EditUserPage.java
@@ -130,7 +130,8 @@ public class EditUserPage extends BasePage {
String type = GitBlit.getString(Keys.realm.passwordStorage, "md5");
if (type.equalsIgnoreCase("md5")) {
// store MD5 digest of password
- userModel.password = StringUtils.MD5_TYPE + StringUtils.getMD5(userModel.password);
+ userModel.password = StringUtils.MD5_TYPE
+ + StringUtils.getMD5(userModel.password);
}
}
diff --git a/src/com/gitblit/wicket/pages/LogPage.java b/src/com/gitblit/wicket/pages/LogPage.java
index 2cd787c7..c012538f 100644
--- a/src/com/gitblit/wicket/pages/LogPage.java
+++ b/src/com/gitblit/wicket/pages/LogPage.java
@@ -27,7 +27,7 @@ public class LogPage extends RepositoryPage {
super(params);
addSyndicationDiscoveryLink();
-
+
int pageNumber = WicketUtils.getPage(params);
int prevPage = Math.max(0, pageNumber - 1);
int nextPage = pageNumber + 1;
diff --git a/src/com/gitblit/wicket/pages/LoginPage.java b/src/com/gitblit/wicket/pages/LoginPage.java
index 971ba327..6ee72db3 100644
--- a/src/com/gitblit/wicket/pages/LoginPage.java
+++ b/src/com/gitblit/wicket/pages/LoginPage.java
@@ -15,7 +15,10 @@
*/
package com.gitblit.wicket.pages;
+import javax.servlet.http.Cookie;
+
import org.apache.wicket.PageParameters;
+import org.apache.wicket.RestartResponseException;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.PasswordTextField;
@@ -24,6 +27,8 @@ import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
+import org.apache.wicket.protocol.http.WebRequest;
+import org.apache.wicket.protocol.http.WebResponse;
import com.gitblit.Constants;
import com.gitblit.GitBlit;
@@ -42,8 +47,11 @@ public class LoginPage extends WebPage {
// If we are already logged in because user directly accessed
// the login url, redirect to the home page
if (GitBlitWebSession.get().isLoggedIn()) {
- setRedirect(true);
- setResponsePage(getApplication().getHomePage());
+ throw new RestartResponseException(getApplication().getHomePage());
+ }
+
+ if (GitBlit.getBoolean(Keys.web.allowCookieAuthentication, false)) {
+ loginByCookie();
}
add(new Label("title", GitBlit.getString(Keys.web.siteName, Constants.NAME)));
@@ -72,11 +80,30 @@ public class LoginPage extends WebPage {
add(loginForm);
}
+ private void loginByCookie() {
+ UserModel user = null;
+
+ // Grab cookie from Browser Session
+ Cookie[] cookies = ((WebRequest) getRequestCycle().getRequest()).getCookies();
+ if (cookies != null && cookies.length > 0) {
+ user = GitBlit.self().authenticate(cookies);
+ }
+
+ // Login the user
+ loginUser(user);
+ }
+
private void loginUser(UserModel user) {
if (user != null) {
// Set the user into the session
GitBlitWebSession.get().setUser(user);
+ // Set Cookie
+ if (GitBlit.getBoolean(Keys.web.allowCookieAuthentication, false)) {
+ WebResponse response = (WebResponse) getRequestCycle().getResponse();
+ GitBlit.self().setCookie(response, user);
+ }
+
if (!continueToOriginalDestination()) {
// Redirect to home page
setResponsePage(getApplication().getHomePage());
diff --git a/src/com/gitblit/wicket/pages/LogoutPage.java b/src/com/gitblit/wicket/pages/LogoutPage.java
index 05beab3c..b049e8e0 100644
--- a/src/com/gitblit/wicket/pages/LogoutPage.java
+++ b/src/com/gitblit/wicket/pages/LogoutPage.java
@@ -16,11 +16,16 @@
package com.gitblit.wicket.pages;
import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.protocol.http.WebResponse;
+
+import com.gitblit.GitBlit;
+import com.gitblit.wicket.GitBlitWebSession;
public class LogoutPage extends WebPage {
public LogoutPage() {
- getSession().invalidate();
+ GitBlitWebSession.get().invalidate();
+ GitBlit.self().setCookie(((WebResponse) getResponse()), null);
setRedirect(true);
setResponsePage(getApplication().getHomePage());
}
diff --git a/src/com/gitblit/wicket/pages/RepositoryPage.java b/src/com/gitblit/wicket/pages/RepositoryPage.java
index 00ed7554..22d3323a 100644
--- a/src/com/gitblit/wicket/pages/RepositoryPage.java
+++ b/src/com/gitblit/wicket/pages/RepositoryPage.java
@@ -15,6 +15,7 @@
*/
package com.gitblit.wicket.pages;
+import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -205,7 +206,7 @@ public abstract class RepositoryPage extends BasePage {
RepositoryModel model = GitBlit.self().getRepositoryModel(
GitBlitWebSession.get().getUser(), repositoryName);
if (model == null) {
- error("Unauthorized access for repository " + repositoryName, true);
+ authenticationError("Unauthorized access for repository " + repositoryName);
return null;
}
m = model;
@@ -333,7 +334,9 @@ public abstract class RepositoryPage extends BasePage {
return WicketUtils.newPathParameter(repositoryName, objectId, path);
}
- private static class PageRegistration {
+ private static class PageRegistration implements Serializable {
+ private static final long serialVersionUID = 1L;
+
final String translationKey;
final Class<? extends BasePage> pageClass;
@@ -343,7 +346,7 @@ public abstract class RepositoryPage extends BasePage {
}
}
- private static class SearchForm extends StatelessForm<Void> {
+ private static class SearchForm extends StatelessForm<Void> implements Serializable {
private static final long serialVersionUID = 1L;
private final String repositoryName;
diff --git a/src/com/gitblit/wicket/pages/SummaryPage.html b/src/com/gitblit/wicket/pages/SummaryPage.html
index bbf89798..35ad3477 100644
--- a/src/com/gitblit/wicket/pages/SummaryPage.html
+++ b/src/com/gitblit/wicket/pages/SummaryPage.html
@@ -32,15 +32,11 @@
<!-- commits -->
<div style="padding-bottom:10px;" wicket:id="commitsPanel">[commits panel]</div>
- <!-- branches -->
- <div style="padding-bottom:10px;width:400px; float:left;">
- <div wicket:id="branchesPanel">[branches panel]</div>
- </div>
-
<!-- tags -->
- <div style="padding-bottom:10px;margin-left:405px;">
- <div wicket:id="tagsPanel">[tags panel]</div>
- </div>
+ <div style="padding-bottom:10px;" wicket:id="tagsPanel">[tags panel]</div>
+
+ <!-- branches -->
+ <div style="padding-bottom:10px;" wicket:id="branchesPanel">[branches panel]</div>
<!-- markdown readme -->
<div wicket:id="readme" class="markdown" style="clear:both;padding-bottom:5px;"></div>
diff --git a/src/com/gitblit/wicket/pages/SummaryPage.java b/src/com/gitblit/wicket/pages/SummaryPage.java
index e31375c0..39b8a97e 100644
--- a/src/com/gitblit/wicket/pages/SummaryPage.java
+++ b/src/com/gitblit/wicket/pages/SummaryPage.java
@@ -58,18 +58,11 @@ public class SummaryPage extends RepositoryPage {
public SummaryPage(PageParameters params) {
super(params);
- int numCommitsDef = 20;
- int numRefsDef = 5;
-
- int numberCommits = GitBlit.getInteger(Keys.web.summaryCommitCount, numCommitsDef);
+ int numberCommits = GitBlit.getInteger(Keys.web.summaryCommitCount, 20);
if (numberCommits <= 0) {
- numberCommits = numCommitsDef;
- }
-
- int numberRefs = GitBlit.getInteger(Keys.web.summaryRefsCount, numRefsDef);
- if (numberRefs <= 0) {
- numberRefs = numRefsDef;
+ numberCommits = 20;
}
+ int numberRefs = GitBlit.getInteger(Keys.web.summaryRefsCount, 5);
Repository r = getRepository();
List<Metric> metrics = null;
@@ -78,7 +71,7 @@ public class SummaryPage extends RepositoryPage {
metrics = MetricUtils.getDateMetrics(r, null, true, null);
metricsTotal = metrics.remove(0);
}
-
+
addSyndicationDiscoveryLink();
// repository description
@@ -121,7 +114,7 @@ public class SummaryPage extends RepositoryPage {
add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
}
StringBuilder sb = new StringBuilder();
- sb.append(WicketUtils.getHostURL(getRequestCycle().getRequest()));
+ sb.append(WicketUtils.getHostURL(getRequestCycle().getRequest()));
sb.append(Constants.GIT_PATH);
sb.append(repositoryName);
repositoryUrls.add(sb.toString());