I have following environment setup.
Server: Ubuntu
App Server: Tomcat7
Java: JDK 7
A servlet need to write a file into a mount folder. Tomcat is running using a user called tomcat7
and a CIFS
is bound at /mntt/mydir/
with a different user called coder
.
The permission is set to 777
for /mntt/mydir
Service will create a folder and try to upload/write a file into that folder.
When folder is created it has permission set to 755
and file has permission set to 644
, owner of both file and folder is coder
and not tomcat7
So, when my program tries to write something in file it throws Permission denined
exception.
UPDATE File Creation Code
//Create directory
File uploadFile = new File(dirpath);
uploadFile.mkdirs();
//Create and Write to File
OutputStream stream = new FileOutputStream(new File(dirPath+"/upload"));
Please guide. Also, please let me know if you need further information.
Thanks
Finally i solved the problem !!
I run the tomcat service as coder
user by modifying /etc/defaults/tomcat7
.
Also, i have to change permissions of few tomcat
directories.