1

I was test driving the X500Principal class like so:

Map<String, String> attr = new LinkedHashMap<String, String>();
attr.put("CN", "Duke");
attr.put("O", "JavaSoft");
X500Principal p1 = new X500Principal("", attr);
X500Principal p2 = new X500Principal("CN=Duke,O=JavaSoft");

From the Javadocs, one should get the impression that p1 and p2 should compare equal, but unfortunately they don't. Using the various getName methods on p1 I could figure that I always get an empty string.

So I wonder what's the point of passing in a map into the constructor (or the getName(String, Map) method)?

4

2 回答 2

3

关键字映射应将属性名称映射到 OID 字符串。这个想法是您可以定义自己的不属于标准列表(CN、O、OU 等)的属性名称。

所以用法会是这样的:

Map<String, String> attr = new HashMap<String, String>();
attr.put("FOO", "1.2.3.4.5.6.7.8.9");
X500Principal p = new X500Principal("CN=bar,FOO=baz", attr);
于 2013-05-17T07:49:29.773 回答
0

查看该构造函数的javadoc。具体来说,它将关键字映射参数描述为

属性类型关键字映射,其中每个关键字都是关键字 String,它映射到 String 形式的对应对象标识符(由句点分隔的非负整数序列)。地图可能为空,但绝不为空。

基本上,keywordMap 不能替代 X.500 专有名称,它完全是另外一回事。

于 2013-05-17T07:48:14.820 回答