1

What is the best way to get the current logged in user through Java application running on JBoss. The system environment variable System.getProperty("user.name") does not work as JBoss is running as a service.

The application is running on a laptop running Windows XP. The application is web-based and accessed using Internet Explorer by particular logged in Windows user. Only 1 Windows user can be logged in at a time. The application needs to know which user has logged in to do a role based menu and security features. So both the client (Internet Explorer) and the server (JBoss) are running on the same laptop. Currently, we determine the logged in user using tasklist /v and then parsing the output to look for certain processes and the user running them. However, need to know if there is a cleaner way of getting the logged in Windows user.

1
  • Do you want to find the name of the user logged into your web app, maybe? Maybe HttpServletRequest.getRemoteUser() is what you're looking for? Commented Jun 16, 2009 at 14:49

4 Answers 4

3

I don't think the question really makes much sense. There may be no users logged onto the host - or there may be multiple users.

I'd be somewhat wary of a design that really wanted to know this anyway - web applications shouldn't really be interested in that sort of thing, IMO. What are you trying to do?

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

2 Comments

The application is running on a laptop running Windows XP. The application is web-based and accessed using Internet Explorer by particular logged in Windows user. Only 1 Windows user can be logged in at a time. The application needs to know which user has logged in to do a role based menu and security features. So both the client (Internet Explorer) and the server (JBoss) are running on the same laptop. Currently, we determine the logged in user using tasklist /v and then parsing the output to look for certain processes and the user running them.
It sounds to me like it would be best not running as a service then, but being started as a "regular" application - at which point the relevant user is the one that the application would be running as.
3

String uname = System.getenv("user.name")

Reference: http://download.oracle.com/javase/tutorial/essential/environment/sysprop.html

1 Comment

I think you want System.getProperty("user.name"), not getenv.
0

This assumes you have stored an environment variable named USERNAME when the user logged in:

String username = System.getenv("USERNAME");

Or, if you want the complete set of environment variables:

Map<String, String> envMap = System.getenv();

Then iterate through the map to get an environment variable in which you're storing a username.

Map<String, String> envMap = System.getenv();
int mapsize = envMap.size();
Iterator i = envMap.entrySet().iterator();
for (int j = 0; j < mapsize; j++) {
    Map.Entry entry = (Map.Entry) i.next();
    Object key = entry.getKey();
    Object value = entry.getValue();
}

Comments

0

Use JAAS authentication. You should be able to use NTLM on windows, so the user won't have to do any additional work. Then, on the server you can use the security context to get the caller principal.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.