使用jsp进行Windows身份验证和电子邮件地址检索

时间:2013-03-14 09:49:23

标签: windows jsp email authentication waffle

我正在尝试使用第三方库&Waffle'来实现Windows身份验证。我面临的挑战是如果我们知道用户ID和域,如何检索用户的邮件ID。例如,我能够将用户ID作为XYZ \ phembr获取,并且我想从SMTP服务器获取邮件地址(在本例中为phembrom@xyz.com)。以下是我正在使用的jsp代码和我得到的输出。

<%@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>

我得到的输出是:(注意我应该有phembrom@xyz.com而不是phembr@xyz.com)

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 phembr@xyz.com.

1 个答案:

答案 0 :(得分:1)

常见问题解答:https://github.com/dblock/waffle/blob/master/Docs/faq/AdditionalActiveDirectoryInfo.md

您无法直接使用Waffle执行此操作。在Windows上,可以通过使用ADSI查询Active Directory来完成此操作。这涉及通过从登录获得的SID定位用户的记录并获取任何其他信息。

两个实现: