Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if a user is root in a java application

Tags:

java

linux

root

How can i verify if a user is root in a java application?

Thanks

like image 925
sssssssdddds Avatar asked Feb 25 '11 12:02

sssssssdddds


2 Answers

Process p = Runtime.getRuntime().exec("id -u")

Keep in mind that the "root" user on a system may not be called root (although it's rare to change it), and it's also possible to alias it to another username. If the current user is root-like, the output will be 0.

like image 71
nickgrim Avatar answered Sep 20 '22 08:09

nickgrim


Easy. Just use

System.getProperty("user.name")
like image 38
Abel Callejo Avatar answered Sep 23 '22 08:09

Abel Callejo