This commit fixes the unable to parse the DN issue

Currently when a DN cannot be parsed if the DN is not in RFC2253 format. This commit fixeds this issue.
revert-70aa11f8
Madawa Soysa 7 years ago
parent 9cbc4a5da3
commit 72a09bf90b

@ -323,22 +323,28 @@ public class CertificateGenerator {
CertificateResponse lookUpCertificate = null; CertificateResponse lookUpCertificate = null;
KeyStoreReader keyStoreReader = new KeyStoreReader(); KeyStoreReader keyStoreReader = new KeyStoreReader();
if (distinguishedName != null && !distinguishedName.isEmpty()) { if (distinguishedName != null && !distinguishedName.isEmpty()) {
if (distinguishedName.contains("/CN=")) {
String[] dnSplits = distinguishedName.split("/CN=");
String commonNameExtracted = dnSplits[dnSplits.length - 1];
lookUpCertificate = keyStoreReader.getCertificateBySerial(commonNameExtracted);
} else {
LdapName ldapName; LdapName ldapName;
try { try {
ldapName = new LdapName(distinguishedName); ldapName = new LdapName(distinguishedName);
} catch (InvalidNameException e) { } catch (InvalidNameException e) {
throw new KeystoreException( throw new KeystoreException(
"Invalid name exception while trying to create a LDAP name using the distinguished name ", e); "Invalid name exception while trying to create a LDAP name using the distinguished name ",
e);
} }
for (Rdn relativeDistinuguishedNames : ldapName.getRdns()) { for (Rdn relativeDistinguishedNames : ldapName.getRdns()) {
if (relativeDistinuguishedNames.getType().equalsIgnoreCase("CN")) { if (relativeDistinguishedNames.getType().equalsIgnoreCase("CN")) {
System.err.println("CN is: " + relativeDistinuguishedNames.getValue());
lookUpCertificate = keyStoreReader lookUpCertificate = keyStoreReader
.getCertificateBySerial(String.valueOf(relativeDistinuguishedNames.getValue())); .getCertificateBySerial(String.valueOf(relativeDistinguishedNames.getValue()));
break; break;
} }
} }
} }
}
return lookUpCertificate; return lookUpCertificate;
} }

Loading…
Cancel
Save