use of javax.naming.ldap.LdapName in project OpenAttestation by OpenAttestation.
the class DN method parseLdapName.
private void parseLdapName(String distinguishedName) {
try {
LdapName dn = new LdapName(distinguishedName);
for (int i = 0; i < dn.size(); i++) {
Rdn rdn = dn.getRdn(i);
map.put(rdn.getType(), rdn.getValue().toString());
}
} catch (InvalidNameException e) {
log.error("Cannot extract Common Name from Distinguished Name", e);
}
}
use of javax.naming.ldap.LdapName in project hadoop by apache.
the class LdapGroupsMapping method getRelativeDistinguishedName.
/**
* A helper method to get the Relative Distinguished Name (RDN) from
* Distinguished name (DN). According to Active Directory documentation,
* a group object's RDN is a CN.
*
* @param distinguishedName A string representing a distinguished name.
* @throws NamingException if the DN is malformed.
* @return a string which represents the RDN
*/
private String getRelativeDistinguishedName(String distinguishedName) throws NamingException {
LdapName ldn = new LdapName(distinguishedName);
List<Rdn> rdns = ldn.getRdns();
if (rdns.isEmpty()) {
throw new NamingException("DN is empty");
}
Rdn rdn = rdns.get(rdns.size() - 1);
if (rdn.getType().equalsIgnoreCase(groupNameAttr)) {
String groupName = (String) rdn.getValue();
return groupName;
}
throw new NamingException("Unable to find RDN: The DN " + distinguishedName + " is malformed.");
}
use of javax.naming.ldap.LdapName in project midpoint by Evolveum.
the class TestExpressionFunctions method testComposeDnWithSuffix.
@Test
public void testComposeDnWithSuffix() throws Exception {
final String TEST_NAME = "testComposeDnWithSuffix";
TestUtil.displayTestTile(TEST_NAME);
BasicExpressionFunctions basic = createBasicFunctions();
assertEquals("cn=foo,ou=baz,o=bar", basic.composeDnWithSuffix(new Rdn("cn", "foo"), "ou=baz,o=bar"));
assertEquals("cn=foo,ou=baz,o=bar", basic.composeDnWithSuffix(new Rdn("cn", "foo"), new LdapName("ou=baz,o=bar")));
assertEquals("cn=foo,ou=baz,o=bar", basic.composeDnWithSuffix("cn", "foo", "ou=baz,o=bar"));
assertEquals("cn=foo,ou=baz,o=bar", basic.composeDnWithSuffix("cn", PrismTestUtil.createPolyString("foo"), "ou=baz,o=bar"));
assertEquals("cn=foo,ou=baz,o=bar", basic.composeDnWithSuffix("cn", PrismTestUtil.createPolyStringType("foo"), "ou=baz,o=bar"));
assertEquals("cn=foo,ou=baz,o=bar", basic.composeDnWithSuffix("cn", "foo", new LdapName("ou=baz,o=bar")));
assertEquals("cn=foo,ou=baz\\,baz,o=bar", basic.composeDnWithSuffix("cn", "foo", "ou=baz\\,baz,o=bar"));
assertEquals("cn=foo,ou=baz\\,baz,o=bar", basic.composeDnWithSuffix("cn", "foo", new LdapName("ou=baz\\,baz,o=bar")));
assertEquals("cn=foo\\,foo,ou=baz,o=bar", basic.composeDnWithSuffix("cn", "foo,foo", "ou=baz,o=bar"));
assertEquals("cn=foo\\,foo,ou=baz,o=bar", basic.composeDnWithSuffix("cn", "foo,foo", new LdapName("ou=baz,o=bar")));
assertEquals("cn=foo\\=foo,ou=baz,o=bar", basic.composeDnWithSuffix("cn", "foo=foo", "ou=baz,o=bar"));
assertEquals("cn=foo\\=foo,ou=baz,o=bar", basic.composeDnWithSuffix("cn", "foo=foo", new LdapName("ou=baz,o=bar")));
assertEquals("ou=baz,o=bar", basic.composeDnWithSuffix("ou=baz,o=bar"));
assertEquals("ou=baz, o=bar", basic.composeDnWithSuffix("ou=baz, o=bar"));
assertEquals("OU=baz, o=bar", basic.composeDnWithSuffix("OU=baz, o=bar"));
assertEquals("ou=baz,o=bar", basic.composeDnWithSuffix(new LdapName("ou=baz,o=bar")));
assertEquals(null, basic.composeDnWithSuffix(null));
assertEquals(null, basic.composeDnWithSuffix());
assertEquals(null, basic.composeDnWithSuffix(""));
assertEquals(null, basic.composeDnWithSuffix(" "));
}
use of javax.naming.ldap.LdapName in project midpoint by Evolveum.
the class DistinguishedNameMatchingRule method match.
/* (non-Javadoc)
* @see com.evolveum.midpoint.model.match.MatchingRule#match(java.lang.Object, java.lang.Object)
*/
@Override
public boolean match(String a, String b) throws SchemaException {
if (StringUtils.isBlank(a) && StringUtils.isBlank(b)) {
return true;
}
if (StringUtils.isBlank(a) || StringUtils.isBlank(b)) {
return false;
}
LdapName dnA;
try {
dnA = new LdapName(a);
} catch (InvalidNameException e) {
throw new SchemaException("String '" + a + "' is not a DN: " + e.getMessage(), e);
}
LdapName dnB;
try {
dnB = new LdapName(b);
} catch (InvalidNameException e) {
throw new SchemaException("String '" + b + "' is not a DN: " + e.getMessage(), e);
}
return dnA.equals(dnB);
}
use of javax.naming.ldap.LdapName in project nifi by apache.
the class CertificateUtils method compareDNs.
/**
* Returns true if the two provided DNs are equivalent, regardless of the order of the elements. Returns false if one or both are invalid DNs.
*
* Example:
*
* CN=test1, O=testOrg, C=US compared to CN=test1, O=testOrg, C=US -> true
* CN=test1, O=testOrg, C=US compared to O=testOrg, CN=test1, C=US -> true
* CN=test1, O=testOrg, C=US compared to CN=test2, O=testOrg, C=US -> false
* CN=test1, O=testOrg, C=US compared to O=testOrg, CN=test2, C=US -> false
* CN=test1, O=testOrg, C=US compared to -> false
* compared to -> true
*
* @param dn1 the first DN to compare
* @param dn2 the second DN to compare
* @return true if the DNs are equivalent, false otherwise
*/
public static boolean compareDNs(String dn1, String dn2) {
if (dn1 == null) {
dn1 = "";
}
if (dn2 == null) {
dn2 = "";
}
if (StringUtils.isEmpty(dn1) || StringUtils.isEmpty(dn2)) {
return dn1.equals(dn2);
}
try {
List<Rdn> rdn1 = new LdapName(dn1).getRdns();
List<Rdn> rdn2 = new LdapName(dn2).getRdns();
return rdn1.size() == rdn2.size() && rdn1.containsAll(rdn2);
} catch (InvalidNameException e) {
logger.warn("Cannot compare DNs: {} and {} because one or both is not a valid DN", dn1, dn2);
return false;
}
}
Aggregations