
...
Code Block | ||
---|---|---|
| ||
Path file = new File("file").toPath(); // Throw exception rather than overwrite existing file Set<OpenOption> options = new HashSet<OpenOption>(); options.add(StandardOpenOption.CREATE_NEW); options.add(StandardOpenOption.APPEND); // File permissions should be that only user may read/write file Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rw-------"); FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute(perms); try (SeekableByteChannel sbc = Files.newByteChannel(file, options, attr)) { // write data }; |
Compliant Solution (Java 1.7, Windows)
Java provides no Windows analog of PosixFilePermissions
.
AclFileAttributeView â“ Supports reading or updating a file's Access Control Lists (ACL). The NFSv4 ACL model is supported. Any ACL model, such as the Windows ACL model, that has a well-defined mapping to the NFSv4 model might also be supported.
Exceptions
FIO03-EX0: If a file is created inside a directory that is both secure and unreadable by untrusted users, then that file may be created with the default access permissions. See FIO07-J. Do not create temporary files in shared directories for the definition of a secure directory. This could be the case if, for example, the entire filesystem is trusted, or is accessible only to trusted users.
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="6db7f3e97e388f59-a8519d14-401948dd-b2569cd5-5a8bca74b67bfc699e331004"><ac:plain-text-body><![CDATA[ | [[API 2006 | AA. Bibliography#API 06]] |
| ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="8c506993dbccd738-dbfe6dcc-473c4c22-84b5b926-502201353930ea3b9c140105"><ac:plain-text-body><![CDATA[ | [[CVE | AA. Bibliography#CVE]] |
| ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="acdb357c03d5f037-f9348a00-4b2e47c7-8071bf59-a5078c32932ed3f060af3f46"><ac:plain-text-body><![CDATA[ | [[Dowd 2006 | AA. Bibliography#Dowd 06]] | Chapter 9, "UNIX 1: Privileges and Files" | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="aaf742f4ccabc314-d8e49717-46074233-bbe39c22-38023c03230b378b33fe0a1f"><ac:plain-text-body><![CDATA[ | [[J2SE 2011 | AA. Bibliography#J2SE 11]] |
| ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="2760babdb92dd618-30b31364-42a644e6-ae75b43c-be1fa4d397f517481d4a391f"><ac:plain-text-body><![CDATA[ | [[OpenBSD | AA. Bibliography#OpenBSD]] |
| ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="01a46b15ccb94cf5-11196cd7-4f894fba-a1308f6f-689cfa5797ab7ccd3ed683bd"><ac:plain-text-body><![CDATA[ | [[Open Group 2004 | AA. Bibliography#Open Group 04]] | "The | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="1f39a2f4b72853bb-901f71f0-412e49cc-91658820-75e9ff9b284c7ec2e442d310"><ac:plain-text-body><![CDATA[ | [[Viega 2003 | AA. Bibliography#Viega 03]] | Section 2.7, "Restricting Access Permissions for New Files on UNIX" | ]]></ac:plain-text-body></ac:structured-macro> |
...