Skip to content

Commit

Permalink
CAS-1055
Browse files Browse the repository at this point in the history
fixed encoding
  • Loading branch information
battags committed Oct 9, 2011
1 parent ec86532 commit e12da0e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ldap.core.LdapEncoder;

/**
* Utilities related to LDAP functions.
Expand Down Expand Up @@ -44,7 +45,7 @@ public static String getFilterWithValues(final String filter,
final String[] userDomain;
String newFilter = filter;

properties.put("%u", userName.replace("\\", "\\\\"));
properties.put("%u", userName);

userDomain = userName.split("@");

Expand All @@ -62,7 +63,7 @@ public static String getFilterWithValues(final String filter,
}

for (final String key : properties.keySet()) {
final String value = properties.get(key);
final String value = LdapEncoder.nameEncode(properties.get(key));
newFilter = newFilter.replaceAll(key, Matcher.quoteReplacement(value));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.jasig.cas.util;

import junit.framework.TestCase;

/**
* @author Daniel Frett
* @version $Revision$ $Date$
* @since 3.4.11
*/
public final class LdapUtilTests extends TestCase {

public void testEncoding() {
final String filter = "cn=%u";
assertEquals("cn=test\\+user@example.com", LdapUtils.getFilterWithValues(filter, "test+user@example.com"));
}
}

0 comments on commit e12da0e

Please sign in to comment.