1

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?

5
  • 2
    you wont be getting access to the client machine from the server Commented May 8, 2014 at 7:30
  • It's not a duplicate. He want the user on the client machine, which is impossible AFAIK Commented May 8, 2014 at 7: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). Commented May 8, 2014 at 7:36
  • Hi dileep client machine means what I am telling some other system. Commented May 8, 2014 at 8:07
  • Short answer: use wmic. Long answer check my answer at stackoverflow.com/a/58377194/3584693 Commented Oct 14, 2019 at 12:50

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

4 Comments

This solution is unsafe and won't work on all browsers.
@LuiggiMendoza it would be better if you explain why..?? I can also learn the mistake..
@LuiggiMendoza You have added the comment and i have updated my answer, now i think i don't deserve that down vote...!!
IMO this is not a good answer, that's why I'm keeping the downvote.
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.