I am trying to implement the windows authentication using a third party library 'Waffle'. The challenge I am facing is how to retrieve the mail id of the user if we know the User ID and the domain. For example I am able to get the User Id as XYZ\phembr and I want to get the mail address (phembrom@xyz.com in this case) from SMTP server. Following is the jsp code I am using and the output I am getting.
<%@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>
The output I am getting is: (Note that I should have got phembrom@xyz.com and not 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.