Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating group permissions with Java  RSS feed

 
Deb Miller
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question is: How do I change the group permissions on a directory using Java?
I have a Java app running on Linux, using Tomcat and Apache. The app creates new directories and writes files to these directories. The "owner" and "group" of these directories is listed as tomcat4. The permissions that are automatically set only allow the owner to create files within these directories.
I have another program running under a separate id that later reads the files and needs to write files to the same directory. It, of course, gets a permission error. If I could fix the group permissions, I could put this id into the tomcat4 group and it would be able to write files to this directory. However, I haven't been able to get Java/Apache/Tomcat to let me set the group permissions. I've tried to use the Java class FilePermission. I've also set the umask for both Apache and Tomcat. Whatever is setting the permissions is ignoring all my attempts.
After much searching on the web, the only thing I've found is a item on the java.sun forum that uses a Runtime class to do a chmod. Isn't there a better way to do this?
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Posts: 12156
256
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Deb
Not sure if this is something you want to be doing from inside Java or not. This should be doable from Unix space. Unfortunately it is 1.30 am here, so I havent quite got the perfect solution yet. But see if this helps (or at least gives some ideas):

So it is at least setting the group correctly on my created file.
So if you set the "set group id" bit on the directory itself, then anyone trying to write to that directory will automatically have the group set on the file.
Regards, Andrew
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!