List of usage examples for java.nio.file.attribute PosixFilePermission OWNER_WRITE
PosixFilePermission OWNER_WRITE
To view the source code for java.nio.file.attribute PosixFilePermission OWNER_WRITE.
Click Source Link
From source file:android.databinding.compilationTest.BaseCompilationTest.java
private void setExecutable() throws IOException { Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>(); //add owners permission perms.add(PosixFilePermission.OWNER_READ); perms.add(PosixFilePermission.OWNER_WRITE); perms.add(PosixFilePermission.OWNER_EXECUTE); //add group permissions perms.add(PosixFilePermission.GROUP_READ); //add others permissions perms.add(PosixFilePermission.OTHERS_READ); Files.setPosixFilePermissions(Paths.get(new File(testFolder, "gradlew").getAbsolutePath()), perms); }
From source file:org.cryptomator.cryptofs.CryptoFileSystemImpl.java
void checkAccess(CryptoPath cleartextPath, AccessMode... modes) throws IOException { if (fileStore.supportsFileAttributeView(PosixFileAttributeView.class)) { Set<PosixFilePermission> permissions = readAttributes(cleartextPath, PosixFileAttributes.class) .permissions();//from w w w. j av a 2 s . c om boolean accessGranted = true; for (AccessMode accessMode : modes) { switch (accessMode) { case READ: accessGranted &= permissions.contains(PosixFilePermission.OWNER_READ); break; case WRITE: accessGranted &= permissions.contains(PosixFilePermission.OWNER_WRITE); break; case EXECUTE: accessGranted &= permissions.contains(PosixFilePermission.OWNER_EXECUTE); break; default: throw new UnsupportedOperationException("AccessMode " + accessMode + " not supported."); } } if (!accessGranted) { throw new AccessDeniedException(cleartextPath.toString()); } } else if (fileStore.supportsFileAttributeView(DosFileAttributeView.class)) { DosFileAttributes attrs = readAttributes(cleartextPath, DosFileAttributes.class); if (ArrayUtils.contains(modes, AccessMode.WRITE) && attrs.isReadOnly()) { throw new AccessDeniedException(cleartextPath.toString(), null, "read only file"); } } else { // read attributes to check for file existence / throws IOException if file does not exist readAttributes(cleartextPath, BasicFileAttributes.class); } }
From source file:com.facebook.buck.zip.ZipStepTest.java
@Test public void zipMaintainsExecutablePermissions() throws IOException { assumeTrue(Platform.detect() != Platform.WINDOWS); Path parent = tmp.newFolder("zipstep"); Path toZip = tmp.newFolder("zipdir"); Path file = toZip.resolve("foo.sh"); ImmutableSet<PosixFilePermission> filePermissions = ImmutableSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.GROUP_READ, PosixFilePermission.OTHERS_READ); Files.createFile(file, PosixFilePermissions.asFileAttribute(filePermissions)); Path outputZip = parent.resolve("output.zip"); ZipStep step = new ZipStep(filesystem, outputZip, ImmutableSet.of(), false, ZipCompressionLevel.MIN_COMPRESSION_LEVEL, Paths.get("zipdir")); assertEquals(0, step.execute(TestExecutionContext.newInstance()).getExitCode()); Path destination = tmp.newFolder("output"); Unzip.extractZipFile(outputZip, destination, Unzip.ExistingFileMode.OVERWRITE); assertTrue(Files.isExecutable(destination.resolve("foo.sh"))); }
From source file:org.apache.nifi.registry.bootstrap.RunNiFiRegistry.java
private synchronized void savePidProperties(final Properties pidProperties, final Logger logger) throws IOException { final String pid = pidProperties.getProperty(PID_KEY); if (!StringUtils.isBlank(pid)) { writePidFile(pid, logger);/* w w w. ja v a 2s.c o m*/ } final File statusFile = getStatusFile(logger); if (statusFile.exists() && !statusFile.delete()) { logger.warn("Failed to delete {}", statusFile); } if (!statusFile.createNewFile()) { throw new IOException("Failed to create file " + statusFile); } try { final Set<PosixFilePermission> perms = new HashSet<>(); perms.add(PosixFilePermission.OWNER_READ); perms.add(PosixFilePermission.OWNER_WRITE); Files.setPosixFilePermissions(statusFile.toPath(), perms); } catch (final Exception e) { logger.warn("Failed to set permissions so that only the owner can read status file {}; " + "this may allows others to have access to the key needed to communicate with NiFi Registry. " + "Permissions should be changed so that only the owner can read this file", statusFile); } try (final FileOutputStream fos = new FileOutputStream(statusFile)) { pidProperties.store(fos, null); fos.getFD().sync(); } logger.debug("Saved Properties {} to {}", new Object[] { pidProperties, statusFile }); }
From source file:org.kitodo.filemanagement.FileManagementTest.java
private static void setFileExecutable(File file) throws IOException { Set<PosixFilePermission> perms = new HashSet<>(); perms.add(PosixFilePermission.OWNER_READ); perms.add(PosixFilePermission.OWNER_WRITE); perms.add(PosixFilePermission.OWNER_EXECUTE); perms.add(PosixFilePermission.OTHERS_READ); perms.add(PosixFilePermission.OTHERS_WRITE); perms.add(PosixFilePermission.OTHERS_EXECUTE); perms.add(PosixFilePermission.GROUP_READ); perms.add(PosixFilePermission.GROUP_WRITE); perms.add(PosixFilePermission.GROUP_EXECUTE); Files.setPosixFilePermissions(file.toPath(), perms); }
From source file:org.artifactory.security.crypto.CryptoHelper.java
public static void setPermissionsOnSecurityFolder(File securityFolder) throws IOException { // The security folder should accessible only by the owner if (FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) { Files.setPosixFilePermissions(securityFolder.toPath(), EnumSet.of(PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_READ)); }//w w w.j a va2 s .c o m }
From source file:org.kitodo.filemanagement.FileManagementTest.java
private static void setFileNotExecutable(File file) throws IOException { Set<PosixFilePermission> perms = new HashSet<>(); perms.add(PosixFilePermission.OWNER_READ); perms.add(PosixFilePermission.OWNER_WRITE); perms.add(PosixFilePermission.OTHERS_READ); perms.add(PosixFilePermission.OTHERS_WRITE); perms.add(PosixFilePermission.GROUP_READ); perms.add(PosixFilePermission.GROUP_WRITE); Files.setPosixFilePermissions(file.toPath(), perms); }
From source file:org.osate.atsv.integration.preparser.EngineConfigGenerator.java
private void setPermissions() { Set<PosixFilePermission> perms = new HashSet<>(); perms.add(PosixFilePermission.OWNER_READ); perms.add(PosixFilePermission.OWNER_WRITE); // Required to allow overwriting on subsequent runs perms.add(PosixFilePermission.OWNER_EXECUTE); java.nio.file.Path parseJarPath = FileSystems.getDefault().getPath(targetDirStr + "parser.jar"); java.nio.file.Path connectJarPath = FileSystems.getDefault().getPath(targetDirStr + "connector.jar"); java.nio.file.Path runScriptPath = FileSystems.getDefault() .getPath(targetDirStr + (SystemUtils.IS_OS_WINDOWS ? "run.bat" : "run.sh")); try {/*www .j av a2 s. c o m*/ java.nio.file.Files.setPosixFilePermissions(parseJarPath, perms); java.nio.file.Files.setPosixFilePermissions(connectJarPath, perms); java.nio.file.Files.setPosixFilePermissions(runScriptPath, perms); } catch (IOException e) { e.printStackTrace(); } }
From source file:info.pancancer.arch3.worker.WorkerRunnable.java
/** * Write the content of the job object to an INI file which will be used by the workflow. * * @param job/* w w w . j a v a2 s .c o m*/ * - the job object which must contain a HashMap, which will be used to write an INI file. * @return A Path object pointing to the new file will be returned. * @throws IOException */ private Path writeINIFile(Job job) throws IOException { log.info("INI is: " + job.getIniStr()); EnumSet<PosixFilePermission> perms = EnumSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.GROUP_READ, PosixFilePermission.GROUP_WRITE, PosixFilePermission.OTHERS_READ, PosixFilePermission.OTHERS_WRITE); FileAttribute<?> attrs = PosixFilePermissions.asFileAttribute(perms); Path pathToINI = Files.createTempFile("seqware_", ".ini", attrs); log.info("INI file: " + pathToINI.toString()); try (BufferedWriter bw = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(pathToINI.toFile()), StandardCharsets.UTF_8))) { bw.write(job.getIniStr()); bw.flush(); } return pathToINI; }
From source file:org.apache.nifi.registry.bootstrap.RunNiFiRegistry.java
private synchronized void writePidFile(final String pid, final Logger logger) throws IOException { final File pidFile = getPidFile(logger); if (pidFile.exists() && !pidFile.delete()) { logger.warn("Failed to delete {}", pidFile); }/* ww w . j a v a2 s . c o m*/ if (!pidFile.createNewFile()) { throw new IOException("Failed to create file " + pidFile); } try { final Set<PosixFilePermission> perms = new HashSet<>(); perms.add(PosixFilePermission.OWNER_WRITE); perms.add(PosixFilePermission.OWNER_READ); perms.add(PosixFilePermission.GROUP_READ); perms.add(PosixFilePermission.OTHERS_READ); Files.setPosixFilePermissions(pidFile.toPath(), perms); } catch (final Exception e) { logger.warn("Failed to set permissions so that only the owner can read pid file {}; " + "this may allows others to have access to the key needed to communicate with NiFi Registry. " + "Permissions should be changed so that only the owner can read this file", pidFile); } try (final FileOutputStream fos = new FileOutputStream(pidFile)) { fos.write(pid.getBytes(StandardCharsets.UTF_8)); fos.getFD().sync(); } logger.debug("Saved Pid {} to {}", new Object[] { pid, pidFile }); }