本文整理汇总了Java中javax.naming.ldap.LdapName.getRdns方法的典型用法代码示例。如果您正苦于以下问题:Java LdapName.getRdns方法的具体用法?Java LdapName.getRdns怎么用?Java LdapName.getRdns使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.naming.ldap.LdapName
的用法示例。
在下文中一共展示了LdapName.getRdns方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCommonName
import javax.naming.ldap.LdapName; //导入方法依赖的package包/类
public static String getCommonName(X509Certificate cert)
throws InvalidNameException {
// use LDAP API to parse the certifiate Subject :)
// see http://stackoverflow.com/a/7634755/972463
LdapName ldapDN
= new LdapName(cert.getSubjectX500Principal().getName());
String cn = "";
for (Rdn rdn : ldapDN.getRdns()) {
if (rdn.getType().equals("CN")) {
cn = rdn.getValue().toString();
}
}
return cn;
}
示例2: constructAuthenticationIdentity
import javax.naming.ldap.LdapName; //导入方法依赖的package包/类
private AuthenticationIdentity constructAuthenticationIdentity(X509Certificate certificate) {
AuthenticationIdentity identity = new AuthenticationIdentity();
try {
LdapName ln = new LdapName(certificate.getSubjectDN().getName());
for(Rdn rdn : ln.getRdns()) {
if(rdn.getType().equalsIgnoreCase("GIVENNAME")) {
identity.setGivenName(rdn.getValue().toString());
} else if(rdn.getType().equalsIgnoreCase("SURNAME")) {
identity.setSurName(rdn.getValue().toString());
} else if(rdn.getType().equalsIgnoreCase("SERIALNUMBER")) {
identity.setIdentityCode(rdn.getValue().toString().split("-")[1]);
} else if(rdn.getType().equalsIgnoreCase("C")) {
identity.setCountry(rdn.getValue().toString());
}
}
return identity;
} catch (InvalidNameException e) {
logger.error("Error getting authentication identity from the certificate", e);
throw new TechnicalErrorException("Error getting authentication identity from the certificate", e);
}
}
示例3: getAttributeFromDN
import javax.naming.ldap.LdapName; //导入方法依赖的package包/类
/**
* Extracts from DN a given attribute.
* @param dn
* The entire DN
* @param attribute
* The attribute to extract
* @return the attribute value or null if not found an attribute with the given dn.
*/
public static String getAttributeFromDN(String dn, String attribute) {
try {
LdapName subjectDn = new LdapName(dn);
for (Rdn rdn : subjectDn.getRdns()) {
if (rdn.getType().equals(attribute)) {
return rdn.getValue().toString();
}
}
} catch (InvalidNameException e) {
throw new IllegalArgumentException(e);
}
return null;
}
示例4: distributionGroupOU
import javax.naming.ldap.LdapName; //导入方法依赖的package包/类
private String distributionGroupOU() throws InvalidNameException {
LdapName container = new LdapName(getContainer());
List<String> ous = new ArrayList<>();
List<String> dcs = new ArrayList<>();
String retval = "";
for (Rdn rdn : container.getRdns()) {
if (rdn.getType().equalsIgnoreCase("OU")) {
ous.add(rdn.getValue().toString());
} else if (rdn.getType().equalsIgnoreCase("DC")) {
dcs.add(rdn.getValue().toString());
}
}
for (int i = dcs.size()-1; i >= 0; i--) {
if (!retval.isEmpty()) {
retval += ".";
}
retval += dcs.get(i);
}
for (int i = 0; i < ous.size(); i++) {
retval += "/" + ous.get(i);
}
return retval;
}
示例5: getSignerCn
import javax.naming.ldap.LdapName; //导入方法依赖的package包/类
/**
* Convenience method. Equivalent to calling getSignerCert and
* then parsing out the CN from the certificate's Subject field.
* @return Signer CN or null if there's a problem.
*/
@Override
public String getSignerCn() {
try {
X509Certificate signerCert = this.getSignerCert();
String dn = signerCert.getSubjectX500Principal().getName();
String cn = null;
try {
LdapName ldapDn = new LdapName(dn);
List<Rdn> rdns = ldapDn.getRdns();
for(Rdn r : rdns) {
if("CN".equals(r.getType())) {
cn = r.getValue().toString();
}
}
} catch(InvalidNameException e) {
log.warn("Invalid name", e);
}
return cn;
} catch(Throwable t) {
log.error("Failed to get signer CN: " + t.getMessage());
return null;
}
}
示例6: parseSubjectName
import javax.naming.ldap.LdapName; //导入方法依赖的package包/类
/**
* Parse the given RND type from the given certificate's subject
* @param cert Certificate
* @param rdnType RND type
* @return parsed value as String
*/
public static String parseSubjectName(final X509Certificate cert, final String rdnType) {
String dn = cert.getSubjectX500Principal().getName();
String name = null;
try {
LdapName ldapDn = new LdapName(dn);
List<Rdn> rdns = ldapDn.getRdns();
for(Rdn r : rdns) {
if(rdnType.equals(r.getType())) {
name = r.getValue().toString();
}
}
} catch(InvalidNameException e) {
log.error(e);
}
return name;
}
示例7: getSignerCn
import javax.naming.ldap.LdapName; //导入方法依赖的package包/类
/**
* Get the signer CN.
* <p>Equivalent to calling getSignerCert and
* then parsing out the CN from the certificate's Subject field.
* @return Signer's CN or null if there's a problem.
*/
@Override
public String getSignerCn() {
try {
X509Certificate signerCert = this.getSignerCert();
String dn = signerCert.getSubjectX500Principal().getName();
String cn = null;
try {
LdapName ldapDn = new LdapName(dn);
List<Rdn> rdns = ldapDn.getRdns();
for (Rdn r : rdns) {
if("CN".equals(r.getType())) {
cn = r.getValue().toString();
}
}
} catch(InvalidNameException e) {
log.warn("Invalid name", e);
}
return cn;
} catch (Throwable t) {
log.error("Failed to get Signer cert " + t.getMessage());
return null;
}
}
示例8: getCanonicalizedName
import javax.naming.ldap.LdapName; //导入方法依赖的package包/类
/**
* This method can be removed the simple IssuerSerial verification can be
* performed. In fact the hash verification is sufficient.
*
* @param generalNames
* @return
*/
public static String getCanonicalizedName(final GeneralNames generalNames) {
GeneralName[] names = generalNames.getNames();
TreeMap<String, String> treeMap = new TreeMap<String, String>();
for (GeneralName name : names) {
String ldapString = String.valueOf(name.getName());
LOG.debug("ldapString to canonicalize: {} ", ldapString);
try {
LdapName ldapName = new LdapName(ldapString);
List<Rdn> rdns = ldapName.getRdns();
for (final Rdn rdn : rdns) {
treeMap.put(rdn.getType().toLowerCase(), String.valueOf(rdn.getValue()).toLowerCase());
}
} catch (InvalidNameException e) {
throw new DSSException(e);
}
}
StringBuilder stringBuilder = new StringBuilder();
for (Entry<String, String> entry : treeMap.entrySet()) {
stringBuilder.append(entry.getKey()).append('=').append(entry.getValue()).append('|');
}
final String canonicalizedName = stringBuilder.toString();
LOG.debug("canonicalizedName: {} ", canonicalizedName);
return canonicalizedName;
}
示例9: extractCommonName
import javax.naming.ldap.LdapName; //导入方法依赖的package包/类
private static String extractCommonName(String principal) throws SSLException {
if (principal == null) return null;
try {
LdapName ldapName = new LdapName(principal);
for (Rdn rdn : ldapName.getRdns()) {
if (rdn.getType().equalsIgnoreCase("CN")) {
Object obj = rdn.getValue();
if (obj != null) return obj.toString();
}
}
return null;
} catch (InvalidNameException e) {
throw new SSLException("DN value \"" + principal + "\" is invalid");
}
}
示例10: getName
import javax.naming.ldap.LdapName; //导入方法依赖的package包/类
/**
* Retrieves the name for the given certificate.
*
* @param certificate the certificate to get its name for, cannot be <code>null</code>.
* @return the name for the given certificate, can be <code>null</code>.
*/
@Override
public String getName(final X509Certificate certificate) {
try {
String dn = certificate.getSubjectX500Principal().getName();
if ("dn".equalsIgnoreCase("cn")) {
return dn;
}
LdapName ldapDN = new LdapName(dn);
for (Rdn rdn : ldapDN.getRdns()) {
if ("cn".equalsIgnoreCase(rdn.getType())) {
return (String) rdn.getValue();
}
}
} catch (InvalidNameException e) {
// Ignore...
}
return null;
}
示例11: testLdapNameListOfRdn004
import javax.naming.ldap.LdapName; //导入方法依赖的package包/类
/**
* <p>
* Test method for 'javax.naming.ldap.LdapName.LdapName(List<Rdn>)'
* </p>
* <p>
* Here we are testing the constructor of LdapName with a list of valid
* names.
* </p>
* <p>
* The expected result is an instance of LdapName, with the indexing
* correct.
* </p>
*/
public void testLdapNameListOfRdn004() throws Exception {
LinkedList<Rdn> test = new LinkedList<Rdn>();
test.add(new Rdn("CN=commonName"));
test.add(new Rdn("L=localityName"));
test.add(new Rdn("ST=stateOrProvinceName"));
test.add(new Rdn("O=organizationName"));
test.add(new Rdn("OU=organizationalUnitName"));
LdapName x = new LdapName(test);
assertNotNull(x);
List t = x.getRdns();
int i = 0;
for (Iterator iter = test.iterator(); iter.hasNext();) {
Rdn element = (Rdn) iter.next();
assertEquals(element.toString(), t.get(i).toString());
i++;
}
}
示例12: getSubjectValue
import javax.naming.ldap.LdapName; //导入方法依赖的package包/类
/**
* Get a value out of the subject distinguished name.
*
* Warning - unsupported in Android (no javax.naming), returns null.
*
* @param type e.g. "CN"
* @return value or null if not found
*/
public static String getSubjectValue(X509Certificate cert, String type) {
if (SystemVersion.isAndroid()) {
error("Don't call this in Android", new UnsupportedOperationException("I did it"));
return null;
}
type = type.toUpperCase(Locale.US);
X500Principal p = cert.getSubjectX500Principal();
String subj = p.getName();
try {
LdapName name = new LdapName(subj);
for (Rdn rdn : name.getRdns()) {
if (type.equals(rdn.getType().toUpperCase(Locale.US)))
return (String) rdn.getValue();
}
} catch (InvalidNameException ine) {}
return null;
}
示例13: getSubjectName
import javax.naming.ldap.LdapName; //导入方法依赖的package包/类
private static String getSubjectName(final X509Certificate cert)
throws InvalidNameException {
final String fullSubjectDn = cert.getSubjectX500Principal().getName();
final LdapName fullSubjectLn = new LdapName(fullSubjectDn);
for (final Rdn rdn: fullSubjectLn.getRdns()) {
if ("CN".equalsIgnoreCase(rdn.getType())) {
return rdn.getValue().toString();
}
}
throw new InvalidNameException("Common name not found");
}
示例14: mapDnToDomainName
import javax.naming.ldap.LdapName; //导入方法依赖的package包/类
/**
* Maps a distinguished name (RFC 2253) to a fully qualified domain name.
* Processes a sequence of RDNs having a DC attribute.
* The special RDN "DC=." denotes the root of the domain tree.
* Multi-valued RDNs, non-DC attributes, binary-valued attributes and the
* RDN "DC=." all reset the domain name and processing continues.
*
* @param dn A string distinguished name (RFC 2253).
* @return A domain name or null if none can be derived.
* @throw InvalidNameException If the distinugished name is invalid.
*/
static String mapDnToDomainName(String dn) throws InvalidNameException {
if (dn == null) {
return null;
}
StringBuffer domain = new StringBuffer();
LdapName ldapName = new LdapName(dn);
// process RDNs left-to-right
//List<Rdn> rdnList = ldapName.getRdns();
List<Rdn> rdnList = ldapName.getRdns();
for (int i = rdnList.size() - 1; i >= 0; i--) {
//Rdn rdn = rdnList.get(i);
Rdn rdn = rdnList.get(i);
// single-valued RDN with a DC attribute
if ((rdn.size() == 1) &&
("dc".equalsIgnoreCase(rdn.getType()) )) {
Object attrval = rdn.getValue();
if (attrval instanceof String) {
if (attrval.equals(".") ||
(domain.length() == 1 && domain.charAt(0) == '.')) {
domain.setLength(0); // reset (when current or previous
// RDN value is "DC=.")
}
if (domain.length() > 0) {
domain.append('.');
}
domain.append(attrval);
} else {
domain.setLength(0); // reset (when binary-valued attribute)
}
} else {
domain.setLength(0); // reset (when multi-valued RDN or non-DC)
}
}
return (domain.length() != 0) ? domain.toString() : null;
}
示例15: mapDnToDomainName
import javax.naming.ldap.LdapName; //导入方法依赖的package包/类
/**
* Maps a distinguished name (RFC 2253) to a fully qualified domain name.
* Processes a sequence of RDNs having a DC attribute.
* The special RDN "DC=." denotes the root of the domain tree.
* Multi-valued RDNs, non-DC attributes, binary-valued attributes and the
* RDN "DC=." all reset the domain name and processing continues.
*
* @param dn A string distinguished name (RFC 2253).
* @return A domain name or null if none can be derived.
* @throws InvalidNameException If the distinguished name is invalid.
*/
static String mapDnToDomainName(String dn) throws InvalidNameException {
if (dn == null) {
return null;
}
StringBuilder domain = new StringBuilder();
LdapName ldapName = new LdapName(dn);
// process RDNs left-to-right
//List<Rdn> rdnList = ldapName.getRdns();
List<Rdn> rdnList = ldapName.getRdns();
for (int i = rdnList.size() - 1; i >= 0; i--) {
//Rdn rdn = rdnList.get(i);
Rdn rdn = rdnList.get(i);
// single-valued RDN with a DC attribute
if ((rdn.size() == 1) &&
("dc".equalsIgnoreCase(rdn.getType()) )) {
Object attrval = rdn.getValue();
if (attrval instanceof String) {
if (attrval.equals(".") ||
(domain.length() == 1 && domain.charAt(0) == '.')) {
domain.setLength(0); // reset (when current or previous
// RDN value is "DC=.")
}
if (domain.length() > 0) {
domain.append('.');
}
domain.append(attrval);
} else {
domain.setLength(0); // reset (when binary-valued attribute)
}
} else {
domain.setLength(0); // reset (when multi-valued RDN or non-DC)
}
}
return (domain.length() != 0) ? domain.toString() : null;
}