[英]ldap connection pool in web application
我需要在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調用上使用-D參數將參數設置為JVM系統參數。
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”對象,而不是系統屬性對象。
編輯並且不要調試為真實。 設置它具有關閉合並的奇怪效果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.