]> source.dussan.org Git - gitblit.git/commitdiff
Fixed username case-sensitivity bugs (issue 43)
authorJames Moger <james.moger@gitblit.com>
Mon, 16 Jan 2012 13:28:37 +0000 (08:28 -0500)
committerJames Moger <james.moger@gitblit.com>
Mon, 16 Jan 2012 13:28:37 +0000 (08:28 -0500)
docs/04_releases.mkd
src/com/gitblit/ConfigUserService.java
src/com/gitblit/FileUserService.java
src/com/gitblit/client/EditUserDialog.java
src/com/gitblit/wicket/pages/EditUserPage.java
tests/com/gitblit/tests/UserServiceTest.java

index c51c2d76b285e8899c0e5b9483dd601d90afba23..d9177fd0d6d401e6331e8b195a80ea3bd8776e50 100644 (file)
@@ -4,6 +4,11 @@
 \r
 **%VERSION%** ([go](http://code.google.com/p/gitblit/downloads/detail?name=%GO%) | [war](http://code.google.com/p/gitblit/downloads/detail?name=%WAR%) | [express](http://code.google.com/p/gitblit/downloads/detail?name=%EXPRESS%) | [fedclient](http://code.google.com/p/gitblit/downloads/detail?name=%FEDCLIENT%) | [manager](http://code.google.com/p/gitblit/downloads/detail?name=%MANAGER%) | [api](http://code.google.com/p/gitblit/downloads/detail?name=%API%)) based on [%JGIT%][jgit] &nbsp; *released %BUILDDATE%*\r
 \r
+#### fixes \r
+- Fixed username case-sensitivity issues (issue 43)\r
+\r
+**0.8.2** ([go](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.8.2.zip) | [war](http://code.google.com/p/gitblit/downloads/detail?name=gitblit-0.8.2.war) | [express](http://code.google.com/p/gitblit/downloads/detail?name=express-0.8.2.zip) | [fedclient](http://code.google.com/p/gitblit/downloads/detail?name=fedclient-0.8.2.zip) | [manager](http://code.google.com/p/gitblit/downloads/detail?name=manager-0.8.2.zip) | [api](http://code.google.com/p/gitblit/downloads/detail?name=gbapi-0.8.2.zip)) based on [JGit 1.2.0 (201112221803-r)][jgit] &nbsp; *released 2012-01-13*\r
+\r
 #### fixes\r
 \r
 - Fixed bug when upgrading from users.properties to users.conf (issue 41)\r
index 5ba49aeaf0da07b011c7d3e31f1ca70af5b2fc1a..681efd5360f01516077e22e21e23b19be9a169b4 100644 (file)
@@ -746,7 +746,7 @@ public class ConfigUserService implements IUserService {
                                config.load();\r
                                Set<String> usernames = config.getSubsections(USER);\r
                                for (String username : usernames) {\r
-                                       UserModel user = new UserModel(username);\r
+                                       UserModel user = new UserModel(username.toLowerCase());\r
                                        user.password = config.getString(USER, username, PASSWORD);\r
 \r
                                        // user roles\r
@@ -763,8 +763,8 @@ public class ConfigUserService implements IUserService {
                                        }\r
 \r
                                        // update cache\r
-                                       users.put(username, user);\r
-                                       cookies.put(StringUtils.getSHA1(username + user.password), user);\r
+                                       users.put(user.username, user);\r
+                                       cookies.put(StringUtils.getSHA1(user.username + user.password), user);\r
                                }\r
 \r
                                // load the teams\r
index 37ca9a70ae9fcefaa310ad8142b99eaa31ce3b31..dfc4da8ac6dbfd7c210860629807cdf932aba0f2 100644 (file)
@@ -165,11 +165,11 @@ public class FileUserService extends FileSettings implements IUserService {
        @Override\r
        public UserModel getUserModel(String username) {\r
                Properties allUsers = read();\r
-               String userInfo = allUsers.getProperty(username);\r
+               String userInfo = allUsers.getProperty(username.toLowerCase());\r
                if (userInfo == null) {\r
                        return null;\r
                }\r
-               UserModel model = new UserModel(username);\r
+               UserModel model = new UserModel(username.toLowerCase());\r
                String[] userValues = userInfo.split(",");\r
                model.password = userValues[0];\r
                for (int i = 1; i < userValues.length; i++) {\r
@@ -219,7 +219,7 @@ public class FileUserService extends FileSettings implements IUserService {
         */\r
        @Override\r
        public boolean updateUserModel(String username, UserModel model) {\r
-               try {\r
+               try {                   \r
                        Properties allUsers = read();\r
                        UserModel oldUser = getUserModel(username);\r
                        ArrayList<String> roles = new ArrayList<String>(model.repositories);\r
@@ -241,8 +241,8 @@ public class FileUserService extends FileSettings implements IUserService {
                        }\r
                        // trim trailing comma\r
                        sb.setLength(sb.length() - 1);\r
-                       allUsers.remove(username);\r
-                       allUsers.put(model.username, sb.toString());\r
+                       allUsers.remove(username.toLowerCase());\r
+                       allUsers.put(model.username.toLowerCase(), sb.toString());\r
 \r
                        // null check on "final" teams because JSON-sourced UserModel\r
                        // can have a null teams object\r
@@ -661,7 +661,7 @@ public class FileUserService extends FileSettings implements IUserService {
                                } else {\r
                                        // user definition\r
                                        String password = roles[0];\r
-                                       cookies.put(StringUtils.getSHA1(username + password), username);\r
+                                       cookies.put(StringUtils.getSHA1(username.toLowerCase() + password), username.toLowerCase());\r
                                }\r
                        }\r
                }\r
index 3f1b9291d5602db6feb94e92d3400bd73e243f42..f3665d9bc35f160d835b6c8cc7be88de4618c046 100644 (file)
@@ -78,7 +78,7 @@ public class EditUserDialog extends JDialog {
        private JCheckBox notFederatedCheckbox;\r
 \r
        private JPalette<String> repositoryPalette;\r
-       \r
+\r
        private JPalette<TeamModel> teamsPalette;\r
 \r
        private Set<String> usernames;\r
@@ -135,10 +135,10 @@ public class EditUserDialog extends JDialog {
                final Insets _insets = new Insets(5, 5, 5, 5);\r
                repositoryPalette = new JPalette<String>();\r
                teamsPalette = new JPalette<TeamModel>();\r
-               \r
+\r
                JPanel fieldsPanelTop = new JPanel(new BorderLayout());\r
                fieldsPanelTop.add(fieldsPanel, BorderLayout.NORTH);\r
-               \r
+\r
                JPanel repositoriesPanel = new JPanel(new BorderLayout()) {\r
 \r
                        private static final long serialVersionUID = 1L;\r
@@ -166,7 +166,6 @@ public class EditUserDialog extends JDialog {
                }\r
                panel.addTab(Translation.get("gb.restrictedRepositories"), repositoriesPanel);\r
 \r
-\r
                JButton createButton = new JButton(Translation.get("gb.save"));\r
                createButton.addActionListener(new ActionListener() {\r
                        public void actionPerformed(ActionEvent event) {\r
@@ -188,7 +187,7 @@ public class EditUserDialog extends JDialog {
                JPanel controls = new JPanel();\r
                controls.add(cancelButton);\r
                controls.add(createButton);\r
-               \r
+\r
                JPanel centerPanel = new JPanel(new BorderLayout(5, 5)) {\r
 \r
                        private static final long serialVersionUID = 1L;\r
@@ -217,16 +216,15 @@ public class EditUserDialog extends JDialog {
        }\r
 \r
        private boolean validateFields() {\r
-               String uname = usernameField.getText();\r
-               if (StringUtils.isEmpty(uname)) {\r
+               if (StringUtils.isEmpty(usernameField.getText())) {\r
                        error("Please enter a username!");\r
                        return false;\r
                }\r
-\r
+               String uname = usernameField.getText().toLowerCase();\r
                boolean rename = false;\r
                // verify username uniqueness on create\r
                if (isCreate) {\r
-                       if (usernames.contains(uname.toLowerCase())) {\r
+                       if (usernames.contains(uname)) {\r
                                error(MessageFormat.format("Username ''{0}'' is unavailable.", uname));\r
                                return false;\r
                        }\r
@@ -234,7 +232,7 @@ public class EditUserDialog extends JDialog {
                        // check rename collision\r
                        rename = !StringUtils.isEmpty(username) && !username.equalsIgnoreCase(uname);\r
                        if (rename) {\r
-                               if (usernames.contains(uname.toLowerCase())) {\r
+                               if (usernames.contains(uname)) {\r
                                        error(MessageFormat.format(\r
                                                        "Failed to rename ''{0}'' because ''{1}'' already exists.", username,\r
                                                        uname));\r
@@ -274,7 +272,7 @@ public class EditUserDialog extends JDialog {
                        } else if (type.equalsIgnoreCase("combined-md5")) {\r
                                // store MD5 digest of username+password\r
                                user.password = StringUtils.COMBINED_MD5_TYPE\r
-                                               + StringUtils.getMD5(username.toLowerCase() + password);\r
+                                               + StringUtils.getMD5(user.username + password);\r
                        } else {\r
                                // plain-text password\r
                                user.password = password;\r
@@ -292,7 +290,7 @@ public class EditUserDialog extends JDialog {
 \r
                user.repositories.clear();\r
                user.repositories.addAll(repositoryPalette.getSelections());\r
-               \r
+\r
                user.teams.clear();\r
                user.teams.addAll(teamsPalette.getSelections());\r
                return true;\r
@@ -323,7 +321,7 @@ public class EditUserDialog extends JDialog {
                }\r
                repositoryPalette.setObjects(restricted, selected);\r
        }\r
-       \r
+\r
        public void setTeams(List<TeamModel> teams, List<TeamModel> selected) {\r
                Collections.sort(teams);\r
                if (selected != null) {\r
index 799cf01d4c74340257bf57663259d349ed708fb3..142a5424adb657ba3d649b8095b4d30ec16b68f6 100644 (file)
@@ -108,11 +108,13 @@ public class EditUserPage extends RootSubPage {
                         */\r
                        @Override\r
                        protected void onSubmit() {\r
-                               String username = userModel.username;\r
-                               if (StringUtils.isEmpty(username)) {\r
+                               if (StringUtils.isEmpty(userModel.username)) {\r
                                        error("Please enter a username!");\r
                                        return;\r
                                }\r
+                               // force username to lower-case\r
+                               userModel.username = userModel.username.toLowerCase();\r
+                               String username = userModel.username;\r
                                if (isCreate) {\r
                                        UserModel model = GitBlit.self().getUserModel(username);\r
                                        if (model != null) {\r
@@ -151,7 +153,7 @@ public class EditUserPage extends RootSubPage {
                                        } else if (type.equalsIgnoreCase("combined-md5")) {\r
                                                // store MD5 digest of username+password\r
                                                userModel.password = StringUtils.COMBINED_MD5_TYPE\r
-                                                               + StringUtils.getMD5(username.toLowerCase() + userModel.password);\r
+                                                               + StringUtils.getMD5(username + userModel.password);\r
                                        }\r
                                } else if (rename\r
                                                && password.toUpperCase().startsWith(StringUtils.COMBINED_MD5_TYPE)) {\r
@@ -177,7 +179,7 @@ public class EditUserPage extends RootSubPage {
                                        userModel.teams.add(team);\r
                                }\r
 \r
-                               try {\r
+                               try {                                   \r
                                        GitBlit.self().updateUserModel(oldName, userModel, isCreate);\r
                                } catch (GitBlitException e) {\r
                                        error(e.getMessage());\r
index b1f02472c6f253ad84106a00b03b4dc93416f38f..03051bdb5887c5a004de0e9522d16c0c792f23b6 100644 (file)
@@ -80,12 +80,15 @@ public class UserServiceTest {
                service.updateUserModel(newUser);\r
 \r
                // add one more new user and then test reload of first new user\r
-               newUser = new UserModel("garbage");\r
+               newUser = new UserModel("GARBAGE");\r
                newUser.password = "garbage";\r
                service.updateUserModel(newUser);\r
 \r
                // confirm all added users\r
                assertEquals(3, service.getAllUsernames().size());\r
+               assertTrue(service.getUserModel("garbage") != null);\r
+               assertTrue(service.getUserModel("GaRbAgE") != null);\r
+               assertTrue(service.getUserModel("GARBAGE") != null);\r
 \r
                // confirm reloaded test user\r
                newUser = service.getUserModel("test");\r