Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow for admin teams with spaces in their name.

  • Loading branch information...
commit 3d699cb14d6c891338567c562f7fe8d81e318b1c 1 parent f898a65
unknown authored
View
22 src/com/gitblit/LdapUserService.java
@@ -20,6 +20,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.security.GeneralSecurityException;
+import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -174,17 +175,16 @@ public UserModel authenticate(String username, char[] password) {
}
private void setAdminAttribute(UserModel user) {
- String adminString = settings.getString(Keys.realm.ldap_admins, "");
- String[] admins = adminString.split(" ");
- user.canAdmin = false;
- for (String admin : admins) {
- if (admin.startsWith("@")) { // Team
- if (user.getTeam(admin.substring(1)) != null)
- user.canAdmin = true;
- } else
- if (user.getName().equalsIgnoreCase(admin))
- user.canAdmin = true;
- }
+ user.canAdmin = false;
+ List<String> admins = settings.getStrings(Keys.realm.ldap_admins);
+ for (String admin : admins) {
+ if (admin.startsWith("@")) { // Team
+ if (user.getTeam(admin.substring(1)) != null)
+ user.canAdmin = true;
+ } else
+ if (user.getName().equalsIgnoreCase(admin))
+ user.canAdmin = true;
+ }
}
private void getTeamsFromLdap(LDAPConnection ldapConnection, String simpleUsername, SearchResultEntry loggingInUser, UserModel user) {
View
32 src/com/gitblit/utils/StringUtils.java
@@ -327,20 +327,24 @@ public static String getRelativePath(String basePath, String fullPath) {
* @return list of strings
*/
public static List<String> getStringsFromValue(String value, String separator) {
- List<String> strings = new ArrayList<String>();
- try {
- String[] chunks = value.split(separator);
- for (String chunk : chunks) {
- chunk = chunk.trim();
- if (chunk.length() > 0) {
- strings.add(chunk);
- }
- }
- } catch (PatternSyntaxException e) {
- throw new RuntimeException(e);
- }
- return strings;
- }
+ List<String> strings = new ArrayList<String>();
+ try {
+ String[] chunks = value.split(separator + "(?=([^\"]*\"[^\"]*\")*[^\"]*$)");
+ for (String chunk : chunks) {
+ chunk = chunk.trim();
+ if (chunk.length() > 0) {
+ if (chunk.charAt(0) == '"' && chunk.charAt(chunk.length() - 1) == '"') {
+ // strip double quotes
+ chunk = chunk.substring(1, chunk.length() - 1).trim();
+ }
+ strings.add(chunk);
+ }
+ }
+ } catch (PatternSyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ return strings;
+ }
/**
* Validates that a name is composed of letters, digits, or limited other
View
5 tests/com/gitblit/tests/LdapUserServiceTest.java
@@ -69,7 +69,7 @@ public void createLdapUserService() {
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 void testAuthenticate() {
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);
View
25 tests/com/gitblit/tests/StringUtilsTest.java
@@ -112,13 +112,24 @@ public void testRootPath() throws Exception {
@Test
public void testStringsFromValue() throws Exception {
- List<String> strings = StringUtils.getStringsFromValue("A B C D");
- assertEquals(4, strings.size());
- assertEquals("A", strings.get(0));
- assertEquals("B", strings.get(1));
- assertEquals("C", strings.get(2));
- assertEquals("D", strings.get(3));
- }
+ List<String> strings = StringUtils.getStringsFromValue("\"A A \" B \"C C\" D \"\" \"E\"");
+ assertEquals(6, strings.size());
+ assertEquals("A A", strings.get(0));
+ assertEquals("B", strings.get(1));
+ assertEquals("C C", strings.get(2));
+ assertEquals("D", strings.get(3));
+ assertEquals("", strings.get(4));
+ assertEquals("E", strings.get(5));
+
+ strings = StringUtils.getStringsFromValue("\"A A \", B, \"C C\", D, \"\", \"E\"", ",");
+ assertEquals(6, strings.size());
+ assertEquals("A A", strings.get(0));
+ assertEquals("B", strings.get(1));
+ assertEquals("C C", strings.get(2));
+ assertEquals("D", strings.get(3));
+ assertEquals("", strings.get(4));
+ assertEquals("E", strings.get(5));
+ }
@Test
public void testStringsFromValue2() throws Exception {
View
8 tests/com/gitblit/tests/resources/ldapUserServiceSampleData.ldif
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.