本文整理汇总了Java中javax.naming.ldap.Rdn类的典型用法代码示例。如果您正苦于以下问题:Java Rdn类的具体用法?Java Rdn怎么用?Java Rdn使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Rdn类属于javax.naming.ldap包,在下文中一共展示了Rdn类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCommonName
import javax.naming.ldap.Rdn; //导入依赖的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.Rdn; //导入依赖的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: compareDNs
import javax.naming.ldap.Rdn; //导入依赖的package包/类
/**
* 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;
}
}
示例4: getAttributeFromDN
import javax.naming.ldap.Rdn; //导入依赖的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;
}
示例5: testComposeDn
import javax.naming.ldap.Rdn; //导入依赖的package包/类
@Test
public void testComposeDn() throws Exception {
final String TEST_NAME = "testComposeDn";
TestUtil.displayTestTile(TEST_NAME);
BasicExpressionFunctions basic = createBasicFunctions();
assertEquals("cn=foo,o=bar", basic.composeDn("cn","foo","o","bar"));
assertEquals("cn=foo,o=bar", basic.composeDn("cn",PrismTestUtil.createPolyString("foo"),"o","bar"));
assertEquals("cn=foo,o=bar", basic.composeDn("cn",PrismTestUtil.createPolyStringType("foo"),"o","bar"));
assertEquals("cn=foo,o=bar", basic.composeDn("cn","foo",new Rdn("o","bar")));
assertEquals("cn=foo,ou=baz,o=bar", basic.composeDn(new Rdn("cn","foo"),"ou","baz",new Rdn("o","bar")));
assertEquals("cn=foo,ou=baz,o=bar", basic.composeDn(new Rdn("cn","foo"),"ou","baz","o","bar"));
assertEquals("cn=foo,ou=baz,o=bar", basic.composeDn(new Rdn("cn","foo"),new LdapName("ou=baz,o=bar")));
assertEquals("cn=foo,ou=baz,o=bar", basic.composeDn("cn","foo",new LdapName("ou=baz,o=bar")));
assertEquals("cn=foo\\,foo,ou=baz,o=bar", basic.composeDn("cn","foo,foo",new LdapName("ou=baz,o=bar")));
assertEquals("cn=foo\\=foo,ou=baz,o=bar", basic.composeDn("cn","foo=foo",new LdapName("ou=baz,o=bar")));
assertEquals(null, basic.composeDn(null));
assertEquals(null, basic.composeDn());
assertEquals(null, basic.composeDn(""));
assertEquals(null, basic.composeDn(" "));
}
示例6: distributionGroupOU
import javax.naming.ldap.Rdn; //导入依赖的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;
}
示例7: printEscapedVal
import javax.naming.ldap.Rdn; //导入依赖的package包/类
static void printEscapedVal(Object[] values) {
String escVal;
for (int i = 0; i < values.length; i++) {
escVal = Rdn.escapeValue(values[i]);
System.out.println("Orig val: " + values[i] +
" Escaped val: " + escVal);
}
}
示例8: getSignerCn
import javax.naming.ldap.Rdn; //导入依赖的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;
}
}
示例9: parseSubjectName
import javax.naming.ldap.Rdn; //导入依赖的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;
}
示例10: getSignerCn
import javax.naming.ldap.Rdn; //导入依赖的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;
}
}
示例11: getCanonicalizedName
import javax.naming.ldap.Rdn; //导入依赖的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;
}
示例12: getACLs
import javax.naming.ldap.Rdn; //导入依赖的package包/类
protected Set<GroupPrincipal> getACLs(String destinationBase, SearchControls constraints, String roleBase, String roleAttribute) {
try {
Set<GroupPrincipal> roles = new HashSet<GroupPrincipal>();
Set<String> acls = new HashSet<String>();
NamingEnumeration<?> results = context.search(destinationBase, roleBase, constraints);
while (results.hasMore()) {
SearchResult result = (SearchResult)results.next();
Attributes attrs = result.getAttributes();
if (attrs == null) {
continue;
}
acls = addAttributeValues(roleAttribute, attrs, acls);
}
for (Iterator<String> iter = acls.iterator(); iter.hasNext();) {
String roleName = iter.next();
LdapName ldapname = new LdapName(roleName);
Rdn rdn = ldapname.getRdn(ldapname.size() - 1);
LOG.debug("Found role: [" + rdn.getValue().toString() + "]");
roles.add(new GroupPrincipal(rdn.getValue().toString()));
}
return roles;
} catch (NamingException e) {
LOG.error(e.toString());
return new HashSet<GroupPrincipal>();
}
}
示例13: extractCommonName
import javax.naming.ldap.Rdn; //导入依赖的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");
}
}
示例14: getName
import javax.naming.ldap.Rdn; //导入依赖的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;
}
示例15: testCompareTo011
import javax.naming.ldap.Rdn; //导入依赖的package包/类
/**
* <p>
* Test method for 'javax.naming.ldap.Rdn.compareTo(Object)'
* </p>
* <p>
* Here we are testing if this method correctly compares an Rdn with another
* object.
* </p>
* <p>
* The expected result is 0.
* </p>
*/
public void testCompareTo011() throws Exception {
String x1 = "t=test+a= anything+A=\\#080808<a+c=c=#0808+"
+ "asd=asd=asd=asd=asd=asd=asd=Asd<asd<asd>asd>asd>asd+"
+ "asd=asd=asd=asd=asd=asd=asd=Asd<asd<asd>asd>asd>asd+"
+ "asd=asd=asd=asd=asd=asd=asd=Asd<asd<asd>asd>asd>asd+"
+ "asd=asd=asd=asd=asd=asd=asd=Asd<asd<asd>asd>asd>asd+"
+ "a=<z>=at+a=<z>=at+a=<z>=at+a=<z>=at+a=>z<=at+a=>z<=at+a=>z<=at"
+ "+v================================+a=+a=+a=+a=+a=+a=+a=+a=+a=+a=+a=+a=+a="
+ "+a=+a=+a=+a=+a=+a=+a=+a=+a=+a=+a=+a========a+s=s<>ss";
String x2 = "asd=asd=asd=asd=asd=asd=asd=Asd<asd<asd>asd>asd>asd+"
+ "asd=asd=asd=asd=asd=asd=asd=Asd<asd<asd>asd>asd>asd+"
+ "asd=asd=asd=asd=asd=asd=asd=Asd<asd<asd>asd>asd>asd+"
+ "asd=asd=asd=asd=asd=asd=asd=Asd<asd<asd>asd>asd>asd+"
+ "a=<z>=at+a=<z>=at+a=<z>=at+a=<z>=at+a=>z<=at+a=>z<=at+a=>z<=at"
+ "+v================================+a=+a=+a=+a=+a=+a=+a=+a=+a=+a=+a=+a=+a="
+ "+a=+a=+a=+a=+a=+a=+a=+a=+a=+a=+a=+a========a+s=s<>ss+"
+ "A=\\#080808<a+c=c=#0808+t=test+a= anything";
Rdn rdn1 = new Rdn(x1);
Rdn rdn2 = new Rdn(x2);
assertEquals(0, rdn1.compareTo(rdn2));
}