From 9effe1630d97039b3e01cd9b58ed07e75be1d63c Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Mon, 25 Feb 2013 08:40:30 -0500
Subject: [PATCH] Merge pull request #75 from thefake/master

---
 src/com/gitblit/wicket/pages/BasePage.java |   59 ++++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 44 insertions(+), 15 deletions(-)

diff --git a/src/com/gitblit/wicket/pages/BasePage.java b/src/com/gitblit/wicket/pages/BasePage.java
index 48a872a..c733c99 100644
--- a/src/com/gitblit/wicket/pages/BasePage.java
+++ b/src/com/gitblit/wicket/pages/BasePage.java
@@ -29,7 +29,6 @@
 import java.util.TimeZone;
 import java.util.regex.Pattern;
 
-import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.wicket.Application;
@@ -55,6 +54,7 @@
 import com.gitblit.Constants;
 import com.gitblit.Constants.AccessPermission;
 import com.gitblit.Constants.AccessRestrictionType;
+import com.gitblit.Constants.AuthorizationControl;
 import com.gitblit.Constants.FederationStrategy;
 import com.gitblit.GitBlit;
 import com.gitblit.Keys;
@@ -98,6 +98,10 @@
 		return GitBlitWebSession.get().getLocale().getLanguage();
 	}
 	
+	protected String getCountryCode() {
+		return GitBlitWebSession.get().getLocale().getCountry().toLowerCase();
+	}
+	
 	protected TimeUtils getTimeUtils() {
 		if (timeUtils == null) {
 			ResourceBundle bundle;		
@@ -130,19 +134,21 @@
 	}	
 
 	private void login() {
-		Cookie[] cookies = ((WebRequest) getRequestCycle().getRequest()).getCookies();
-		UserModel user = null;
-		if (GitBlit.self().allowCookieAuthentication() && cookies != null && cookies.length > 0) {
-			// Grab cookie from Browser Session
-			user = GitBlit.self().authenticate(cookies);
-		} else {
-			user = GitBlit.self().authenticate(((WebRequest) getRequestCycle().getRequest()).getHttpServletRequest());
+		GitBlitWebSession session = GitBlitWebSession.get();
+		if (session.isLoggedIn() && !session.isSessionInvalidated()) {
+			// already have a session, refresh usermodel to pick up
+			// any changes to permissions or roles (issue-186)
+			UserModel user = GitBlit.self().getUserModel(session.getUser().username);
+			session.setUser(user);
+			return;
 		}
+		
+		// try to authenticate by servlet request
+		HttpServletRequest httpRequest = ((WebRequest) getRequestCycle().getRequest()).getHttpServletRequest();
+		UserModel user = GitBlit.self().authenticate(httpRequest);
 
 		// Login the user
 		if (user != null) {
-			// Set the user into the session
-			GitBlitWebSession session = GitBlitWebSession.get();
 			// issue 62: fix session fixation vulnerability
 			session.replaceSession();
 			session.setUser(user);
@@ -212,6 +218,9 @@
 			case NONE:
 				map.put(type, MessageFormat.format(getString("gb.noPermission"), type.code));
 				break;
+			case EXCLUDE:
+				map.put(type, MessageFormat.format(getString("gb.excludePermission"), type.code));
+				break;
 			case VIEW:
 				map.put(type, MessageFormat.format(getString("gb.viewPermission"), type.code));
 				break;
@@ -247,6 +256,21 @@
 				break;
 			case FEDERATE_ORIGIN:
 				map.put(type, getString("gb.federateOrigin"));
+				break;
+			}
+		}
+		return map;
+	}
+	
+	protected Map<AuthorizationControl, String> getAuthorizationControls() {
+		Map<AuthorizationControl, String> map = new LinkedHashMap<AuthorizationControl, String>();
+		for (AuthorizationControl type : AuthorizationControl.values()) {
+			switch (type) {
+			case AUTHENTICATED:
+				map.put(type, getString("gb.allowAuthenticatedDescription"));
+				break;
+			case NAMED:
+				map.put(type, getString("gb.allowNamedDescription"));
 				break;
 			}
 		}
@@ -409,14 +433,19 @@
 		public UserFragment(String id, String markupId, MarkupContainer markupProvider) {
 			super(id, markupId, markupProvider);
 
-			if (GitBlitWebSession.get().isLoggedIn()) {
+			GitBlitWebSession session = GitBlitWebSession.get();
+			if (session.isLoggedIn()) {				
+				UserModel user = session.getUser();
+				boolean editCredentials = GitBlit.self().supportsCredentialChanges(user);
+				boolean standardLogin = session.authenticationType.isStandard();
+
 				// username, logout, and change password
-				add(new Label("username", GitBlitWebSession.get().getUser().getDisplayName() + ":"));
+				add(new Label("username", user.getDisplayName() + ":"));
 				add(new LinkPanel("loginLink", null, markupProvider.getString("gb.logout"),
-						LogoutPage.class));
-				boolean editCredentials = GitBlit.self().supportsCredentialChanges();
+						LogoutPage.class).setVisible(standardLogin));
+				
 				// quick and dirty hack for showing a separator
-				add(new Label("separator", "|").setVisible(editCredentials));
+				add(new Label("separator", "|").setVisible(standardLogin && editCredentials));
 				add(new BookmarkablePageLink<Void>("changePasswordLink", 
 						ChangePasswordPage.class).setVisible(editCredentials));
 			} else {

--
Gitblit v1.9.1