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
}\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
* @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
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);
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);
\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
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
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