From 0e44acbb2fec928a1606dc60f427a148fff405c9 Mon Sep 17 00:00:00 2001
From: Mohamed Ragab <moragab@gmail.com>
Date: Wed, 02 May 2012 11:15:01 -0400
Subject: [PATCH] Added a script to facilitate setting the proxy host and port and no proxy hosts, and then it concatenates all the java system properties for setting the java proxy configurations and puts the resulting string in an environment variable JAVA_PROXY_CONFIG, modified the scirpts gitblit,  gitblit-ubuntu, and gitblit-centos to source the java-proxy-config.sh script and then include the resulting java proxy configuration in the java command

---
 src/com/gitblit/wicket/pages/EditUserPage.java |  107 ++++++++++++++++++++++++++++++++---------------------
 1 files changed, 65 insertions(+), 42 deletions(-)

diff --git a/src/com/gitblit/wicket/pages/EditUserPage.java b/src/com/gitblit/wicket/pages/EditUserPage.java
index 142a542..cfe7c35 100644
--- a/src/com/gitblit/wicket/pages/EditUserPage.java
+++ b/src/com/gitblit/wicket/pages/EditUserPage.java
@@ -22,10 +22,10 @@
 import java.util.List;
 
 import org.apache.wicket.PageParameters;
+import org.apache.wicket.behavior.SimpleAttributeModifier;
 import org.apache.wicket.extensions.markup.html.form.palette.Palette;
 import org.apache.wicket.markup.html.form.Button;
 import org.apache.wicket.markup.html.form.CheckBox;
-import org.apache.wicket.markup.html.form.ChoiceRenderer;
 import org.apache.wicket.markup.html.form.Form;
 import org.apache.wicket.markup.html.form.PasswordTextField;
 import org.apache.wicket.markup.html.form.TextField;
@@ -43,6 +43,7 @@
 import com.gitblit.models.UserModel;
 import com.gitblit.utils.StringUtils;
 import com.gitblit.wicket.RequiresAdminRole;
+import com.gitblit.wicket.StringChoiceRenderer;
 import com.gitblit.wicket.WicketUtils;
 
 @RequiresAdminRole
@@ -53,6 +54,10 @@
 	public EditUserPage() {
 		// create constructor
 		super();
+		if (!GitBlit.self().supportsCredentialChanges()) {
+			error(MessageFormat.format(getString("gb.userServiceDoesNotPermitAddUser"),
+					GitBlit.getString(Keys.realm.userService, "users.conf")), true);
+		}
 		isCreate = true;
 		setupPage(new UserModel(""));
 	}
@@ -93,10 +98,10 @@
 		final String oldName = userModel.username;
 		final Palette<String> repositories = new Palette<String>("repositories",
 				new ListModel<String>(new ArrayList<String>(userModel.repositories)),
-				new CollectionModel<String>(repos), new ChoiceRenderer<String>("", ""), 10, false);
+				new CollectionModel<String>(repos), new StringChoiceRenderer(), 10, false);
 		final Palette<String> teams = new Palette<String>("teams", new ListModel<String>(
 				new ArrayList<String>(userTeams)), new CollectionModel<String>(GitBlit.self()
-				.getAllTeamnames()), new ChoiceRenderer<String>("", ""), 10, false);
+				.getAllTeamnames()), new StringChoiceRenderer(), 10, false);
 		Form<UserModel> form = new Form<UserModel>("editForm", model) {
 
 			private static final long serialVersionUID = 1L;
@@ -109,7 +114,7 @@
 			@Override
 			protected void onSubmit() {
 				if (StringUtils.isEmpty(userModel.username)) {
-					error("Please enter a username!");
+					error(getString("gb.pleaseSetUsername"));
 					return;
 				}
 				// force username to lower-case
@@ -118,47 +123,48 @@
 				if (isCreate) {
 					UserModel model = GitBlit.self().getUserModel(username);
 					if (model != null) {
-						error(MessageFormat.format("Username ''{0}'' is unavailable.", username));
+						error(MessageFormat.format(getString("gb.usernameUnavailable"), username));
 						return;
 					}
 				}
 				boolean rename = !StringUtils.isEmpty(oldName)
 						&& !oldName.equalsIgnoreCase(username);
-				if (!userModel.password.equals(confirmPassword.getObject())) {
-					error("Passwords do not match!");
-					return;
-				}
-				String password = userModel.password;
-				if (!password.toUpperCase().startsWith(StringUtils.MD5_TYPE)
-						&& !password.toUpperCase().startsWith(StringUtils.COMBINED_MD5_TYPE)) {
-					// This is a plain text password.
-					// Check length.
-					int minLength = GitBlit.getInteger(Keys.realm.minPasswordLength, 5);
-					if (minLength < 4) {
-						minLength = 4;
-					}
-					if (password.trim().length() < minLength) {
-						error(MessageFormat.format(
-								"Password is too short. Minimum length is {0} characters.",
-								minLength));
+				if (GitBlit.self().supportsCredentialChanges()) {
+					if (!userModel.password.equals(confirmPassword.getObject())) {
+						error(getString("gb.passwordsDoNotMatch"));
 						return;
 					}
-
-					// Optionally store the password MD5 digest.
-					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);
-					} else if (type.equalsIgnoreCase("combined-md5")) {
-						// store MD5 digest of username+password
-						userModel.password = StringUtils.COMBINED_MD5_TYPE
-								+ StringUtils.getMD5(username + userModel.password);
+					String password = userModel.password;
+					if (!password.toUpperCase().startsWith(StringUtils.MD5_TYPE)
+							&& !password.toUpperCase().startsWith(StringUtils.COMBINED_MD5_TYPE)) {
+						// This is a plain text password.
+						// Check length.
+						int minLength = GitBlit.getInteger(Keys.realm.minPasswordLength, 5);
+						if (minLength < 4) {
+							minLength = 4;
+						}
+						if (password.trim().length() < minLength) {
+							error(MessageFormat.format(getString("gb.passwordTooShort"),
+									minLength));
+							return;
+						}
+	
+						// Optionally store the password MD5 digest.
+						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);
+						} else if (type.equalsIgnoreCase("combined-md5")) {
+							// store MD5 digest of username+password
+							userModel.password = StringUtils.COMBINED_MD5_TYPE
+									+ StringUtils.getMD5(username + userModel.password);
+						}
+					} else if (rename
+							&& password.toUpperCase().startsWith(StringUtils.COMBINED_MD5_TYPE)) {
+						error(getString("gb.combinedMd5Rename"));
+						return;
 					}
-				} else if (rename
-						&& password.toUpperCase().startsWith(StringUtils.COMBINED_MD5_TYPE)) {
-					error("Gitblit is configured for combined-md5 password hashing. You must enter a new password on account rename.");
-					return;
 				}
 
 				Iterator<String> selectedRepositories = repositories.getSelectedChoices();
@@ -188,7 +194,7 @@
 				setRedirect(false);
 				if (isCreate) {
 					// create another user
-					info(MessageFormat.format("New user ''{0}'' successfully created.",
+					info(MessageFormat.format(getString("gb.userCreated"),
 							userModel.username));
 					setResponsePage(EditUserPage.class);
 				} else {
@@ -197,20 +203,37 @@
 				}
 			}
 		};
+		
+		// do not let the browser pre-populate these fields
+		form.add(new SimpleAttributeModifier("autocomplete", "off"));
+		
+		// not all user services support manipulating username and password
+		boolean editCredentials = GitBlit.self().supportsCredentialChanges();
+		
+		// not all user services support manipulating display name
+		boolean editDisplayName = GitBlit.self().supportsDisplayNameChanges();
+
+		// not all user services support manipulating email address
+		boolean editEmailAddress = GitBlit.self().supportsEmailAddressChanges();
+
+		// not all user services support manipulating team memberships
+		boolean editTeams = GitBlit.self().supportsTeamMembershipChanges();
 
 		// field names reflective match UserModel fields
-		form.add(new TextField<String>("username"));
+		form.add(new TextField<String>("username").setEnabled(editCredentials));
 		PasswordTextField passwordField = new PasswordTextField("password");
 		passwordField.setResetPassword(false);
-		form.add(passwordField);
+		form.add(passwordField.setEnabled(editCredentials));
 		PasswordTextField confirmPasswordField = new PasswordTextField("confirmPassword",
 				confirmPassword);
 		confirmPasswordField.setResetPassword(false);
-		form.add(confirmPasswordField);
+		form.add(confirmPasswordField.setEnabled(editCredentials));
+		form.add(new TextField<String>("displayName").setEnabled(editDisplayName));
+		form.add(new TextField<String>("emailAddress").setEnabled(editEmailAddress));
 		form.add(new CheckBox("canAdmin"));
 		form.add(new CheckBox("excludeFromFederation"));
 		form.add(repositories);
-		form.add(teams);
+		form.add(teams.setEnabled(editTeams));
 
 		form.add(new Button("save"));
 		Button cancel = new Button("cancel") {

--
Gitblit v1.9.1