/** * Get the value of the {@link LdapRdnComponent} with the specified key * (Attribute value). If there are several Rdns with the same key, the value * of the first one found (in order of significance) will be returned. * * @param key Attribute name of the {@link LdapRdn} to retrieve. * @return the value. * @throws IllegalArgumentException if no Rdn matches the given key. */ public String getValue(String key) { return getLdapRdn(key).getValue(); }
/** * Get the value of the {@link LdapRdnComponent} with the specified key * (Attribute value). If there are several Rdns with the same key, the value * of the first one found (in order of significance) will be returned. * * @param key Attribute name of the {@link LdapRdn} to retrieve. * @return the value. * @throws IllegalArgumentException if no Rdn matches the given key. */ public String getValue(String key) { return getLdapRdn(key).getValue(); }
/** * Get the value of the {@link LdapRdnComponent} with the specified key * (Attribute value). If there are several Rdns with the same key, the value * of the first one found (in order of significance) will be returned. * * @param key Attribute name of the {@link LdapRdn} to retrieve. * @return the value. * @throws IllegalArgumentException if no Rdn matches the given key. */ public String getValue(String key) { return getLdapRdn(key).getValue(); }
/** * Get the value of the {@link LdapRdnComponent} with the specified key * (Attribute value). If there are several Rdns with the same key, the value * of the first one found (in order of significance) will be returned. * * @param key Attribute name of the {@link LdapRdn} to retrieve. * @return the value. * @throws IllegalArgumentException if no Rdn matches the given key. */ public String getValue(String key) { return getLdapRdn(key).getValue(); }
@Test(expected = IllegalArgumentException.class) public void testGetLdapRdnForKeyNoMatchingKeyThrowsException() throws Exception { DistinguishedName dn = new DistinguishedName("cn=john doe, ou=Some company, c=SE"); dn.getLdapRdn("nosuchkey"); }
@Test public void testGetLdapRdnForKey() throws Exception { DistinguishedName dn = new DistinguishedName("cn=john doe, ou=Some company, c=SE"); LdapRdn ldapRdn = dn.getLdapRdn("ou"); assertThat(ldapRdn).isEqualTo(new LdapRdn("ou=Some company")); }
/** * Test for http://forum.springsource.org/showthread.php?t=86640. */ @Test public void testDistinguishedNameWithDotParsesProperly() { DistinguishedName name = new DistinguishedName("cn=first.last,OU=DevTest Users,DC=xyz,DC=com"); assertThat(name.toCompactString()).isEqualTo("cn=first.last,ou=DevTest Users,dc=xyz,dc=com"); DistinguishedName dn = new DistinguishedName(); dn.parse("cn=first.last,OU=DevTest Users,DC=xyz,DC=com"); assertThat(dn.getValue("cn")).isEqualTo("first.last"); assertThat(dn.getValue("ou")).isEqualTo("DevTest Users"); assertThat(dn.getLdapRdn(1).getValue()).isEqualTo("xyz"); assertThat(dn.getLdapRdn(0).getValue()).isEqualTo("com"); }
@Test public void testDistinguishedName() { String testPath = "cn=foo\\,bar,OU=FOO\\,bar , OU=foo\\;bar;OU=foo\\;bar" + " ; ou=foo\\,,ou=foo\\,;ou=foo\\;;ou=foo\\,;ou=bar\\,"; System.out.println(testPath); DistinguishedName path = new DistinguishedName(testPath); assertThat(path.getLdapRdn(8).getComponent().getKey()).isEqualTo("cn"); assertThat(path.getLdapRdn(8).getComponent().getValue()).isEqualTo("foo,bar"); assertThat(path.getLdapRdn(7).getComponent().getKey()).isEqualTo("ou"); assertThat(path.getLdapRdn(7).getComponent().getValue()).isEqualTo("FOO,bar"); assertThat(path.getLdapRdn(6).getComponent().getKey()).isEqualTo("ou"); assertThat(path.getLdapRdn(6).getComponent().getValue()).isEqualTo("foo;bar"); assertThat(path.getLdapRdn(5).getComponent().getKey()).isEqualTo("ou"); assertThat(path.getLdapRdn(5).getComponent().getValue()).isEqualTo("foo;bar"); assertThat(path.getLdapRdn(4).getComponent().getKey()).isEqualTo("ou"); assertThat(path.getLdapRdn(4).getComponent().getValue()).isEqualTo("foo,"); assertThat(path.getLdapRdn(3).getComponent().getKey()).isEqualTo("ou"); assertThat(path.getLdapRdn(3).getComponent().getValue()).isEqualTo("foo,"); assertThat(path.getLdapRdn(2).getComponent().getKey()).isEqualTo("ou"); assertThat(path.getLdapRdn(2).getComponent().getValue()).isEqualTo("foo;"); assertThat(path.getLdapRdn(1).getComponent().getKey()).isEqualTo("ou"); assertThat(path.getLdapRdn(1).getComponent().getValue()).isEqualTo("foo,"); assertThat(path.getLdapRdn(0).getComponent().getKey()).isEqualTo("ou"); assertThat(path.getLdapRdn(0).getComponent().getValue()).isEqualTo("bar,"); }
@Test(expected = UnsupportedOperationException.class) public void testUnmodifiableDistinguishedNameFailsToModifyRdn() throws Exception { DistinguishedName result = DistinguishedName.immutableDistinguishedName("cn=john doe"); LdapRdn ldapRdn = result.getLdapRdn(0); ldapRdn.addComponent(new LdapRdnComponent("somekey", "somevalue")); }
@Test(expected = UnsupportedOperationException.class) public void testUnmodifiableDistinguishedNameFailsToModifyRdnComponentKey() throws Exception { DistinguishedName result = DistinguishedName.immutableDistinguishedName("cn=john doe"); LdapRdnComponent component = result.getLdapRdn(0).getComponent(); component.setKey("somekey"); }
@Test(expected = UnsupportedOperationException.class) public void testUnmodifiableDistinguishedNameFailsToModifyRdnComponentValue() throws Exception { DistinguishedName result = DistinguishedName.immutableDistinguishedName("cn=john doe"); LdapRdnComponent component = result.getLdapRdn(0).getComponent(); component.setValue("somevalue"); }
LdapRdn rdn = name.getLdapRdn(name.size() - 1); if (rdn.getKey().equals(searchConfiguration.getLdapIdAttribute()))