我有一個字符串,我從一個x509證書獲取表單讀LDAP安全主體
UID上=唯一的ID,CN =通用名稱,C =國家代碼,ST =州
對我來說,看起來ldap'ish,然後我認爲也許存在一個Java的LDAP API,可以標記爲我的這個字符串,所以我可能得到一個地圖名稱作爲關鍵和內容作爲價值 - 或類似的東西。 這是否存在?
我有一個字符串,我從一個x509證書獲取表單讀LDAP安全主體
UID上=唯一的ID,CN =通用名稱,C =國家代碼,ST =州
對我來說,看起來ldap'ish,然後我認爲也許存在一個Java的LDAP API,可以標記爲我的這個字符串,所以我可能得到一個地圖名稱作爲關鍵和內容作爲價值 - 或類似的東西。 這是否存在?
好吧,我決定採取的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();
}
...
}
我不知道它的任何標記器。你可能會「濫用」 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"));
有建於至少兩個Java的API:從LDAP Context
,這將產生一個javax.naming.Name
衍生javax.naming.NameParser
;和javax.naming.ldap.LdapName
。
您可能會發現[UnboundID LDAP SDK](http://www.unboundid.com/products/ldap-sdk/)更易於使用。 – 2012-03-09 16:50:50