Skip to content

Commit 87f7ec5

Browse files
committed
KEYCLOAK-1561 LDAPDn.getParentDn() return value is not a DN
1 parent 18583eb commit 87f7ec5

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

federation/ldap/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
<artifactId>jboss-logging</artifactId>
5353
<scope>provided</scope>
5454
</dependency>
55+
<dependency>
56+
<groupId>junit</groupId>
57+
<artifactId>junit</artifactId>
58+
<scope>test</scope>
59+
</dependency>
5560
</dependencies>
5661

5762
<build>

federation/ldap/src/main/java/org/keycloak/federation/ldap/idm/model/LDAPDn.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.keycloak.federation.ldap.idm.model;
22

3+
import java.util.Collection;
34
import java.util.Deque;
45
import java.util.LinkedList;
56
import java.util.regex.Matcher;
@@ -26,6 +27,10 @@ public static LDAPDn fromString(String dnString) {
2627

2728
@Override
2829
public String toString() {
30+
return toString(entries);
31+
}
32+
33+
private static String toString(Collection<Entry> entries) {
2934
StringBuilder builder = new StringBuilder();
3035

3136
boolean first = true;
@@ -62,7 +67,9 @@ public String getFirstRdnAttrName() {
6267
* @return string like "dc=something,dc=org" from the DN like "uid=joe,dc=something,dc=org"
6368
*/
6469
public String getParentDn() {
65-
return new LinkedList<>(entries).remove().toString();
70+
LinkedList<Entry> parentDnEntries = new LinkedList<>(entries);
71+
parentDnEntries.remove();
72+
return toString(parentDnEntries);
6673
}
6774

6875
public void addFirst(String rdnName, String rdnValue) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.keycloak.federation.ldap.idm.model;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
/**
7+
* @author <a href="mailto:[email protected]">Marek Posolda</a>
8+
*/
9+
public class LDAPDnTest {
10+
11+
@Test
12+
public void testDn() throws Exception {
13+
LDAPDn dn = LDAPDn.fromString("dc=keycloak, dc=org");
14+
dn.addFirst("ou", "People");
15+
Assert.assertEquals("ou=People,dc=keycloak,dc=org", dn.toString());
16+
17+
dn.addFirst("uid", "Johny,Depp");
18+
Assert.assertEquals("uid=Johny\\,Depp,ou=People,dc=keycloak,dc=org", dn.toString());
19+
20+
Assert.assertEquals("ou=People,dc=keycloak,dc=org", dn.getParentDn());
21+
}
22+
}

0 commit comments

Comments
 (0)