[英]What is the correct format for SECURITY_PRINCIPAL in LDAP authentication using "com.sun.jndi.ldap.LdapCtxFactory"
[英]Reading the LDAP security principal
我有一个从X509Certificate上获得的字符串
UID =唯一ID,CN =通用名称,C =国家/地区代码,ST =州
对我来说,这看起来很荒谬,然后我认为也许存在一个Java LDAP API,可以为我对该字符串进行标记化,所以我可能会得到一个名称为键,内容为值的映射或类似的名称。 是否存在?
有内置在至少两个的Java API: javax.naming.NameParser
从LDAP衍生Context
,这将产生一个javax.naming.Name
; 和javax.naming.ldap.LdapName
。
在我发布问题后,我决定最后看一下Java API-猜我发现了什么:LdapName。 Hat类做我所做的事情,甚至验证输入。
所以现在我得到以下代码:
LdapName ldapName = new LdapName(dn);
List<Rdn> distinguishedNames = ldapName.getRdns();
for (Rdn rdn : distinguishedNames) {
if ("c".equals(name.getType().toLowerCase())) {
country = (String) name.getValue();
}
...
}
我不知道有任何分词器。 您可能为此“滥用”基于Map的java.util.Properites
:
String cert = "UID=A unique id,CN=Common name,C=country code, ST=state";
cert = cert.replaceAll(",", "\n");
Properties props = new Properties();
props.load(new StringReader(cert));
System.out.println(props.getProperty("UID"));
System.out.println(props.getProperty("CN"));
System.out.println(props.getProperty("C"));
System.out.println(props.getProperty("ST"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.