title: Java cant access Files In NFS Share
body: <p>Some strange behavior in Java app JBOSS (technology not relevant..)</p>
  
  <p>application can access files, only OWNED by user, which runs process. Group is not used.</p>
  
  <blockquote>
    <p>-rwxrwxrwx. 1 root GroupUnix1 448 Jun 4 06:26 output_new.txt</p>
    
    <p>id uid=401322(MySuperUser) gid=401322(MySuperGroup) >groups=401322(MySuperGroup),7013595(GroupUnix1 ) >context=unconfined_u:system_r:openshift_t:s0:c528,c834</p>
    
    <p>getenforce Permissive
    From first view looks like Java does not care about file level permissions. Only ownership.</p>
    
    <p>ls -la
    -rw------- 1 MySuperUser GroupUnix1 308 Jun 3 14:15 output_new.txt &lt;-access ok</p>
  </blockquote>
  
  <p>Any ideas how to access file in Java, which is owned by Group and not user? I run in MultiUser environment.</p>
  
  <blockquote>
    <p>----rw---- 1 MySuperUser GroupUnix1 308 Jun 3 14:15 output_new.txt access ok ? WHY?</p>
    
    <p>---------- 1 MySuperUser GroupUnix1 308 Jun 3 14:15 output_new.txt access ok ? WHY?</p>
    
    <p>----rw---- 1 root GroupUnix1 364 Jun 3 14:16 output_new.txt no access ? WHY?</p>
  </blockquote>
  
  <p>Error from JBOSS. But basically i get access restricted.</p>
  
  <blockquote>
    <p>Error: java.nio.file.FileSystemException: /mnt/SuperFolder/share1/outbound/output_new.txt: Operation not permitted sun.nio.fs.UnixException.translateToIOException(UnixException.java:91) sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102) sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107) sun.nio.fs.UnixFileAttributeViews$Posix.setMode(UnixFileAttributeViews.java:228) sun.nio.fs.UnixFileAttributeViews$Posix.setPermissions(UnixFileAttributeViews.java:250) java.nio.file.Files.setPosixFilePermissions(Files.java:1992) com.company.soft.eap.test.nfs.ReadFile.doGet(ReadFile.java:85) javax.servlet.http.HttpServlet.service(HttpServlet.java:734) javax.servlet.http.HttpServlet.service(HttpServlet.java:847)</p>
  </blockquote>
  
  <p>CODE i try:</p>
  
  <pre><code>String path = "/mnt/SuperFolder/share1/outbound/output_new.txt";
  // (use relative path for Unix systems)
  File f = new File(path);
  // (works for both Windows and Linux)
  f.getParentFile().mkdirs();
  f.createNewFile();
  FileWriter fstream = new FileWriter(path, true);
  BufferedWriter outt = new BufferedWriter(fstream);
  outt.write(" something \n ");
  outt.newLine();
  // close buffer writer
  outt.close();
  </code></pre>
  
  <p>So if file has 070 it cant write, edit as a group. </p>
  
  <p>UPDATE: writing happens to NFS share. outside NFS this behaves as expected. But inside share - Crashes. </p>