简体   繁体   English

如何在 Java 客户端机器上获取当前登录用户的用户名?

[英]How to get username of currently logged user on client machine in Java?

When the user (client) tries to get into the application by typing the URL, i need to get that machine's windows logged in username.当用户(客户端)尝试通过输入 URL 进入应用程序时,我需要让该机器的 Windows 登录用户名。

I have tried with System.getProperty("user.name") but when I access the application from some other machine (client) then this still shows username of logged in user on server.我已经尝试过System.getProperty("user.name")但是当我从其他机器(客户端)访问应用程序时,它仍然显示服务器上登录用户的用户名。 I want this is to be changed according to the client machine username every time.我希望每次都根据客户端机器用户名进行更改。

And also I have tried with some JavaScript code, it only works on IE but we are using Firefox.我也尝试过一些 JavaScript 代码,它只适用于 IE,但我们使用的是 Firefox。

Kindly suggest the possible ways to work with all kind of browsers.请建议使用各种浏览器的可能方法。

Application Details:申请详情:

View: Struts视图:支柱
Application Framework: Spring 3.1.1应用框架: Spring 3.1.1
Application Server: jboss-6.1.0.Final应用服务器: jboss-6.1.0.Final
Server OS: CentOS 5服务器操作系统: CentOS 5

For security purposes the amount of data applications running in a browser can access is limited.出于安全目的,在浏览器中运行的应用程序可以访问的数据量是有限的。 As far as I know, the only thing which is allowed access to client related data would be a Signed Applet .据我所知,唯一允许访问客户端相关数据的是Signed Applet

Through java you will not be able to access it since it resides in server.通过java您将无法访问它,因为它驻留在服务器中。 You will have to use javascript to get it done...你将不得不使用 javascript 来完成它......

This might help you..这可能会帮助你..

Get Windows username with JavaScript? 使用 JavaScript 获取 Windows 用户名?

If this is for an intranet application, you can look at using NTLM (older) or Kerberos (newer) authentication (aka integrated windows authentication).如果这是针对 Intranet 应用程序,您可以考虑使用 NTLM(较旧)或 Kerberos(较新)身份验证(又名集成 Windows 身份验证)。

If you're using Spring security, look at the kerberos extension, http://blog.springsource.org/2009/09/28/spring-security-kerberos/ .如果您使用 Spring 安全性,请查看 kerberos 扩展, http://blog.springsource.org/2009/09/28/spring-security-kerberos/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM