title: How to change a file owner created from Java Web Application deployed in Wildfly?
body: <p>I'm developing a Web Application in Java, it deployed in Wildfly 15. Wildfly run with a specific user (wildfly or jboss), the application create a file (.docx) for example: stuff.docx in a specific diretory /opt/documents, this directory beloging to other user (lool).</p>
  
  <p>The user "lool"  run another application (loolwsd LibreOffice Web) to edit text, but is some strict with permissions and it need be owner to files. I've added wildfly user to editor group, and change group permissions to 775 in directory and file, but editor doesn't execute correctly. </p>
  
  <p>I tried change owner with Java NIO but throw "Operation not allowed"</p>
  
  <p>Example: </p>
  
  <pre><code>Path path = Paths.get(sPath);
  FileOwnerAttributeView foav = Files.getFileAttributeView(path, FileOwnerAttributeView.class);
  
  UserPrincipal owner = foav.getOwner();
  logger.info("Original owner  of  " + path + "  is " + owner.getName());
  
  FileSystem fs = FileSystems.getDefault();
  UserPrincipalLookupService upls = fs.getUserPrincipalLookupService();
  
  UserPrincipal newOwner = upls.lookupPrincipalByName("lool");
  foav.setOwner(newOwner);
  
  UserPrincipal changedOwner = foav.getOwner();
  logger.info("New owner  of " + path + " is %s%n" + changedOwner.getName());
  </code></pre>
  
  <p>When I create a file from Wildfly this created by wildfly, I want change user after this process to editor user. How to change file user owner from java (in wildfly) safetly?</p>