I write a web application I have to do signin in that using the windows username.. I tried to get username using system.get property() but its giving the username of server windows name only.but I want to the username of client system..can any one help me?
-
2you wont be getting access to the client machine from the server – Dileep May 08 '14 at 07:30
-
It's not a duplicate. He want the user on the client machine, which is impossible AFAIK – SomethingSomething May 08 '14 at 07:33
-
You need to use a single sign-on service like CAS to authenticate your users against a LDAP. Only then, you may *access* to the *window user name* (which is, in fact, retrieved by the Active Directory, LDAP implementation on Windows). – Luiggi Mendoza May 08 '14 at 07:36
-
Hi dileep client machine means what I am telling some other system. – Mohankumars May 08 '14 at 08:07
-
Short answer: use *wmic*. Long answer check my answer at https://stackoverflow.com/a/58377194/3584693 – Deepak Oct 14 '19 at 12:50
3 Answers
If I understood you correctly you want to sign in to the web application using the Windows credentials. If so - the problem is that the server machine knows nothing about the client. It can provide you the user info only after successful login (see Get windows username using JAVA or JSP).
You could point your system to some user store (e.g. LDAP) that will be used by both Windows system and your app. In this situation you will be able to sign in to the app using Windows credentials.
The Browser is an application to generate the view based on an HTML code. It wont give access to the client machine.
You can use request.getRemoteUser()
to get the user name, that too is possible only if its allowed in the client machine.
If your client is running on a windows machine you can get the user name using this
var wshshell=new ActiveXObject("wscript.shell");
var username=wshshell.ExpandEnvironmentStrings("%username%");
This is a solution for getting the user name, but i will never recommend this, it surely is a bad practice.

- 5,362
- 3
- 22
- 38
-
1
-
@LuiggiMendoza it would be better if you explain why..?? I can also learn the mistake.. – Dileep May 08 '14 at 08:44
-
@LuiggiMendoza You have added the comment and i have updated my answer, now i think i don't deserve that down vote...!! – Dileep May 08 '14 at 09:06
-
IMO this is not a good answer, that's why I'm keeping the downvote. – Luiggi Mendoza May 08 '14 at 19:10
Is the entire Java application running on the server? How would your application even know about a specific client machine? And how would it deal with concurrently logged in users? And how would it deal with a primitive client machine which does not have a notion of a user name?
You can instead run a Java applet which is invoked on the client's machine. You could the send this information to the server to process. However, your users would most likely not like that and not grant the required privileges.
Alternatively, you could try to use JavaScript to read the user name, in case that you are communicating via a webpage. I want to stress the word try in this context since there is not universally functional approach and most users will most likely not allow you to read this property either.
In a nutshell: Users do not normally want to share this information with you and therefore you cannot access it. If you could, you would have found a security hole which would most likely get fixed. Rather, ask your application's users to enter a name to use for whatever reason you would require it. Or, if this is an option, organize for example your Windows credentials in a service that can be accessed by a standardized API.

- 1
- 1

- 42,759
- 13
- 108
- 192