- Need currently logged in Windows user name in java
- 1 Answer 1
- Not the answer you’re looking for? Browse other questions tagged windows jsp or ask your own question.
- Linked
- Related
- Hot Network Questions
- Subscribe to RSS
- Detect user logged on a computer using Java
- 4 Answers 4
- Not the answer you’re looking for? Browse other questions tagged java active-directory or ask your own question.
- Linked
- Related
- Hot Network Questions
- Subscribe to RSS
- Get login username in java
- 9 Answers 9
- Windows logged user informations
- 3 Answers 3
- Retrieving the logged in user’s name and hostname in Windows
- 2 Answers 2
Need currently logged in Windows user name in java
An Java application is hosted in Linux server. and we are trying to access the windows username of the user who tries to access the application using browser.
In the jsp, we are trying to print the username of the user with the below lines of code.
But the output prints the username of the linux server and not the windows user.
1 Answer 1
Oups, in a client server application, you must know what runs on server and what runs on client.
The JSP is first translated to java code, compiled and executed server side and produces HTML that is displayed on client. That’s the reason why you get the user that runs the server application. You will need an applet (a java application executed client side in a browser) to to that, or you can use javascript as suggested in answers to this question :
Not the answer you’re looking for? Browse other questions tagged windows jsp or ask your own question.
Linked
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.4.16.39093
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Detect user logged on a computer using Java
I want to develop an Java application that can detect the user logged on a Window Domain. These credentials are going to be used to logging on the Java application.
How can I do this?
4 Answers 4
If you need to domain name, you can use this :
Note: System.getProperty(«user.name») will only work if the user launches the application. If the program is run by System or an application like LANDesk, then the user will come out as «SYSTEM» (under domain «NT AUTHORITY»).
In which case, the second solution using NTSystem will return the correct results.
I noticed that the topicstarter asks afterwards in comments if s/he can use it in a Java webapp which was answered with «no» everytime. This is true if you run the particular code at the server side, but not if you run it at the client side in flavor of an applet or jnlp which is embedded in the requested jsp/html page. It however has to send the needed information to the server side afterwards.
Not the answer you’re looking for? Browse other questions tagged java active-directory or ask your own question.
Linked
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.4.16.39093
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Get login username in java
How can I get the username/login name in Java?
This is the code I have tried.
I get a SecurityException when I try to run this code. Could someone please tell me whether I’m heading in the right direction, and help me to understand the problem.
9 Answers 9
inspired by @newacct‘s answer, a code that can be compiled in any platform:
System.getProperty(«user.name») is not a good security option since that environment variable could be faked: C:\ set USERNAME=»Joe Doe» java . // will give you System.getProperty(«user.name») You ought to do:
JDK 1.5 and greater.
I use it within an applet, and it has to be signed. info source
Using JNA its simple:
The ‘set Username=»Username» ‘ is a temporary override that only exists as long as the cmd windows is still up, once it is killed off, the variable loses value. So i think the
is still a short and precise code to use.
System.getenv().get(«USERNAME»); — works on windows !
In environment properties you have the information you need about computer and host! I am saying again! Works on WINDOWS !
Below is a solution for WINDOWS ONLY
In cases where the application (like Tomcat) is started as a windows service, the System.getProperty(«user.name») or System.getenv().get(«USERNAME») return the user who started the service and not the current logged in user name.
Also in Java 9 the NTSystem etc classes will not be accessible
So workaround for windows: You can use wmic, so you have to run the below command
If available, this will return output of the form:
Note: For windows you need to use cmd /c as a prefix, so below is a crude program as an example:
Windows logged user informations
I want to create an application in java that is monitoring logged users activities(create, delete, update folders/files). The problem is that I didn’t found how to get the OS of the logged user (java app is running on a windows server and users have windows on their machine, I want to know if there is a way to get the windows version of the logged users).
3 Answers 3
You would use JNI and call a native (windows-specific DLL) method to get the information. You would have to create this DLL yourself in (likely in C/C++)
If it’s a web application you can use user-agent header. It can change easily, but worth to try. Check https://stackoverflow.com/a/1328393/5684110.
You’re asking for a Windows-specific feature. I doubt Java would support that, so you will need a native module (written in C/C++ or something) to read that information and pass it into your Java application via JNI or a local socket connection. Maybe you could poll that data from Active Directory.
Another idea is, you could get the info through another Java app running on the client PC at startup. That way you would be able to monitor changes in the file system and some basic system properties like OS name and version (see Mustafa’s answer). The app would be silently downloaded into the workstation and run automatically through Active Directory, sending the data to your server app via socket, web or a webservice.
Retrieving the logged in user’s name and hostname in Windows
I’m currently writing a Java application to be used with a Windows-Machine authed with an ActiveDirectory. The application basically only needs to know the user’s name and hostname. I know there are
But I am not sure wether System.getProperty(«user.name») will function correctly with the VM running on windows (I searched google and found a lot of threads saying it might not work with windows, as it might return something different, depending on the environment-variables (and I am currently unable to test it [I’m running ubuntu and archLinux]).
So, I wondered if there is a better and more secure way to handle this and stumbled upon NTSystem . But NTSystem does not seem to be available on Linux (which I use for developing), which — I think — is due to calling native windows code.
My question would hence be: «Is there a secure way to retrieve the logged in user’s name in Windows and if yes — how would you accomplish that?»
2 Answers 2
user.name is inherently insecure because it can be overridden via -Duser.name=XYZ . This might be an issue for you, or it may not be
Obviously NTSystem won’t work on Linux but you mention that you are writing a GUI to be run on Windows. Are you trying to validate the Windows user name of the user? You can do this via NTSystem embedded in the code which runs on the Windows client but not (of course) code which runs under the Linux OS .