我将在服务器中托管我的应用程序。我只想获取登录到我的应用程序的用户的 NT ID。如果有人有答案,请分享?
system.getremoteUser()
并将system.getProperty
返回托管机器名称。
If you are specific about NT ID fetching in Java
, this might work
com.sun.security.auth.module.NTSystem NTSystem = new
com.sun.security.auth.module.NTSystem();
System.out.println(NTSystem.getName());
System.out.println(NTSystem.getDomain());
System.out.println(NTSystem.getUserSID());
But for a webapplication context where you have NTLM authentication, you should be having NTLM (Windows) users as your application users as-well (this is a general case).
It would be better to query NTLMRealm (in Tomcat) or store user identity (SID etc) in a context (this can be session based or specific custom server-side implementation) while authenticating user via NTLM. Now use this context to retrieve NTLM properties of users (SID, GroupID etc) logged-in.