KEYCLOAK-5453 - Empty RDNs makes Keycloak unstable

This commit is contained in:
Przemyslaw Kadej 2017-09-12 13:28:35 +02:00
parent 7f8b5e032a
commit 5b1a761b0f
2 changed files with 24 additions and 1 deletions

View file

@ -50,7 +50,11 @@ public class LDAPDn {
String[] rdns = dnString.split("(?<!\\\\),");
for (String entryStr : rdns) {
String[] rdn = entryStr.split("(?<!\\\\)=");
if (rdn.length >1) {
dn.addLast(rdn[0].trim(), rdn[1].trim());
} else {
dn.addLast(rdn[0].trim(), "");
}
}
return dn;

View file

@ -47,6 +47,25 @@ public class LDAPDnTest {
Assert.assertEquals("Johny,Depp+Pepp\\Foo", dn.getFirstRdnAttrValue());
}
@Test
public void testEmptyRDN() throws Exception {
LDAPDn dn = LDAPDn.fromString("dc=keycloak, dc=org");
dn.addFirst("ou", "");
Assert.assertEquals("ou", dn.getFirstRdnAttrName());
Assert.assertEquals("", dn.getFirstRdnAttrValue());
Assert.assertEquals("ou=,dc=keycloak,dc=org", dn.toString());
dn.addFirst("uid", "Johny,Depp+Pepp\\Foo");
Assert.assertEquals("uid=Johny\\,Depp\\+Pepp\\\\Foo,ou=,dc=keycloak,dc=org", dn.toString());
dn = LDAPDn.fromString("uid=Johny\\,Depp\\+Pepp\\\\Foo,ou=,O=keycloak,C=org");
Assert.assertTrue(dn.isDescendantOf(LDAPDn.fromString("ou=, O=keycloak,C=org")));
Assert.assertTrue(dn.isDescendantOf(LDAPDn.fromString("OU=, o=keycloak,c=org")));
Assert.assertFalse(dn.isDescendantOf(LDAPDn.fromString("ou=People, O=keycloak,C=org")));
}
@Test
public void testCorrectEscape() throws Exception {
LDAPDn dn = LDAPDn.fromString("dc=keycloak, dc=org");