Example usage for java.nio.file.attribute PosixFilePermission OTHERS_READ

List of usage examples for java.nio.file.attribute PosixFilePermission OTHERS_READ

Introduction

In this page you can find the example usage for java.nio.file.attribute PosixFilePermission OTHERS_READ.

Prototype

PosixFilePermission OTHERS_READ

To view the source code for java.nio.file.attribute PosixFilePermission OTHERS_READ.

Click Source Link

Document

Read permission, others.

Usage

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.artifactory.security.crypto.CryptoHelper.java

public static void checkPermissionsOnSecurityFolder(File securityFolder) throws IOException {
    if (FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) {
        Set<PosixFilePermission> filePermissions = Files.getPosixFilePermissions(securityFolder.toPath());
        if (filePermissions.contains(PosixFilePermission.GROUP_READ)
                || filePermissions.contains(PosixFilePermission.OTHERS_READ)) {
            throw new RuntimeException("The folder containing the key file " + securityFolder.getAbsolutePath()
                    + " has too broad permissions!\n" + "Please limit access to the Artifactory user only!");
        }/*  w  w  w. j  a v  a  2  s  .  c o  m*/
    }
}

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.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 w w .java  2s .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);
    }//from  ww w.  ja va 2 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 });
}

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  .ja  va 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   w  w  w .j  ava2 s . com*/

    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()));
}