2013-03-14 126 views
1

我正在嘗試使用第三方庫'Waffle'實現Windows身份驗證。我面臨的挑戰是如果我們知道用戶ID和域,如何檢索用戶的郵件ID。例如,我可以將用戶ID作爲XYZ \ phembr,並且我想從SMTP服務器獲取郵件地址(在這種情況下爲[email protected])。以下是我正在使用的jsp代碼和我得到的輸出。使用jsp進行Windows身份驗證和電子郵件地址檢索

<%@page import="java.security.Principal" %> 

<%@page import="waffle.windows.auth.WindowsAccount" %> 

<%@page import="waffle.servlet.WindowsPrincipal" %> 

<%@page import="com.sun.jna.platform.win32.Secur32" %> 

<%@page import="com.sun.jna.platform.win32.Secur32Util" %> 

<% 

if (request.getParameter("logoff") != null) { 

session.invalidate(); 

response.sendRedirect("index.jsp"); 

return; 

} 

%> 

<html> 

<head> 

<title>Protected Page for Examples</title> 

</head> 

<body bgcolor="white"> 

Welcome <b><%= Secur32Util.getUserNameEx(Secur32.EXTENDED_NAME_FORMAT.NameDisplay) %></b> <br> 

You are logged in as remote user <b><%= request.getRemoteUser() %></b> in session <b><%= session.getId() %></b>.<br> 

You are impersonating user <b><%= Secur32Util.getUserNameEx(Secur32.EXTENDED_NAME_FORMAT.NameSamCompatible) %> </b>. 

<br><br> 

<% 

if (request.getUserPrincipal() != null) { 

%> 

Your user principal name is <b><%= request.getUserPrincipal().getName() %></b>.<br> 



Your email is <b><%= Secur32Util.getUserNameEx(Secur32.EXTENDED_NAME_FORMAT.NameUserPrincipal) %></b>. 



<br><br> 

<% 

} else { 

%> 

No user principal could be identified. 

<br><br> 

<% 

} 

%> 

</body> 

我得到的輸出是:(請注意,我應該得到[email protected]而不是[email protected]

Welcome Prashant Kumar Hembrom 

You are logged in as remote user XYZ\phembr in session DB5376CCEF5FA13F6059AC679F0B95BE. 

You are impersonating user XYZ\phembr . 



Your user principal name is XYZ\phembr. 

Your email is [email protected] 

回答

1

這是在回答常見問題:https://github.com/dblock/waffle/blob/master/Docs/faq/AdditionalActiveDirectoryInfo.md

你不能直接用華夫餅做這個。在Windows上,這可以通過使用ADSI查詢Active Directory來完成。這涉及通過從登錄中獲得的SID查找用戶的記錄並獲取任何附加信息。

兩個實現:

相關問題