Java - get windows logged user - java

I'm logged in to windows 10 with a regular user (no admin privileges). I run my java application with admin privileges, but I need to get the normal logged-in user path (that's unprivileged) at runtime. System.getProperty ("user.home") only returns me the admin user path. Can anyone help me solve this problem?
Thanks a lot

Change "user.home" to "user.name". However, if you run the program as Administrator that is what it will return.

Related

how to hide password while typing in console in java

I am developing a online order management system in java connecting MySql to run in console where I need to login using userid and password. so, here I need to mask the password while typing in console. can anyone pls, help me with this?
The class Console has a method readPassword() that might be helpful in your case.
char[] password = System.console().readPassword("password:");
notice: you can't run this code in IDE, you have to execute on terminal.

running a javaservice using the administrator user

I have a Java application which I want to run it using the JavaService wrapper.
The service works well when the -user parameter is not used (using the defaul user as local system).
For permissions reasons, I need use the administrator user as a owner of service, but the following message apears when I start it.
Translate: It can not start the service due to error in the login.
The service.exe install command is the following:
JavaService.exe -install "ServiceName" "%JAVA_HOME%\bin\client\jvm.dll" -start "ServiceClass" -user ".\Administrador" -password "1234"
UPDATE:
If I change the user of the service using the services.msc console, the result is the same.
My problem is solved.
The Error message 1069 was caused then this user doesn't have permisions to logon as a service.
To add this permision follow the steps:
Open the ocal security settings (start -> run -> secpol.msc) if is not domain or setting the Default Domain Controller GPO is a Domain server.
Expand Local Policies, and then click User Rights Assignment
In the right pane, right-click Log on as a service, and then click Add User or Group

System.getProperty() on a server

I'm using System.getProperty("user.name") to get the name of localuser. It works fine and now my class need to work on server.
Unfortunately, System.getProperty("user.name") try to catch the user name of the server and return "root".
Is it possible using System.getProperty() I get the name of localuser running the class on the server? If not, is there any way?
System.getProperty("user.name") returns user's account name on which the java process is running. As you mentioned on your local computer you are running it on user "Filiipe" however on server you are running it as a root user. Maybe you are using tomcat/jboss started automatically as a system service, that kind of services are running under root user.
You can also easily check it with ps -ef command on linux - the first column is user that started the service.
You can also try override this parameter by adding additional option to your server starting script -Duser.name=Fellipe. I didn't try it but it may work.

Remote admin of glassfish does not work

I have a server on remote where i am logged by ssh. I have unzip it the glassfish v 3.1.2 and follow the steps http://bbissett.blogspot.com.es/2012/01/asadmin-with-remote-glassfish.html until the part where enters in the link of admin(port 4848) There I am redirect by the browser to the web where the login loader (ip-glassfish-installed:4848) starts spinning and nothing happens.
The log I got in the server is "User [] from host localhost does not have administration access|#]" But I have changed the admin password and login with it. So I dont understand in first instance why I got the user empty. Also, although I think is not related, says that the certificate has expired.
You need to enable remote adminstration. Here are couple of other useful links that provide help in that direction:
http://www.adam-bien.com/roller/abien/entry/enabling_remote_administration_for_glassfish
https://blogs.oracle.com/quinn/entry/securing_adminstration_in_glassfish_server1
The problem is that the user I logged in the remote machine by ssh did not have the right permission to execute the domain, even after doing "sudo su". If I enter in the remote machine with the root user everything works fine, or using "sudo su -" after login with the normal user.

How do I change the logged in user to another temporary?

In my system, I want to have only the administrator account to access the specific folder.
So when client login as himself, click the open file link, I want it switch to the admin account temporary to open the files. After closing the openning file, the account goes back to the original account of the client.
I find it can be done in C# in ASP.NET by this link:
How do I change the logged in user to another?
Wondering if we can do that in Java?
You can perform a task as a different user by calling RUNAS via Runetim.exec()
RUNAS USAGE:
RUNAS [ [/noprofile | /profile] [/env] [/savecred | /netonly] ]
/user:<UserName> program
RUNAS [ [/noprofile | /profile] [/env] [/savecred] ]
/smartcard [/user:<UserName>] program
RUNAS /trustlevel:<TrustLevel> program
/noprofile specifies that the user's profile should not be loaded.
This causes the application to load more quickly, but
can cause some applications to malfunction.
/profile specifies that the user's profile should be loaded.
This is the default.
/env to use current environment instead of user's.
/netonly use if the credentials specified are for remote
access only.
/savecred to use credentials previously saved by the user.
This option is not available on Windows 7 Home or Windows 7 Starter Editions
and will be ignored.
/smartcard use if the credentials are to be supplied from a
smartcard.
/user <UserName> should be in form USER#DOMAIN or DOMAIN\USER
/showtrustlevels displays the trust levels that can be used as arguments
to /trustlevel.
/trustlevel <Level> should be one of levels enumerated
in /showtrustlevels.
program command line for EXE. See below for examples
Examples:
> runas /noprofile /user:mymachine\administrator cmd
> runas /profile /env /user:mydomain\admin "mmc %windir%\system32\dsa.msc"
> runas /env /user:user#domain.microsoft.com "notepad \"my file.txt\""
http://ss64.com/nt/runas.html
If you're using Java EE I think you could use the #RunAs annotation (but I haven't tried):
http://docs.oracle.com/javaee/6/api/javax/annotation/security/RunAs.html
Edit:
And here is a link to more about JAAS "doAs", but I haven't studied it yet:
http://docs.oracle.com/javase/7/docs/technotes/guides/security/jaas/JAASRefGuide.html

Categories

Resources