AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1052514
Accepted
theimpatientcoder
theimpatientcoder
Asked: 2021-02-06 07:11:07 +0800 CST2021-02-06 07:11:07 +0800 CST 2021-02-06 07:11:07 +0800 CST

尝试使用 JNDI 和 GSSAPI 执行 LDAP 搜索时出现 javax.naming.CommunicationException:连接重置和 AD“事件 ID 1216”

  • 772

我正在尝试分析 Ldap 搜索期间异常/失败的原因。我在 Active Directory 域控制器上使用 JNDI 执行操作。

这是我正在尝试做的事情的背景:

  1. 使用 SASL( Kerberos authentication) 使用 JAAS( KRB5LoginModule) 生成一个LoginContext.
  2. 登录成功后,LoginContext实例具有经过身份验证的主题,其中TGT填充了 kerberos 票证 ()PrivateCredentials
  3. 之后,我使用 GSSAPI 使用上面的 authenticated 生成 LdapContext Subject。
  4. LdapContext生成后,我用它来执行 JNDI 操作(主要使用分页搜索)

  1. 到现在一切都很好,并且 LdapContext 已正确生成
  2. Active Directory 域控制器设置的一些详细信息:
  3. TGT 的生命周期设置为1 hour
  4. 服务票证( )的生命周期TGS设置为 10 分钟(由于某些限制而需要,但实际上是这样的)

现在的场景:

  • 使用LdapContext上面创建的,它开始使用 查询域控制器,pagingcontrol并且事情在一定的时间或一定的搜索量内工作顺利(这样说是为了我不希望你们都误导这实际上可能涉及时间,只需考虑这发生在(大约)定期间隔之后 - 这些间隔可能是时间或搜索

  • 当它在一定间隔后获取下一页时,搜索失败并显示:

       Caused by: javax.naming.CommunicationException: Connection reset
          at com.sun.jndi.ldap.LdapCtx.getSearchReply(LdapCtx.java:1920) ~[?:1.8.0_73]
          at com.sun.jndi.ldap.AbstractLdapNamingEnumeration.getNextBatch(AbstractLdapNamingEnumeration.java:130) ~[?:1.8.0_73]
          at com.sun.jndi.ldap.AbstractLdapNamingEnumeration.hasMoreImpl(AbstractLdapNamingEnumeration.java:217) ~[?:1.8.0_73]
          at com.sun.jndi.ldap.AbstractLdapNamingEnumeration.hasMore(AbstractLdapNamingEnumeration.java:189) ~[?:1.8.0_73]
    
          ... 10 more
    
       Caused by: java.net.SocketException: Connection reset
          at java.net.SocketInputStream.read(SocketInputStream.java:209) ~[?:1.8.0_73]
          at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[?:1.8.0_73]
          at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) ~[?:1.8.0_73]
          at java.io.BufferedInputStream.read1(BufferedInputStream.java:286) ~[?:1.8.0_73]
          at java.io.BufferedInputStream.read(BufferedInputStream.java:345) ~[?:1.8.0_73]
          at com.sun.jndi.ldap.sasl.SaslInputStream.readFully(SaslInputStream.java:166) ~[?:1.8.0_73]
          at com.sun.jndi.ldap.sasl.SaslInputStream.fill(SaslInputStream.java:123) ~[?:1.8.0_73]
          at com.sun.jndi.ldap.sasl.SaslInputStream.read(SaslInputStream.java:90) ~[?:1.8.0_73]
          at com.sun.jndi.ldap.Connection.run(Connection.java:860) ~[?:1.8.0_73]
          at java.lang.Thread.run(Thread.java:745) ~[?:1.8.0_73]
    

同时,我在 Active Directory 域控制器上看到以下事件日志:EventId:2889

 Log Name:      Directory Service
 Source:        Microsoft-Windows-ActiveDirectory_DomainService
 Event ID:      2889
 Task Category: LDAP Interface
 Level:         Information
 Keywords:      Classic
 User:          ANONYMOUS LOGON
 Computer:      myad01.example.lab
 Description:The following client performed a SASL (Negotiate/Kerberos/NTLM/Digest) LDAP bind without
 requesting signing (integrity verification), or performed a simple bind over a clear text (non-
 SSL/TLS-encrypted) LDAP connection. 

 Client IP address: X.X.X.X:56260 
 Identity the client attempted to authenticate as:EXAMPLE\Administrator 
 Binding Type:0

我还看到了一个EventID为1216的日志。详细信息如下:

 Log Name:      Directory Service
 Source:        Microsoft-Windows-ActiveDirectory_DomainService
 Event ID:      1216
 Task Category: LDAP Interface
 Level:         Warning
 Keywords:      Classic
 User:          N/A
 Computer:      myad01.example.lab
 Description:Internal event: An LDAP client connection was closed because of an error. 

 Client IP:X.X.X.X:56244 

 Additional Data 
 Error value: 1236 The network connection was aborted by the local system. 
 Internal ID: c060420

我的理解:每当(在一段时间后)它去获取下一页时ldap connection,服务器(如事件 id 所建议的那样1216)将其无效,因此我得到了CommunicationException. 我的问题是为什么我会在一段时间后而不是立即得到这个?是因为 kerberos 和服务票证的有效期已经结束了吗? 如果是这种情况,那么我应该如何设计来克服分页问题?因为,在收到通信异常后,如果我创建一个新的 LdapContext 并设置分页控件,我会按预期得到以下异常:

  javax.naming.OperationNotSupportedException: [LDAP: error code 12 - 00000057: LdapErr: DSID-0C090B0B, comment: Error processing control, data 0, v3839 ]
     at com.sun.jndi.ldap.LdapCtx.mapErrorCode(Unknown Source) ~[?:1.8.0_201]
     at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source) ~[?:1.8.0_201]
     at com.sun.jndi.ldap.LdapCtx.processReturnCode(Unknown Source) ~[?:1.8.0_201]
     at com.sun.jndi.ldap.LdapCtx.searchAux(Unknown Source) ~[?:1.8.0_201]
     at com.sun.jndi.ldap.LdapCtx.c_search(Unknown Source) ~[?:1.8.0_201]
     at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_search(Unknown Source) ~[?:1.8.0_201]
     at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.search(Unknown Source) ~[?:1.8.0_201]
     at javax.naming.directory.InitialDirContext.search(Unknown Source) ~[?:1.8.0_201]

对我来说,同时支持身份验证的 SASL(kerberos) 和创建 LdapContext 的 GSSAPI 对我来说非常重要。此外,分页很重要,因为数据量很大,而且我们不能对票证的有效性进行任何限制,因为我无法控制客户的环境!

请为我提供有关如何进一步调试此问题的指示,并提出正确的方法或解决方法(对此感到抱歉,但无论如何都需要它)来解决此问题。

java active-directory ldap kerberos gssapi
  • 1 1 个回答
  • 1158 Views

1 个回答

  • Voted
  1. Best Answer
    theimpatientcoder
    2021-02-11T05:54:27+08:002021-02-11T05:54:27+08:00

    我的观察可能会帮助某人分析他们的问题。首先Event ID:1216是在客户端(在我的问题中,我提到了 JNDI,在这种情况下客户端只是 LdapContext/DirContext)关闭其底层时在 Active Directory 上生成Socket。看看这个链接。

    LdapContext只不过是在客户端(例如:JNDI)和 LDAP 服务器(例如:Active Directory 目录服务)之间使用某些连接设置形成的连接。当网络上任意两个实体之间存在连接时,通常由客户端套接字和服务器端套接字的形成来支持。在 LdapContext 的情况下,LdapContext 也有一个底层套接字。

    在GSSAPI用于获取 LdapContext 实例时,底层套接字带有一个超时,该超时等于AD DS 上存在的服务票证生命周期设置的有效性。一旦底层套接字的有效性/超时结束,套接字就会关闭。如果,LdapContext则尝试查询 AD DS,则发生上述Caused by: javax.naming.CommunicationException: Connection reset异常并且通信失败。

    由于 TGT 和 TGS 的生命周期/有效性设置位于 AD DS 上,因此无法使用 GSSAPI 绕过它们。如果有需要使用LdapContext更多时间的要求,那么唯一的出路是增加相应票的有效期。

    • 1

相关问题

  • jvm性能调优技巧/资源?

  • Linux 服务器上的多个*几乎*相同的进程

  • 您认为 Linux 服务器上的 Java 是个问题吗?[关闭]

  • 如何定期复制 SVN 存储库而不会丢失目标标签和分支?

  • GlassFish 更改 Web 服务的端口

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve