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("(?<!\\\\),"); String[] rdns = dnString.split("(?<!\\\\),");
for (String entryStr : rdns) { for (String entryStr : rdns) {
String[] rdn = entryStr.split("(?<!\\\\)="); String[] rdn = entryStr.split("(?<!\\\\)=");
dn.addLast(rdn[0].trim(), rdn[1].trim()); if (rdn.length >1) {
dn.addLast(rdn[0].trim(), rdn[1].trim());
} else {
dn.addLast(rdn[0].trim(), "");
}
} }
return dn; return dn;

View file

@ -47,6 +47,25 @@ public class LDAPDnTest {
Assert.assertEquals("Johny,Depp+Pepp\\Foo", dn.getFirstRdnAttrValue()); 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 @Test
public void testCorrectEscape() throws Exception { public void testCorrectEscape() throws Exception {
LDAPDn dn = LDAPDn.fromString("dc=keycloak, dc=org"); LDAPDn dn = LDAPDn.fromString("dc=keycloak, dc=org");