我已經使用JNDIRealm在tomcat中設置了spnego庫。 遵循以下指南:https://dzone.com/articles/do-not-publish-configuring-tomcat-single-sign-on-w 我想知道我可以從另一個java類中的LDAP中獲得用戶組,我正在使用它在我的數據庫中創建一個用戶。我想獲得所有用戶的詳細信息,如電子郵件,電話等。以及用戶所屬的所有組。SPNEGO獲取用戶詳細信息
1
A
回答
0
請參閱this list以獲取您可以從LDAP中檢索的所有屬性。
例如,假設您需要用戶的名稱,組,職位,電話號碼和電子郵件。 (對於你的問題,我將使用與你的鏈接相同的「虛擬值」)。
的第一步是連接到LDAP中的Java類,對於我寧願使用一個單獨的功能:
public static Hashtable<String, String> getContextEnv() {
Hashtable<String, String> contextEnv = new Hashtable<String, String>();
contextEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
contextEnv.put(Context.PROVIDER_URL, "ldap://dc.mydomain.com:3268");
contextEnv.put(Context.SECURITY_AUTHENTICATION, "simple");
contextEnv.put(Context.SECURITY_PRINCIPAL, "CN=TECHNICAL_USER,DC=mydomain,DC=com");
contextEnv.put(Context.SECURITY_CREDENTIALS, "TECHNICAL_USER_PASSWORD");
contextEnv.put("java.naming.referral", "follow");
contextEnv.put("java.naming.ldap.derefAliases", "never");
contextEnv.put("com.sun.jndi.ldap.connect.pool", "true");
contextEnv.put("com.sun.jndi.ldap.connect.timeout", "60000");
return contextEnv;
}
凡TECHNICAL_USER是您使用與的ktpass創建密鑰表的一個命令。
下一步是調用該函數,並創建一個SearchControls對象。這是,你會把你想(見上面的鏈接瞭解所有的可能)的屬性和一些PARAMATERS(超時爲例):
Hashtable<String, String> contextEnv = getContextEnv();
DirContext ctx = new InitialDirContext(contextEnv);
// UserID - Last Name - First Name - Group - Job Title - Phone Number - Email address
String[] attrIDs = { "sAMAccountName", "sn", "givenName", "memberOf", "title", "telephoneNumber", "mail"};
SearchControls searchControls = new SearchControls();
searchControls.setReturningAttributes(attrIDs);
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
searchControls.setTimeLimit(6000);
最後一步,你得到的信息你其中currentUser是用戶ID貴公司使用,以確定員工當前用戶:
NamingEnumeration<SearchResult> searchResults = ctx.search("DC=mydomain,DC=com", "(sAMAccountName=" + currentUser + ")", searchControls);
if (searchResults.hasMore()) {
SearchResult currentSearchResult = searchResults.next();
Attributes searchResultAttributes = currentSearchResult.getAttributes();
String userID = searchResultAttributes.get("sAMAccountName");
String lastName = searchResultAttributes.get("sn");
String firstName = searchResultAttributes.get("givenName");
String group = searchResultAttributes.get("memberOf");
String jobTitle = searchResultAttributes.get("title");
String phoneNumber = searchResultAttributes.get("telephoneNumber");
String email = searchResultAttributes.get("mail");
searchResults.close();
}
ctx.close();
相關問題
- 1. Pinterest api - 獲取用戶詳細信息
- 2. Get-ADGroupMember獲取用戶詳細信息?
- 3. ActiveDirectoryLdapAuthenticationProvider:獲取用戶詳細信息
- 4. 從log.nsf獲取用戶詳細信息
- 5. Google Api - 獲取用戶詳細信息
- 6. 從MGTwitterEngine獲取用戶詳細信息
- 7. Instagram獲取用戶詳細信息
- 8. Facebook API:獲取用戶詳細信息
- 9. 從facebook獲取用戶詳細信息
- 10. 獲取Facebook帳戶詳細信息
- 11. 獲取Facebook詳細信息
- 12. 使用cURL獲取用戶facebook用戶詳細信息
- 13. 在用戶登錄Facebook後獲取用戶詳細信息
- 14. 從用戶名(Sqlite,PHP)獲取用戶詳細信息
- 15. Crystal Reports詳細信息詳細信息
- 16. Android主詳細信息詳細信息
- 17. Ldap如何獲取用戶詳細信息。像電子郵件和用戶名其他詳細信息
- 18. 用戶詳細信息表中的用戶認證詳細信息或單獨?
- 19. 客戶詳細信息
- 20. 無法使用Cakephp獲取Facebook用戶詳細信息
- 21. 使用PFFVideosUtilsV4在Swift中獲取Facebook用戶詳細信息Cocoapods
- 22. 如何使用BadgeVille API獲取用戶詳細信息?
- 23. 使用Sitecore SocialConnected模塊獲取用戶詳細信息
- 24. 如何使用Facebook連接獲取用戶詳細信息
- 25. 獲取所有的facebook應用程序用戶詳細信息
- 26. 在Josso中,如何使用「josso_assertion_id」獲取用戶詳細信息
- 27. 用ios6在xcode 4.5中從facebook獲取用戶詳細信息
- 28. 如何獲取使用restfb的用戶的詳細信息?
- 29. 獲取表格詳細信息
- 30. 從google地方獲取詳細信息
只是要清楚,你沒有管理Java類中連接到LDAP?如果是的話,你可以添加你的代碼片段嗎? – fab
我只是按照鏈接,它確實用戶身份,並給我用戶名。然而,我現在想編寫代碼來獲取更多用戶的細節。要獲取用戶名,我使用request.getRemoteUser()。 – michael