如何通过 LDAP SSL 启用连接池?

发布于 2024-09-25 03:46:55 字数 1287 浏览 6 评论 0原文

好的,我将我的应用程序从非 SSL 连接转移到 SSL 连接到我的 LDAP 服务器。当以非 SSL 方式运行应用程序时,连接池工作正常。但是当我切换到 SSL 连接池时就不再工作了。

在研究此处时,我意识到我从未设置过“ com.sun.jndi.ldap.connect.pool.protocol”属性设置为“plain ssl”,因为默认情况下它设置为 plain。我以为这就是问题所在。

当我实施更改以包含“plain ssl”时,它没有解决问题,并且连接池仍然没有被使用。

我还缺少其他一些设置吗?

相关代码:

    Hashtable LDAPEnvironment = new Hashtable();
    LDAPEnvironment.put(Context.SECURITY_AUTHENTICATION, SECURITY_AUTHENTICATION);
    LDAPEnvironment.put(Context.SECURITY_PRINCIPAL, SECURITY_PRINCIPAL);
    LDAPEnvironment.put(Context.SECURITY_CREDENTIALS, SECURITY_CREDENTIALS);
    LDAPEnvironment.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
    LDAPEnvironment.put(Context.PROVIDER_URL, PROVIDER_URL );
    LDAPEnvironment.put(Context.SECURITY_AUTHENTICATION, "simple");
    LDAPEnvironment.put("java.naming.ldap.version", versionOfLDAP );

    if (ldapProtocol != null && ldapProtocol.equalsIgnoreCase("SSL")){
        LDAPEnvironment.put(Context.SECURITY_PROTOCOL,"ssl");
        LDAPEnvironment.put("com.sun.jndi.ldap.connect.pool.protocol","plain ssl");
    }

    LDAPEnvironment.put("com.sun.jndi.ldap.connect.pool", "true");

Okay, so I'm moving my application over from non-SSL to SSL connections to my LDAP server. When running the application in non-SSL, connection pooling is working fine. However when I switch to SSL connection pools no longer work.

While researching here I realized that I never set the "com.sun.jndi.ldap.connect.pool.protocol" property to "plain ssl" since defaultly it is set to plain. I thought this was the problem.

When I implemented the change to include "plain ssl", it did not fix the problem and connection pools were still not being used.

Is there some other setting that I am missing?

Relevant code:

    Hashtable LDAPEnvironment = new Hashtable();
    LDAPEnvironment.put(Context.SECURITY_AUTHENTICATION, SECURITY_AUTHENTICATION);
    LDAPEnvironment.put(Context.SECURITY_PRINCIPAL, SECURITY_PRINCIPAL);
    LDAPEnvironment.put(Context.SECURITY_CREDENTIALS, SECURITY_CREDENTIALS);
    LDAPEnvironment.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
    LDAPEnvironment.put(Context.PROVIDER_URL, PROVIDER_URL );
    LDAPEnvironment.put(Context.SECURITY_AUTHENTICATION, "simple");
    LDAPEnvironment.put("java.naming.ldap.version", versionOfLDAP );

    if (ldapProtocol != null && ldapProtocol.equalsIgnoreCase("SSL")){
        LDAPEnvironment.put(Context.SECURITY_PROTOCOL,"ssl");
        LDAPEnvironment.put("com.sun.jndi.ldap.connect.pool.protocol","plain ssl");
    }

    LDAPEnvironment.put("com.sun.jndi.ldap.connect.pool", "true");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遮了一弯 2024-10-02 03:46:55

我已经找到问题了。该文档特别指出,这些属性是系统属性不是环境属性。我将它们设置为环境属性。 :-)

I have found the problem. The documentation specifically states that the those properties are system properties and not environment properties. I was setting these as environment properties. :-)

护你周全 2024-10-02 03:46:55

如果您向下滚动一点,在您提供的链接处(滚动到“连接如何池化”),您将看到池化工作原理的说明。

当您请求池连接时,仅当所有指定属性都相同时您才会获得一个。这是一长串属性...

我的情况是:

  • 连接控制
  • 主机名、“java.naming.provider.url”属性中指定的端口号、引用或提供给初始上下文
  • java.naming 的 URL .security.protocol 属性
  • java.naming.ldap.version 属性
  • java.naming.security.principal 属性
  • java.naming.security.credentials 属性

如果您在从连接池请求连接时始终使用相同的常量,我认为您应该得到相同的池连接。也就是说,如果您正确设置 com.sun.jndi.ldap.connect.pool.* 属性 - 但我在您提供的代码中没有看到这一点。

如果您确实将 com.sun.jndi.ldap.connect.pool.* 属性设置为合理的值,请尝试将 com.sun.jndi.ldap.connect.pool.debug 设置为fine。这将帮助您进行调试。

另一种选择是使用支持连接池的框架或提供程序。请注意,Java 提供给您的池是相当有限的。我过去使用过Spring-Ldap,它有很好的支持。

希望这有帮助。

If you scroll down a little, at the link you provided (scroll to "How Connections are Pooled"), you'll see the explanation to how the pooling works.

When you request a pooled connection, you will get one only if ALL the specified properties are identical. And that's a long list of properties...

I your case this is:

  • connection controls
  • host name, port number as specified in the "java.naming.provider.url" property, referral, or URL supplied to the initial context
  • java.naming.security.protocol property
  • java.naming.ldap.version property
  • java.naming.security.principal property
  • java.naming.security.credentials property

If you always use the same constants when request a connection from the connection pool, I think you should get the same pooled connection. That is, if you set the com.sun.jndi.ldap.connect.pool.* properties properly - but I didn't see that in the code you provided.

If you did set the com.sun.jndi.ldap.connect.pool.* properties to sensible values, try setting com.sun.jndi.ldap.connect.pool.debug to fine. This will help you debug.

Another option is to use a framework, or a provider that supports connection pooling. Note that the pooling provided to you by Java is rather limited. I used Spring-Ldap in the past, and it has very good support.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文