]> source.dussan.org Git - gitblit.git/commitdiff
Improvements to create/edit user.
authorJames Moger <james.moger@gitblit.com>
Thu, 12 May 2011 22:18:20 +0000 (18:18 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 12 May 2011 22:18:20 +0000 (18:18 -0400)
distrib/gitblit.properties
src/com/gitblit/JettyLoginService.java
src/com/gitblit/wicket/pages/EditRepositoryPage.java
src/com/gitblit/wicket/pages/EditUserPage.java

index 6bf33f13b6bcef76aa23edd2900ec31526f48c30..bcbd3db422446cf32a9f0372557184172b5570c2 100644 (file)
@@ -37,6 +37,10 @@ realm.realmFile = users.properties
 # Valid values are plain, md5 or crypt (unix style).  Default is md5. \r
 realm.passwordStorage = md5\r
 \r
+# Minimum valid length for a plain text password.\r
+# Default value is 5.  Absolute minimum is 4. \r
+realm.minPasswordLength = 5\r
+\r
 #\r
 # Git:Blit Web Settings\r
 #\r
index fb510ee6f4f4b42da29fb2e7e4a73e1dfa35377d..c191f0f0b3277ad29d06f5d17e5e74071f48647c 100644 (file)
@@ -69,8 +69,11 @@ public class JettyLoginService extends MappedLoginService implements ILoginServi
 \r
        @Override\r
        public UserModel getUserModel(String username) {\r
-               UserModel model = new UserModel(username);\r
                UserIdentity identity = _users.get(username);\r
+               if (identity == null) {\r
+                       return null;\r
+               }\r
+               UserModel model = new UserModel(username);\r
                Subject subject = identity.getSubject();\r
                for (Principal principal : subject.getPrincipals()) {\r
                        if (principal instanceof RolePrincipal) {\r
index 8eed00593cc7c57d0f416fe22b64ed0baa6c3539..88202901594f6021ae9f8fa7330cf3d2c16b5dba 100644 (file)
@@ -116,7 +116,7 @@ public class EditRepositoryPage extends BasePage {
                                        error(e.getMessage());\r
                                        return;\r
                                }\r
-                               setRedirect(true);\r
+                               setRedirect(false);\r
                                setResponsePage(RepositoriesPage.class);\r
                        }\r
                };\r
index d1faa782b54ee1ba2099203d2500f2e58fd5265f..7522f3edb619e69500eac104ba700ef36d9bd863 100644 (file)
@@ -1,5 +1,6 @@
 package com.gitblit.wicket.pages;\r
 \r
+import java.text.MessageFormat;\r
 import java.util.ArrayList;\r
 import java.util.Iterator;\r
 import java.util.List;\r
@@ -71,8 +72,25 @@ public class EditUserPage extends BasePage {
 \r
                        private static final long serialVersionUID = 1L;\r
 \r
+                       /*\r
+                        * (non-Javadoc)\r
+                        * \r
+                        * @see org.apache.wicket.markup.html.form.Form#onSubmit()\r
+                        */\r
                        @Override\r
                        protected void onSubmit() {\r
+                               String username = userModel.getUsername();\r
+                               if (StringUtils.isEmpty(username)) {\r
+                                       error("Please enter a username!");\r
+                                       return;\r
+                               }\r
+                               if (isCreate) {\r
+                                       UserModel model = GitBlit.self().getUserModel(username);\r
+                                       if (model != null) {\r
+                                               error(MessageFormat.format("Username {0} is unavailable.", username));\r
+                                               return;\r
+                                       }\r
+                               }\r
                                if (!userModel.getPassword().equals(confirmPassword.getObject())) {\r
                                        error("Passwords do not match!");\r
                                        return;\r
@@ -80,6 +98,16 @@ public class EditUserPage extends BasePage {
                                String password = userModel.getPassword();\r
                                if (!password.toUpperCase().startsWith(Crypt.__TYPE) && !password.toUpperCase().startsWith(MD5.__TYPE)) {\r
                                        // This is a plain text password.\r
+                                       // Check length.\r
+                                       int minLength = GitBlit.self().settings().getInteger(Keys.realm.minPasswordLength, 5);\r
+                                       if (minLength < 4) {\r
+                                               minLength = 4;\r
+                                       }\r
+                                       if (password.trim().length() < minLength) {\r
+                                               error(MessageFormat.format("Password is too short. Minimum length is {0} characters.", minLength));\r
+                                               return;\r
+                                       }\r
+                                       \r
                                        // Optionally encrypt/obfuscate the password.\r
                                        String type = GitBlit.self().settings().getString(Keys.realm.passwordStorage, "md5");\r
                                        if (type.equalsIgnoreCase("md5")) {\r
@@ -103,9 +131,10 @@ public class EditUserPage extends BasePage {
                                        error(e.getMessage());\r
                                        return;\r
                                }\r
-                               setRedirect(true);\r
+                               setRedirect(false);\r
                                if (isCreate) {\r
                                        // create another user\r
+                                       info(MessageFormat.format("New user {0} successfully created.", userModel.getUsername()));\r
                                        setResponsePage(EditUserPage.class);\r
                                } else {\r
                                        // back to home\r