List of usage examples for java.nio.file.attribute PosixFilePermission GROUP_READ
PosixFilePermission GROUP_READ
To view the source code for java.nio.file.attribute PosixFilePermission GROUP_READ.
Click Source Link
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: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//from w ww.j av a 2 s .com * - 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); }// w ww .j ava2s . co 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 }); }
From source file:org.apache.nifi.minifi.bootstrap.RunMiNiFi.java
private synchronized void saveProperties(final Properties minifiProps, final Logger logger) throws IOException { final String pid = minifiProps.getProperty(PID_KEY); if (!StringUtils.isBlank(pid)) { writePidFile(pid, logger);/*from w w w . j a 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_WRITE); perms.add(PosixFilePermission.OWNER_READ); perms.add(PosixFilePermission.GROUP_READ); perms.add(PosixFilePermission.OTHERS_READ); 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 MiNiFi. " + "Permissions should be changed so that only the owner can read this file", statusFile); } try (final FileOutputStream fos = new FileOutputStream(statusFile)) { minifiProps.store(fos, null); fos.getFD().sync(); } logger.debug("Saved Properties {} to {}", new Object[] { minifiProps, statusFile }); }
From source file:com.facebook.buck.util.ProjectFilesystemTest.java
@Test public void testCreateReadOnlyFileSetsPermissions() throws IOException { Path path = Paths.get("hello.txt"); ImmutableSet<PosixFilePermission> permissions = ImmutableSet.<PosixFilePermission>of( PosixFilePermission.OWNER_READ, PosixFilePermission.GROUP_READ, PosixFilePermission.OTHERS_READ); filesystem.writeContentsToPath("hello world", path, PosixFilePermissions.asFileAttribute(permissions)); // The umask may restrict the actual permissions on the filesystem: // https://fburl.com/26569549 // So the best we can do is to check that the actual permissions are a // strict subset of the expected permissions. PosixFileAttributes attrs = filesystem.readAttributes(path, PosixFileAttributes.class); assertTrue(permissions.containsAll(attrs.permissions())); }
From source file:org.apache.nifi.bootstrap.RunNiFi.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); }/*from ww w. j a va2 s . co 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. " + "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 }); }
From source file:com.facebook.buck.io.filesystem.impl.DefaultProjectFilesystemTest.java
@Test public void testCreateReadOnlyFileSetsPermissions() throws IOException { Assume.assumeTrue(FileSystems.getDefault().supportedFileAttributeViews().contains("posix")); Path path = Paths.get("hello.txt"); ImmutableSet<PosixFilePermission> permissions = ImmutableSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.GROUP_READ, PosixFilePermission.OTHERS_READ); filesystem.writeContentsToPath("hello world", path, PosixFilePermissions.asFileAttribute(permissions)); // The umask may restrict the actual permissions on the filesystem: // https://fburl.com/26569549 // So the best we can do is to check that the actual permissions are a // strict subset of the expected permissions. PosixFileAttributes attrs = filesystem.readAttributes(path, PosixFileAttributes.class); assertTrue(permissions.containsAll(attrs.permissions())); }
From source file:com.virtualparadigm.packman.processor.JPackageManager.java
public static boolean autorun(File autorunDir, Map<String, String> environmentVariableMap) { logger.info("PackageManager::autorun()"); boolean status = true; if (autorunDir != null && autorunDir.isDirectory()) { File[] autorunFiles = autorunDir.listFiles(); Arrays.sort(autorunFiles); String fileExtension = null; DefaultExecutor cmdExecutor = new DefaultExecutor(); // String sqlScriptFilePath = null; // Reader sqlScriptReader = null; // Properties sqlScriptProperties = null; for (File autorunFile : autorunFiles) { if (!autorunFile.isDirectory()) { try { fileExtension = FilenameUtils.getExtension(autorunFile.getAbsolutePath()); if (fileExtension != null) { if (fileExtension.equalsIgnoreCase("bat")) { logger.info(" executing autorun batch script: " + autorunFile.getAbsolutePath()); logger.info(" executing autorun environment: " + EnvironmentUtils.toStrings(environmentVariableMap)); cmdExecutor.execute(CommandLine.parse(autorunFile.getAbsolutePath()), environmentVariableMap); } else if (fileExtension.equalsIgnoreCase("sh")) { Set<PosixFilePermission> permissionSet = new HashSet<PosixFilePermission>(); permissionSet.add(PosixFilePermission.OWNER_READ); permissionSet.add(PosixFilePermission.OWNER_WRITE); permissionSet.add(PosixFilePermission.OWNER_EXECUTE); permissionSet.add(PosixFilePermission.OTHERS_READ); permissionSet.add(PosixFilePermission.OTHERS_WRITE); permissionSet.add(PosixFilePermission.OTHERS_EXECUTE); permissionSet.add(PosixFilePermission.GROUP_READ); permissionSet.add(PosixFilePermission.GROUP_WRITE); permissionSet.add(PosixFilePermission.GROUP_EXECUTE); Files.setPosixFilePermissions(Paths.get(autorunFile.toURI()), permissionSet); logger.info(" executing autorun shell script: " + autorunFile.getAbsolutePath()); logger.info(" executing autorun environment: " + EnvironmentUtils.toStrings(environmentVariableMap)); cmdExecutor.execute(CommandLine.parse(autorunFile.getAbsolutePath()), environmentVariableMap); } else if (fileExtension.equalsIgnoreCase("sql") || fileExtension.equalsIgnoreCase("ddl")) { logger.info(" executing autorun file: " + autorunFile.getAbsolutePath()); // look for properties file named same as script file for connection properties // sqlScriptFilePath = autorunFile.getAbsolutePath(); // sqlScriptProperties = PropertyLoader.loadProperties(sqlScriptFilePath.substring(0, sqlScriptFilePath.length()-3) + "properties"); // sqlScriptReader = new FileReader(autorunFile.getAbsolutePath()); } else if (fileExtension.equalsIgnoreCase("jar")) { logger.info(" executing autorun file: " + autorunFile.getAbsolutePath()); }/*from w w w.j a v a2s .co m*/ } } catch (Exception e) { logger.error("", e); e.printStackTrace(); } } } } return status; }
From source file:org.apache.hadoop.yarn.server.security.CertificateLocalizationService.java
private void materializeInternalX509(X509SecurityMaterial material) throws IOException { writeX509ToLocalFS(material.getKeyStoreMem(), material.getKeyStoreLocation().toFile(), material.getTrustStoreMem(), material.getTrustStoreLocation().toFile(), material.getKeyStorePass(), material.getPasswdLocation().toFile()); if (service == ServiceType.NM) { Set<PosixFilePermission> materialPermissions = EnumSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.GROUP_READ, PosixFilePermission.GROUP_EXECUTE); Files.setPosixFilePermissions(material.getCertFolder(), materialPermissions); Files.setPosixFilePermissions(material.getKeyStoreLocation(), materialPermissions); Files.setPosixFilePermissions(material.getTrustStoreLocation(), materialPermissions); Files.setPosixFilePermissions(material.getPasswdLocation(), materialPermissions); }// w w w. j a v a2 s. c o m }
From source file:org.apache.hadoop.yarn.server.security.CertificateLocalizationService.java
private void materializeInternalJWT(JWTSecurityMaterial material) throws IOException { FileUtils.writeStringToFile(material.getTokenLocation().toFile(), material.getToken()); if (service == ServiceType.NM) { Set<PosixFilePermission> materialPermissions = EnumSet.of(PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.GROUP_READ, PosixFilePermission.GROUP_EXECUTE); Files.setPosixFilePermissions(material.getCertFolder(), materialPermissions); Files.setPosixFilePermissions(material.getTokenLocation(), materialPermissions); }//from w w w . ja v a 2s.co m }