I'm developing an application that would be hosted on tomcat server. I'm looking to get the username details with which the user would logon to his windows system for tracking purpose. Is there a way to get the user name details with which the user logged onto the system before accessing the application through a browser?
Asked
Active
Viewed 1,092 times
0
-
3Have you seen [this](http://stackoverflow.com/a/19990060/3861396)? – 2016rshah Jul 09 '15 at 14:11
-
2possible duplicate of [How to get Windows username in Java?](http://stackoverflow.com/questions/19990038/how-to-get-windows-username-in-java) – dhke Jul 09 '15 at 14:12
-
4@2016rshah That is a slightly different case. – biziclop Jul 09 '15 at 14:12
-
2If the user is running the tomcat server under his own account the link from @2016rshah should help, if not you should google for NTLM – Gerald Schneider Jul 09 '15 at 14:12
-
1you may need to use `javascript` for get client information .not sure is it possible get username even throw javascript.but you can get information like `operating system,browser` – Madhawa Priyashantha Jul 09 '15 at 14:13
-
1You're looking for a way for an application on a tomcat server to get the local windows username of someone who connects to your application? Local as in "on their own machine"? – CPerkins Jul 09 '15 at 14:13
-
3In general, no. The server can only see what the browser sends and for obvious reasons browsers don't advertise this information. – biziclop Jul 09 '15 at 14:14
-
Although I would ask the question: if you need to track users by name (and not just give them a persistent but anonymous identity in the form of a tracking cookie), why don't you formally log them in? – biziclop Jul 09 '15 at 14:24
-
CPerkins - By local i meant on their own machine. – Punith Jul 09 '15 at 14:37
-
biziclop - This is an application where the user would be able to edit or delete the information that is available. So for our tracking purpose we would like to capture the windows username instead of formally logging them in. – Punith Jul 09 '15 at 14:39
-
I'm sorry but that's no reason for not logging them in. In fact I'd argue that any application that lets you edit or delete persistent information visible by others should probably be protected by some kind of login mechanism. – biziclop Jul 09 '15 at 14:42
-
possible duplicate of [Get Windows username with JavaScript?](http://stackoverflow.com/questions/2968690/get-windows-username-with-javascript) – LittleBobbyTables - Au Revoir Jul 09 '15 at 19:47
-
biziclop - Thanks. We shall look at having login details stored for the user as it involves edit or deletion of the information. – Punith Jul 10 '15 at 04:59
-
Short answer: use *wmic*. Long answer check my answer at https://stackoverflow.com/a/58377194/3584693 – Deepak Oct 14 '19 at 12:49
1 Answers
2
i doubt there is a java only way to do this. you have to check the username using javascript. here is an example for windows user:
Get Windows username with JavaScript?
Also you probably want to do the same for Linux/Mac users?
Once you got the java script name you could either save it into a cookie and read it with your Java servlet or send an Ajax request to your backend.

Community
- 1
- 1

tagtraeumer
- 1,451
- 11
- 19
-
Would like to get the user name for Windows, Linux and Mac users as well. The JavaScript would require active content to enabled on the client machine? – Punith Jul 09 '15 at 14:41
-
yes, javascript should be enabled on the client machine. for each operating system you might have to use seperate commands, i assume. in my opinion this is not the most elegant solution. i'd rather try to track people using other means, like create an ID using browserinformation, that should be sent each request. there should be lots of reseach content on that. – tagtraeumer Jul 09 '15 at 15:44