Detect user logged on a computer using Java

后端 未结 4 1877
感情败类
感情败类 2020-12-17 01:03

I want to develop an Java application that can detect the user logged on a Window Domain. These credentials are going to be used to logging on the Java application.

相关标签:
4条回答
  • 2020-12-17 01:43
    System.getProperty("user.name") 
    
    0 讨论(0)
  • 2020-12-17 01:43

    I noticed that the topicstarter asks afterwards in comments if s/he can use it in a Java webapp which was answered with "no" everytime. This is true if you run the particular code at the server side, but not if you run it at the client side in flavor of an applet or jnlp which is embedded in the requested jsp/html page. It however has to send the needed information to the server side afterwards.

    0 讨论(0)
  • 2020-12-17 02:01

    Note: System.getProperty("user.name") will only work if the user launches the application. If the program is run by System or an application like LANDesk, then the user will come out as "SYSTEM" (under domain "NT AUTHORITY").

    In which case, the second solution using NTSystem will return the correct results.

    0 讨论(0)
  • 2020-12-17 02:05

    If you need to domain name, you can use this :

      com.sun.security.auth.module.NTSystem NTSystem = new
              com.sun.security.auth.module.NTSystem();
      System.out.println(NTSystem.getName());
      System.out.println(NTSystem.getDomain());
    

    Bye.

    0 讨论(0)
提交回复
热议问题