-4

I want to get logged username on windows , I mean the user logged in to windows using java. I used System.getProperty("user.name"); but I got the server-name, not the user.

13
  • In what context? The computer? A webapp? According to the documentation, user.name is the name of the account that is logged into the computer. Commented Apr 23, 2013 at 11:04
  • can you please elborate more on your envionment? are you talking about Web application or Desktop application? if its web application System.getProperty("user.name") will give you user logged on server machine. Commented Apr 23, 2013 at 11:05
  • possible duplicate of stackoverflow.com/questions/797549/get-login-username-in-java Commented Apr 23, 2013 at 11:05
  • 1
    If you use System.getProperty("user.name") in a JSP, which is deployed in a Servlet container running under Windows as a service with the System account, you will see the host name, since that is the "real" name of the system account. Commented Apr 23, 2013 at 11:07
  • 3
    Why does every starter think that Java/JSP runs in webbrowser instead of in webserver? Java/JSP runs in webserver and produces a bunch of HTML code which get sent to the webbrowser. In order to run Java in webbrowser, you need a client application (e.g. Swing) in flavor of an applet or webstart which you embed via <object> element in the produced HTML. This way the webbrowser will download and run it in its own (sandboxed!) environment. Commented Apr 23, 2013 at 11:12

1 Answer 1

4

Getting the name of the user logged into your web application (which I think is what you want to do, based on your comments) entirely depends on how you have implemented authentication in your system. However, if your login mechanism adds this information, the username might be available in request.getRemoteUser() or request.getUserPrincipal(). But as mentioned, it all depends. Your authentication mechanism might expose this otherwise, but then we would need more information to assist.

System.getProperty("user.name") will only give you the username of the user running the java process.

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

14 Comments

If you use a waffle filter, it will add the correct user credentials to the request. See github.com/dblock/waffle for more information.
Great! If it's Kerberos/NTLM that is used, that will probably do it.
@tstorms: I don't know why you deleted your answer. Until now, it was the only reasonable attempt here to actually solve the problem. The Waffle documentation is however pretty vague. There are many NTLM authentication modules for Java supporting NTLMv1, but AFAIK none supporting NTLMv2. Do you know if Waffle also supports NTLMv2? NTLMv1 is for good reasons disabled in many Windows domains.
Yes i am using Kerberos for Single sign in. But how can i get it from Kerberos.
I know, my answer has been deleted. Some admins are just too diligent... To answer your question, yes, waffle supports NTLM 2 out of the box.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.