Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to enforce user management with file reading in java?  RSS feed

 
ilias basha
Ranch Hand
Posts: 55
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need to enforce user management with respect to the file reading in java applicaiton.

If the applicaiton is running under the other usernames it should not be allowed to read the file.

Kindly advise how to achieve this..
 
ilias basha
Ranch Hand
Posts: 55
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we enforce user based read privileges in java?? or is it the responsibility of the OS-file system??
 
Stephan van Hulst
Saloon Keeper
Posts: 7797
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is handled purely through the OS. You should be able to tell the OS the file is only readable for a specific user though. The problem is that this is mostly platform dependent. For example, in Unix you should be able to handle these permissions by making Runtime.exec() execute chmod.
 
Joe Ess
Bartender
Posts: 9428
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could get the current user name with:

and not give unauthorised users access. Of course, this only prevents access through your application. The file would still be accessible through other means.
 
ilias basha
Ranch Hand
Posts: 55
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan, Thanks for the suggestion But my application runs on the windows environment, and using i am able to hide and make read only file in windows but was not sure of the windows32 api instructions to make changes in privileges of the file for restricting access though.

Joe, Thanks for the property to get the user name of the OS, but my requirement is beyond application, infact it should enforce restriction in OS level
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!