1

I need to know using Java if the user that executes the Java class has the required permission to change the system time.

I just need a boolean returning method.

Achintya Jha
  • 12,735
  • 2
  • 27
  • 39
Alfergon
  • 5,463
  • 6
  • 36
  • 56
  • 2
    You can't change the system time in Java so I suspect there is no standard way to check for permission to do this either. How do you give your user's permissions currently? – Peter Lawrey Jan 14 '13 at 14:55
  • Why there is need of checking that permission? Besides, you can check this [post](http://stackoverflow.com/questions/6203857/how-can-i-set-the-system-time-in-java) for more details. – CuriousMind Jan 14 '13 at 14:56
  • It seems to me, that in any case solution will depend on used OS – Andremoniy Jan 14 '13 at 15:01
  • We currently have to allow the user to change the system time via a dialog (it's part of the requirements) and we do it usgin Runtime.getRuntime().exec(command). But if the user doesn't have rights to do it, then the time doesn't change. So I would like to assert if the user has the rights to show a popup alerting the user so he can call support or something like that. – Alfergon Jan 14 '13 at 15:02
  • We change the command depending on the OS in which the app is running. – Alfergon Jan 14 '13 at 15:02
  • Why don't you *try* and change the time, then if its not changed raise a pop up? – Tom Jan 14 '13 at 15:03
  • I already do that check, but I'd prefer to assert beforehand whether the user will be able to perform said action. – Alfergon Jan 14 '13 at 15:10

1 Answers1

0

That's not trivial.

On Unix-based systems, you can check whether the current user has the capability CAP_SYS_TIME but there is no standard way to check this from Java.

On Windows, they will need admin rights but I don't know which permission exactly. Like on Unix, there is no Java API that you could use to check.

Maybe an external script/binary could do the check. You could then use ProcessBuilder to execute this tool.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • I was afraid that this was the only choice, so I think we'll end using this aproach. Thank you all. – Alfergon Jan 14 '13 at 15:11