當前位置: 首頁>>代碼示例>>Java>>正文


Java LdapName.getRdns方法代碼示例

本文整理匯總了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;
}
 
開發者ID:spyhunter99,項目名稱:installcert,代碼行數:15,代碼來源:InstallCert.java

示例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);
  }
}
 
開發者ID:SK-EID,項目名稱:smart-id-java-client,代碼行數:23,代碼來源:AuthenticationResponseValidator.java

示例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;
}
 
開發者ID:vmware,項目名稱:photon-model,代碼行數:24,代碼來源:CertificateUtil.java

示例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;
}
 
開發者ID:Pardus-Engerek,項目名稱:engerek,代碼行數:24,代碼來源:TestExchangeConnectorLow.java

示例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;
    }
}
 
開發者ID:laverca,項目名稱:laverca,代碼行數:31,代碼來源:CmsSignature.java

示例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;
}
 
開發者ID:laverca,項目名稱:laverca,代碼行數:25,代碼來源:X509Util.java

示例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;
    }
}
 
開發者ID:laverca,項目名稱:laverca,代碼行數:32,代碼來源:Pkcs1.java

示例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;
}
 
開發者ID:esig,項目名稱:dss,代碼行數:32,代碼來源:DSSASN1Utils.java

示例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");
    }
}
 
開發者ID:MariaDB,項目名稱:mariadb-connector-j,代碼行數:17,代碼來源:HostnameVerifierImpl.java

示例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;
}
 
開發者ID:Appverse,項目名稱:appverse-server,代碼行數:26,代碼來源:CertServiceImpl.java

示例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++;
    }
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:33,代碼來源:LdapNameTest.java

示例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;
}
 
開發者ID:NoYouShutup,項目名稱:CryptMeme,代碼行數:26,代碼來源:CertUtil.java

示例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");
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:13,代碼來源:Signer.java

示例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;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:50,代碼來源:ServiceLocator.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:50,代碼來源:ServiceLocator.java


注:本文中的javax.naming.ldap.LdapName.getRdns方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。