gpt4 book ai didi

java - Nexus 和 LDAP - 针对 OpenLDAP 服务器验证用户时的 JNDI 问题

转载 作者:搜寻专家 更新时间:2023-11-01 03:45:32 26 4
gpt4 key购买 nike

我将 Nexus 存储库管理器 (nexus.sonatype.org) 与开源 LDAP 插件 (code.google.com/p/nexus-ldap/) 一起使用,但我收到一条错误消息,指出使用了错误的协议(protocol)版本 (详见下文)。该插件所做的全部工作是使用 JNDI LDAP 服务提供程序连接到我的 LDAP 服务器。如果您查看 nexus.log 文件中的堆栈跟踪,异常发生在 JNDI LDAP 实现中的上下文初始化期间。所以我的猜测是,下面描述的问题不是由 Nexus 插件引起的,而是由于 JNDI 的误用或对 LDAP 身份验证的误解引起的。

非常感谢任何关于错误是如何引起的猜测或想法!

哪些步骤会重现问题?

  1. 使用 OpenLDAP 1.2.x 服务器将 Nexus 配置为使用 LdapAuthenticatingRealm - 因此是 LDAP 协议(protocol)的版本 2。
  2. 尝试从 OpenLDAP-Server 列出用户并将他们映射到 Nexus 配置用户界面中的角色 - 效果完美。
  3. 现在尝试使用已成功映射到角色的 LDAP 用户登录或验证正在运行的 Nexus 实例。

预期的输出是什么?你看到了什么?

尝试登录时,我收到错误消息“用户名、密码不正确或无权使用 Nexus 用户界面。请重试。”。在 Nexus 日志文件中,当 Sun 的 JNDI-LDAP 实现(请参阅从下面的日志文件中获取的堆栈跟踪)尝试使用给定信息初始化上下文以便根据 LDAP 服务器对用户进行身份验证时,我看到抛出异常。使用 Nexus UI 的用户查找以及身份验证期间执行的查找工作正常(请参阅下面的日志文件)。

CommunicationException 中包含的错误消息(“[LDAP:错误代码 2 - 版本不受支持]”)表明使用了错误的 LDAP 协议(protocol)版本。我试图明确使用协议(protocol)版本 2,因为 OpenLDAP 版本 1.2.7-30 仅支持 LDAP v2(企业环境 - 服务器版本不可协商)。为此,我检查了您的源代码,添加了行“env.put("java.naming.ldap.version", "2");"到 se.devoteam.nexus.ldap.NexusLdapContextFactory:52。什么都没有改变。

在测试期间,我在浏览 Sun 源代码时意识到,javax.naming.ldap.InitialLdapContext.InitialLdapContext() 方法所做的第一件事就是将 ldap 协议(protocol)版本设置为“3”(javax.naming.ldap. InitialLdapContext:131)。尽管 Java6 文档解释了我使用的属性 (java.sun[dot]com/javase/6/docs/technotes/guides/jndi/jndi-ldap-gl.html#version) 并且 JNDI 教程将此作为解决协议(protocol)版本冲突的正确方法 (java.sun[dot]com/products/jndi/tutorial/ldap/misc/version.html) 我想知道:有没有办法在使用 JNDI 时显式使用 LDAP 协议(protocol)版本 2作为 LDAP 服务提供商?

接下来,我尝试使用一个相当新版本的 OpenLDAP 服务器 (openldap2-2.3) 作为 LDAP 协议(protocol)版本 3 请求的代理,这会将它们委托(delegate)给旧服务器。同样的问题,同样的异常。

附加信息

环境:部署在 Tomcat 6.0.16 上的 Nexus Webapp联系版本:1.3.6ldap-realm 版本:0.4JRE版本:JDK 1.6.0_14-b08平台:虚拟环境LDAP 目录品牌:OpenLDAP 1.2.7 和 2.2.3

nexus.log 的相关部分:

2009-10-23 15:06:37 DEBUG [ajp-8009-3     ] - o.s.j.r.PlexusSecur~          - Realm: 'org.sonatype.jsecurity.realms.XmlAuthenticatingRealm', caused: User 'testuser' cannot be retrieved.
org.jsecurity.authc.AccountException: User 'testuser' cannot be retrieved.
at org.sonatype.jsecurity.realms.XmlAuthenticatingRealm.doGetAuthenticationInfo(XmlAuthenticatingRealm.java:68)
at org.jsecurity.realm.AuthenticatingRealm.getAuthenticationInfo(AuthenticatingRealm.java:168)
at org.sonatype.jsecurity.web.WebPlexusSecurity.getAuthenticationInfo(WebPlexusSecurity.java:185)
at org.jsecurity.authc.pam.ModularRealmAuthenticator.doSingleRealmAuthentication(ModularRealmAuthenticator.java:186)
at org.jsecurity.authc.pam.ModularRealmAuthenticator.doAuthenticate(ModularRealmAuthenticator.java:276)
at org.jsecurity.authc.AbstractAuthenticator.authenticate(AbstractAuthenticator.java:141)
at org.jsecurity.mgt.AuthenticatingSecurityManager.authenticate(AuthenticatingSecurityManager.java:171)
at org.jsecurity.mgt.DefaultSecurityManager.login(DefaultSecurityManager.java:312)
at org.jsecurity.subject.DelegatingSubject.login(DelegatingSubject.java:237)
at org.jsecurity.web.filter.authc.AuthenticatingFilter.executeLogin(AuthenticatingFilter.java:49)
at org.sonatype.nexus.security.filter.authc.NexusHttpAuthenticationFilter.onAccessDenied(NexusHttpAuthenticationFilter.java:121)
at org.jsecurity.web.filter.AccessControlFilter.onPreHandle(AccessControlFilter.java:145)
at org.jsecurity.web.filter.PathMatchingFilter.preHandle(PathMatchingFilter.java:175)
at org.jsecurity.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:129)
at org.jsecurity.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:180)
at org.jsecurity.web.servlet.FilterChainWrapper.doFilter(FilterChainWrapper.java:57)
at org.jsecurity.web.servlet.JSecurityFilter.doFilterInternal(JSecurityFilter.java:382)
at org.jsecurity.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:180)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.ajp.AjpAprProcessor.process(AjpAprProcessor.java:419)
at org.apache.coyote.ajp.AjpAprProtocol$AjpConnectionHandler.process(AjpAprProtocol.java:378)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1509)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.sonatype.jsecurity.realms.tools.NoSuchUserException: User with id='testuser' not found!
at org.sonatype.jsecurity.realms.tools.DefaultConfigurationManager.readUser(DefaultConfigurationManager.java:410)
at org.sonatype.jsecurity.realms.tools.ResourceMergingConfigurationManager.readUser(ResourceMergingConfigurationManager.java:278)
at org.sonatype.jsecurity.realms.XmlAuthenticatingRealm.doGetAuthenticationInfo(XmlAuthenticatingRealm.java:64)
... 29 more
2009-10-23 15:06:37 DEBUG [ajp-8009-3 ] - s.d.n.l.LdapAuthent~ - Authenticating user 'testuser' through LDAP
2009-10-23 15:06:37 DEBUG [ajp-8009-3 ] - s.d.n.l.LdapAuthent~ - LDAP user search filter: (&(objectClass=account)(uid={0}))
2009-10-23 15:06:37 DEBUG [ajp-8009-3 ] - s.d.n.l.NexusLdapCo~ - LDAP security principal not set
2009-10-23 15:06:37 DEBUG [ajp-8009-3 ] - s.d.n.l.NexusLdapCo~ - LDAP security credentials not set
2009-10-23 15:06:37 DEBUG [ajp-8009-3 ] - s.d.n.l.NexusLdapCo~ - LDAP provider url(s): ldap://ldap:389
2009-10-23 15:06:37 DEBUG [ajp-8009-3 ] - s.d.n.l.NexusLdapCo~ - LDAP initial context factory: com.sun.jndi.ldap.LdapCtxFactory
2009-10-23 15:06:37 DEBUG [ajp-8009-3 ] - s.d.n.l.NexusLdapCo~ - LDAP security protocol: null
2009-10-23 15:06:37 DEBUG [ajp-8009-3 ] - s.d.n.l.NexusLdapCo~ - LDAP security authentication: null
2009-10-23 15:06:37 DEBUG [ajp-8009-3 ] - s.d.n.l.NexusLdapCo~ - LDAP search scope: subtree
2009-10-23 15:06:37 DEBUG [ajp-8009-3 ] - s.d.n.l.LdapAuthent~ - User object found
2009-10-23 15:06:37 DEBUG [ajp-8009-3 ] - s.d.n.l.LdapAuthent~ - LDAP authentication principal: uid=testuser, dc=corporation,dc=de
2009-10-23 15:06:37 DEBUG [ajp-8009-3 ] - s.d.n.l.NexusLdapCo~ - LDAP provider url(s): ldap://ldap:389
2009-10-23 15:06:37 DEBUG [ajp-8009-3 ] - s.d.n.l.NexusLdapCo~ - LDAP initial context factory: com.sun.jndi.ldap.LdapCtxFactory
2009-10-23 15:06:37 DEBUG [ajp-8009-3 ] - s.d.n.l.NexusLdapCo~ - LDAP security protocol: null
2009-10-23 15:06:37 DEBUG [ajp-8009-3 ] - s.d.n.l.NexusLdapCo~ - LDAP security authentication: null
2009-10-23 15:06:37 ERROR [ajp-8009-3 ] - o.j.r.l.AbstractLda~ - LDAP naming error while attempting to authenticate user.
javax.naming.CommunicationException: [LDAP: error code 2 - version not supported]
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3089)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2987)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2789)
at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2703)
at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:293)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:175)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:193)
at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:136)
at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:66)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.ldap.InitialLdapContext.<init>(InitialLdapContext.java:134)
at se.devoteam.nexus.ldap.NexusLdapContextFactory.getLdapContext(NexusLdapContextFactory.java:63)
at se.devoteam.nexus.ldap.LdapAuthenticatingRealm.queryForAuthenticationInfo(LdapAuthenticatingRealm.java:139)
at org.jsecurity.realm.ldap.AbstractLdapRealm.doGetAuthenticationInfo(AbstractLdapRealm.java:186)
at org.jsecurity.realm.AuthenticatingRealm.getAuthenticationInfo(AuthenticatingRealm.java:168)
at org.sonatype.jsecurity.web.WebPlexusSecurity.getAuthenticationInfo(WebPlexusSecurity.java:185)
at org.jsecurity.authc.pam.ModularRealmAuthenticator.doSingleRealmAuthentication(ModularRealmAuthenticator.java:186)
at org.jsecurity.authc.pam.ModularRealmAuthenticator.doAuthenticate(ModularRealmAuthenticator.java:276)
at org.jsecurity.authc.AbstractAuthenticator.authenticate(AbstractAuthenticator.java:141)
at org.jsecurity.mgt.AuthenticatingSecurityManager.authenticate(AuthenticatingSecurityManager.java:171)
at org.jsecurity.mgt.DefaultSecurityManager.login(DefaultSecurityManager.java:312)
at org.jsecurity.subject.DelegatingSubject.login(DelegatingSubject.java:237)
at org.jsecurity.web.filter.authc.AuthenticatingFilter.executeLogin(AuthenticatingFilter.java:49)
at org.sonatype.nexus.security.filter.authc.NexusHttpAuthenticationFilter.onAccessDenied(NexusHttpAuthenticationFilter.java:121)
at org.jsecurity.web.filter.AccessControlFilter.onPreHandle(AccessControlFilter.java:145)
at org.jsecurity.web.filter.PathMatchingFilter.preHandle(PathMatchingFilter.java:175)
at org.jsecurity.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:129)
at org.jsecurity.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:180)
at org.jsecurity.web.servlet.FilterChainWrapper.doFilter(FilterChainWrapper.java:57)
at org.jsecurity.web.servlet.JSecurityFilter.doFilterInternal(JSecurityFilter.java:382)
at org.jsecurity.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:180)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.ajp.AjpAprProcessor.process(AjpAprProcessor.java:419)
at org.apache.coyote.ajp.AjpAprProtocol$AjpConnectionHandler.process(AjpAprProtocol.java:378)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1509)
at java.lang.Thread.run(Thread.java:619)
2009-10-23 15:06:37 INFO [ajp-8009-3 ] - o.s.n.s.f.a.NexusSe~ - Unable to authenticate user [testuser] from address/host [172.31.2.155/172.31.2.155]
2009-10-23 15:06:37 DEBUG [ajp-8009-3 ] - o.s.n.e.Authenticat~:default - Notifying 1 EventListener about event org.sonatype.nexus.auth.NexusAuthenticationEvent fired (org.sonatype.nexus.auth.NexusAuthenticationEvent@d637d)

最佳答案

嗯...我不是 LDAP 专家,但根据 Bug ID: 4908306 LDAP Provider version negotiation fails with OpenLDAP server (LDAP v2) :

InitialLdapContext is used for LDAP v3 only. It adds methods to DirContext that make sense only for v3. To use DirContext methods, use InitialDirContext. InitialDirContext will do the appropriate v2/v3 negotiation. The change was made in 1.4.1 to tighten up the implementation to match the spec and also to avoid sending extraneous BINDs for v3.

实际上,我对上面的评论和InitialLdapContext的理解javadoc 是:

This class is the starting context for performing LDAPv3-style extended operations and controls.

InitialLdapContext 类不能用于 LDAP-v2,它显式地将 java.naming.ldap.version 环境属性设置为 "3" 在其源代码中。对于 LDAP-v2,您必须使用 InitialDirContext

如果更改服务器不是一个选项,我想您必须修补 http://code.google.com/p/nexus-ldap/

关于java - Nexus 和 LDAP - 针对 OpenLDAP 服务器验证用户时的 JNDI 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1624137/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com