]> source.dussan.org Git - gitblit.git/commitdiff
Allow for admin teams with spaces in their name. 12/head
authorunknown <jcrygier@JCrygier-W520.int.aonesolutions.us>
Tue, 24 Apr 2012 12:48:39 +0000 (07:48 -0500)
committerunknown <jcrygier@JCrygier-W520.int.aonesolutions.us>
Tue, 24 Apr 2012 12:48:39 +0000 (07:48 -0500)
src/com/gitblit/LdapUserService.java
src/com/gitblit/utils/StringUtils.java
tests/com/gitblit/tests/LdapUserServiceTest.java
tests/com/gitblit/tests/StringUtilsTest.java
tests/com/gitblit/tests/resources/ldapUserServiceSampleData.ldif

index 9fcef9d65ec586189e810213b4d27f4e74cfe7ca..86b6136406a8fb750475104d9a08d5ca807cab3c 100644 (file)
@@ -20,6 +20,7 @@ import java.io.File;
 import java.net.URI;\r
 import java.net.URISyntaxException;\r
 import java.security.GeneralSecurityException;\r
+import java.util.List;\r
 \r
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
@@ -174,17 +175,16 @@ public class LdapUserService extends GitblitUserService {
        }\r
 \r
        private void setAdminAttribute(UserModel user) {\r
-               String adminString = settings.getString(Keys.realm.ldap_admins, "");\r
-               String[] admins = adminString.split(" ");\r
-               user.canAdmin = false;\r
-               for (String admin : admins) {\r
-                       if (admin.startsWith("@")) { // Team\r
-                               if (user.getTeam(admin.substring(1)) != null)\r
-                                       user.canAdmin = true;\r
-                       } else\r
-                               if (user.getName().equalsIgnoreCase(admin))\r
-                                       user.canAdmin = true;\r
-               }\r
+           user.canAdmin = false;\r
+           List<String>  admins = settings.getStrings(Keys.realm.ldap_admins);\r
+           for (String admin : admins) {\r
+               if (admin.startsWith("@")) { // Team\r
+                   if (user.getTeam(admin.substring(1)) != null)\r
+                       user.canAdmin = true;\r
+               } else\r
+                   if (user.getName().equalsIgnoreCase(admin))\r
+                       user.canAdmin = true;\r
+           }\r
        }\r
 \r
        private void getTeamsFromLdap(LDAPConnection ldapConnection, String simpleUsername, SearchResultEntry loggingInUser, UserModel user) {\r
index 0460ac9f37e5f0e96b416a5fbfb8da31537bd06e..2c35724156a4b3d8a7bc6bf16cfbe14681f17f98 100644 (file)
@@ -327,20 +327,24 @@ public class StringUtils {
         * @return list of strings\r
         */\r
        public static List<String> getStringsFromValue(String value, String separator) {\r
-               List<String> strings = new ArrayList<String>();\r
-               try {\r
-                       String[] chunks = value.split(separator);\r
-                       for (String chunk : chunks) {\r
-                               chunk = chunk.trim();\r
-                               if (chunk.length() > 0) {\r
-                                       strings.add(chunk);\r
-                               }\r
-                       }\r
-               } catch (PatternSyntaxException e) {\r
-                       throw new RuntimeException(e);\r
-               }\r
-               return strings;\r
-       }\r
+        List<String> strings = new ArrayList<String>();\r
+        try {\r
+            String[] chunks = value.split(separator + "(?=([^\"]*\"[^\"]*\")*[^\"]*$)");            \r
+            for (String chunk : chunks) {\r
+                chunk = chunk.trim();\r
+                if (chunk.length() > 0) {\r
+                    if (chunk.charAt(0) == '"' && chunk.charAt(chunk.length() - 1) == '"') {\r
+                        // strip double quotes\r
+                        chunk = chunk.substring(1, chunk.length() - 1).trim();\r
+                    }\r
+                    strings.add(chunk);\r
+                }\r
+            }\r
+        } catch (PatternSyntaxException e) {\r
+            throw new RuntimeException(e);\r
+        }\r
+        return strings;\r
+    }\r
 \r
        /**\r
         * Validates that a name is composed of letters, digits, or limited other\r
index 777d86cfebeb585351289f51243c7a439ff1a92f..43af24f26c0fb91567d2f5a4577abf8259a7479f 100644 (file)
@@ -69,7 +69,7 @@ public class LdapUserServiceTest {
                backingMap.put("realm.ldap.accountPattern", "(&(objectClass=person)(sAMAccountName=${username}))");
                backingMap.put("realm.ldap.groupBase", "OU=Groups,OU=UserControl,OU=MyOrganization,DC=MyDomain");
                backingMap.put("realm.ldap.groupPattern", "(&(objectClass=group)(member=${dn}))");
-               backingMap.put("realm.ldap.admins", "UserThree @Git_Admins");
+               backingMap.put("realm.ldap.admins", "UserThree @Git_Admins \"@Git Admins\"");
                
                MemorySettings ms = new MemorySettings(backingMap);
                
@@ -92,7 +92,8 @@ public class LdapUserServiceTest {
                assertNotNull(userTwoModel);
                assertNotNull(userTwoModel.getTeam("git_users"));
                assertNull(userTwoModel.getTeam("git_admins"));
-               assertFalse(userTwoModel.canAdmin);
+               assertNotNull(userTwoModel.getTeam("git admins"));
+               assertTrue(userTwoModel.canAdmin);
                
                UserModel userThreeModel = ldapUserService.authenticate("UserThree", "userThreePassword".toCharArray());
                assertNotNull(userThreeModel);
index 2e00fa3e5f4f2597fa3339e719751ea5353be1b0..91bfa672b9989889b686566d79be1155006b33d6 100644 (file)
@@ -112,13 +112,24 @@ public class StringUtilsTest {
 \r
        @Test\r
        public void testStringsFromValue() throws Exception {\r
-               List<String> strings = StringUtils.getStringsFromValue("A B C D");\r
-               assertEquals(4, strings.size());\r
-               assertEquals("A", strings.get(0));\r
-               assertEquals("B", strings.get(1));\r
-               assertEquals("C", strings.get(2));\r
-               assertEquals("D", strings.get(3));\r
-       }\r
+        List<String> strings = StringUtils.getStringsFromValue("\"A A \" B \"C C\" D \"\" \"E\"");\r
+        assertEquals(6, strings.size());\r
+        assertEquals("A A", strings.get(0));\r
+        assertEquals("B", strings.get(1));\r
+        assertEquals("C C", strings.get(2));\r
+        assertEquals("D", strings.get(3));\r
+        assertEquals("", strings.get(4));\r
+        assertEquals("E", strings.get(5));\r
+\r
+        strings = StringUtils.getStringsFromValue("\"A A \", B, \"C C\", D, \"\", \"E\"", ",");\r
+        assertEquals(6, strings.size());\r
+        assertEquals("A A", strings.get(0));\r
+        assertEquals("B", strings.get(1));\r
+        assertEquals("C C", strings.get(2));\r
+        assertEquals("D", strings.get(3));\r
+        assertEquals("", strings.get(4));\r
+        assertEquals("E", strings.get(5));\r
+    }\r
 \r
        @Test\r
        public void testStringsFromValue2() throws Exception {\r
index 22d68699812607a06ba869c701b3920072125f7b..84ee243e71107d29bd206c6163e87670ac206f0c 100644 (file)
@@ -25,6 +25,13 @@ cn: Git_Admins
 sAMAccountName: Git_Admins
 member: CN=UserOne,OU=US,OU=Users,OU=UserControl,OU=MyOrganization,DC=MyDomain
 
+dn: CN=Git Admins,OU=Groups,OU=UserControl,OU=MyOrganization,DC=MyDomain
+objectClass: top
+objectClass: group
+cn: Git Admins
+sAMAccountName: Git_Admins_With_Space
+member: CN=UserTwo,OU=US,OU=Users,OU=UserControl,OU=MyOrganization,DC=MyDomain
+
 dn: CN=Git_Users,OU=Groups,OU=UserControl,OU=MyOrganization,DC=MyDomain
 objectClass: top
 objectClass: group
@@ -64,6 +71,7 @@ objectClass: person
 sAMAccountName: UserTwo
 userPassword: userTwoPassword
 memberOf: CN=Git_Users,OU=Groups,OU=UserControl,OU=MyOrganization,DC=MyDomain
+memberOf: CN=Git Admins,OU=Groups,OU=UserControl,OU=MyOrganization,DC=MyDomain
 
 dn: CN=UserThree,OU=Canada,OU=Users,OU=UserControl,OU=MyOrganization,DC=MyDomain
 objectClass: user