0

从我的活动目录服务器获取名称时,我总是收到错误消息。错误如下:

javax.naming.InvalidNameException: Invalid name: "CN=»OGMA Serviço LAN/WAN",cn=Recipients,cn=Users,,dc=intra

谷歌搜索了一下,我发现了以下信息

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4307193 http://docs.oracle.com/javase/jndi/tutorial/beyond/names/syntax.html

如您所见,我尝试了解析器方法和复合名称方法,但错误仍然存​​在!我错过了什么?

这是我执行这些操作的代码:

DirContext ctx = new InitialDirContext( (Hashtable<String,String>) env);

Name n2 = new CompositeName().add(usersContainer);
NamingEnumeration contentsEnum = ctx.list(n2);

String[] attName = {"cn"};

while ( contentsEnum.hasNext() ) {
    NameClassPair ncp = (NameClassPair) contentsEnum.next();
    NameParser ldapParser = ctx.getNameParser("");

    String name = ncp.getName() + "," + usersContainer;
    Name n = ldapParser.parse(name);

    ctx.lookup(n);

变量name"CN=»OGMA Serviço LAN/WAN" + cn=Recipients,cn=Users,,dc=intra

4

1 回答 1

0

我不明白你为什么首先要做这么复杂的事情。如果您使用Context.listBindings()而不是,则Context.list(),可以完全避免构建名称和查找,因为您已经拥有名称和绑定。您的代码将减少为:

NamingEnumeration<Binding> contentsEnum = ctx.listBindings(n2);

String[] attName = {"cn"};

while ( contentsEnum.hasNext() ) {
    Binding binding = contentsEnum.next();
    Object o = binding.getObject();
    // etc, whatever you were intending to do with the result of lookup(), which is now in 'o'.
}
于 2012-06-17T11:50:07.983 回答