0

I'm writing a web app where there are some JDBC operations to be done based on the system user name. Currently I'm using the below code to get the details.

String userID = System.getProperty("user.name");

    public String getUserIDDetails() throws Exception {
        System.out.println(userID);
        return userID;
    }

Also I've tried

String systemUserName = new com.sun.security.auth.module.NTSystem().getName();

But here the problem is, when I deploy this on tomcat and tell my collegue to run it using, http://mySystemIPAddress:portNumber/ProjectName, in the console, it prints my system name instead of the system where this url is accessed from (currently my colleague's). None of the above two methods worked.

Please let me know how can I fix this and get the correct system name.

Thanks

user3872094
  • 3,269
  • 8
  • 33
  • 71

1 Answers1

0

The issue you're running into is that the code you're showing is running on a workstation as a user (you in this case). Then a user in a browser is running on a different workstation. In theory, you'd need to use some JavaScript on the browser to determine who is logged into the browser workstation. However, a quick search seems to indicate that this is somewhere between difficult and impossible.

Normally for web based applications you'd want your user to log into your webapp. Then you could, for example, use the Windows domain as a way to verify that they username/password was correct. There are many other ways of doing this but your current approach needs to change I'm afraid.

stdunbar
  • 16,263
  • 11
  • 31
  • 53