How can I trace the users Windows login name from a web application?
I tried with some existing methods in Java, but it's showing server's Windows login name.
userAgent = request.getHeader("User-Agent");
How can I trace the users Windows login name from a web application?
I tried with some existing methods in Java, but it's showing server's Windows login name.
userAgent = request.getHeader("User-Agent");
The short answer for general internet clients is that you can't. The web server does not get any information from the client's web browser to allow it to see the username (doing so would be a security problem).
Javascript running on the user's browser will also be unable to work out the username. It might be possible using a browser extension but then you're a fair way beyond a simple solution and getting well into "Bad Idea" territory.
If you're doing intranet stuff where your users are on the same domain or network you could possibly try having the server do system calls or using local OS tools to find out. Eg:
wmic.exe /node:192.168.33.2 ComputerSystem Get UserName
Note that something like this is only going to work if you have permissions (eg Domain Administrator perhaps) to query other machines. This is not going to work at all for general internet stuff.
Ultimately, this will only be possible if your web server and the client machine are sharing the same authentication mechanism (ie samba, NTLM, Kerberos etc).
You can achieve your requirement by implementing Kerberos or NTML authentication then you can get the Windows username using request.getRemoteUser()
I recommend Kerberos. To add Kerberos authentication check SPNEGO Filter. It on most of the Servlet containers.