【发布时间】:2014-08-05 03:29:26
【问题描述】:
我需要在 Web 应用程序中使用 ldap 连接池。为了验证管理员身份,我使用以下代码:
Properties props = new Properties();
System.setProperty("com.sun.jndi.ldap.connect.pool", "true");
System.setProperty("com.sun.jndi.ldap.connect.pool.maxsize", "1");
System.setProperty("com.sun.jndi.ldap.connect.pool.debug", "fine");
props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
props.put(Context.PROVIDER_URL, "ldap://localhost:10389/o=myldap");
props.put(Context.SECURITY_PRINCIPAL, "uid=admin,ou=system");//adminuser
props.put(Context.SECURITY_CREDENTIALS, "xxxxx");
InitialDirContext context = new InitialDirContext(props);
要查找和验证另一个用户,我需要更改 SECURITY_PRINCIPAL 和 SECURITY_CREDENTIALS,然后再次创建一个新上下文。当我这样做是 POJO 时,它使用连接池,但是当我在多用户 Web 应用程序中使用它时(我用两个线程尝试过),它不使用连接池。
对此可以使用什么解决方法?
【问题讨论】:
标签: java ldap jndi connection-pooling