0

Hi I am working on a module in Java web application where I have to get username of the active windows user on the remote pc, I had used a couple of existing method such as:

  1. System.getenv().get("USERNAME");

  2. com.sun.security.auth.module.NTSystem nsys = new com.sun.security.auth.module.NTSystem(); nsys.getName();

  3. request.getUserPrincipal();

  4. System.getProperty("user.name")

but all giving the username of the server.

Blasanka
  • 21,001
  • 12
  • 102
  • 104
Amaan
  • 1
  • Is there any solution for my above query – Amaan Jun 03 '17 at 18:32
  • Yes, but they all require active directory integration (or some other form of identity federation, etc). – Elliott Frisch Jun 03 '17 at 18:33
  • 1
    *"all giving the username of the server"* Of course, because you're running that code on the server. Your app is a webapp, i.e. Java code on server, JavaScript code in Web Browser on client, and you want client user, so why do you think server-side Java code is the solution? The only code that can find the client user, is code on the client machine, i.e. JavaScript code in the browser. You could use authorization features to ask the browser to auto-login, like Elliott said, but that's way beyond just getting to know the user name. – Andreas Jun 03 '17 at 18:51
  • 1
    See [JavaScript - How to get the name of the current user](https://stackoverflow.com/q/9518092/5221149) – Andreas Jun 03 '17 at 18:55
  • Does the user have to authenticate so we can get his/her username or it can be done directly – Amaan Jun 03 '17 at 18:56
  • using active directory – Amaan Jun 03 '17 at 18:57
  • Hi Elliott is it possible to get windows username using active directory without requiring the user to authenticate in java web application – Amaan Jun 03 '17 at 19:18
  • Hi Andreas Javascript does not work on all browsers and it requires the permission of the user to get the username – Amaan Jun 03 '17 at 19:20

0 Answers0