File permissions in Linux


#1

Hi team,

We have recently purchased the Aspose product license for java and tried to use the Aspose pdf library to manipulate our pdf document. However, when saving the pdf in the Linux environment, it created the file with owner read/write permission only instead of applying the umask. Is that the default behavior when creating a file in Linux environment? Is there a way for us to use the library to set the file permission before creating/saving it?

Thanks


#2

@VRavi_amerisourcebergen_com

Thank you for contacting support.

Would you please share generated PDF document along with the screenshots of current permissions and elaborating expected output so that we may investigate further and assist you accordingly. Before sharing requested data, please ensure using Aspose.PDF for Java 19.7.


#3

Hi Farhan,

The version we are using is 19.6 because at the time when I started doing development, that was the latest release I saw. Unfortunately, we no longer have those files stored on our linux box so I can’t get a screenshot for you but the expected output file permission is 664 where as the actual output file permission when it get generated was 600. Will changing to version 19.7 fix the issue?

Thanks


#4

@VRavi_amerisourcebergen_com

This appears to lie in JVM context instead of Aspose.PDF for Java API. For example, you may set setWritable, setReadable etc as per your requirements. Pleas try below code snippet in your environment and verify this to be out of context for the API. Feel free to contact us if you have any further concerns.

// instantiate Document instance with path of input file as argument
Document pdfDocument = new Document(dataDir + "Test.pdf");
TextAbsorber textAbsorber = new TextAbsorber();
pdfDocument.getPages().accept(textAbsorber);
String extractedText = textAbsorber.getText();
textAbsorber.visit(pdfDocument);
java.io.File file = new java.io.File(dataDir + "Extracted_text_19.7.txt");
//Setting permissions here
file.setWritable(true);
// Create a writer and open the file
java.io.FileWriter writer = new java.io.FileWriter(file);
writer.write(extractedText);
// Close the stream
writer.close();

#5

Hi Farhan,

The pdf will contain images and other type of documents as well, I’m not sure if we will be able to convert it to a File object without the risk of changing the content in any negative way. Do you know why umask was not applied when the file is saved? I believe by default the jvm applies whatever permission is set by umask in the linux environment.

Thanks


#6

@VRavi_amerisourcebergen_com

Thank you for the feedback.

We have logged a ticket with ID PDFJAVA-38783 in our issue management system for further investigation and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

We are sorry for the inconvenience.


#7

@VRavi_amerisourcebergen_com

We have investigated it further and would like to update you that, if umask is changed, java will only use the umask configuration for the current process, otherwise the default configuration will be used.

We have tested the following workflow under Ubuntu 18 Linux (4.15.0-58-generic #64-Ubuntu) and can not notice any issue. PDF file is created with umask that is configured in the console. We can advise you to pay attention to which parameter Your program or server is running or share additional information for reproducing the issue.

Test program:

import com.aspose.pdf.Document;
import java.io.*;

public class Test {
    public static void main(String[] args) {

        try {
            //create default file
            OutputStream stream = new FileOutputStream(args[0]);
            stream.close();

            //create pdf file
            Document doc = new Document();
            doc.getPages().add();
            doc.save(args[0]+".pdf");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

Our test log:

test for umask 002

username:~/work/test/target/classes$ umask 002
username:~/work/test/target/classes$ umask
0002
username:~/work/test/target/classes$ java -cp ".:./aspose-pdf-19.7.jar" Test t1
username:~/work/test/target/classes$ ls
aspose.pdf-19.7.jar  t1  t1.pdf  Test.class
username:~/work/test/target/classes$ ls -ld t1
-rw-rw-r-- 1 username username 0 aug 22 15:04 t1
username:~/work/test/target/classes$ ls -ld t1.pdf
-rw-rw-r-- 1 username username 37817 aug 22 15:04 t1.pdf

then we set new value: umask 022

username:~/work/test/target/classes$ umask 022
username:~/work/test/target/classes$ umask
0022
username:~/work/test/target/classes$ java -cp ".:./aspose-pdf-19.7.jar" Test t2
username@username-B360M-D3P:~/work/test/target/classes$ ls
aspose.pdf-19.7.jar  t1  t1.pdf  t2  t2.pdf  Test.class
username:~/work/test/target/classes$ ls -ld t2
-rw-r--r-- 1 username username 0 aug 22 15:05 t2
username:~/work/test/target/classes$ ls -ld t2.pdf
-rw-r--r-- 1 username username 37817 aug 22 15:05 t2.pdf

You may visit below links for additional information about setting umask:

https://docs.oracle.com/cd/E19683-01/817-3814/userconcept-95347/index.html