Search in sources :

Example 6 with FileOwnerAttributeView

use of java.nio.file.attribute.FileOwnerAttributeView in project j2objc by google.

the class Files method setOwner.

/**
 * Updates the file owner.
 *
 * <p> The {@code path} parameter is associated with a file system that
 * supports {@link FileOwnerAttributeView}. This file attribute view provides
 * access to a file attribute that is the owner of the file.
 *
 * <p> <b>Usage Example:</b>
 * Suppose we want to make "joe" the owner of a file:
 * <pre>
 *     Path path = ...
 *     UserPrincipalLookupService lookupService =
 *         provider(path).getUserPrincipalLookupService();
 *     UserPrincipal joe = lookupService.lookupPrincipalByName("joe");
 *     Files.setOwner(path, joe);
 * </pre>
 *
 * @param   path
 *          The path to the file
 * @param   owner
 *          The new file owner
 *
 * @return  The path
 *
 * @throws  UnsupportedOperationException
 *          if the associated file system does not support the {@code
 *          FileOwnerAttributeView}
 * @throws  IOException
 *          if an I/O error occurs
 * @throws  SecurityException
 *          In the case of the default provider, and a security manager is
 *          installed, it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt>
 *          or its {@link SecurityManager#checkWrite(String) checkWrite}
 *          method denies write access to the file.
 *
 * @see FileSystem#getUserPrincipalLookupService
 * @see java.nio.file.attribute.UserPrincipalLookupService
 */
public static Path setOwner(Path path, UserPrincipal owner) throws IOException {
    FileOwnerAttributeView view = getFileAttributeView(path, FileOwnerAttributeView.class);
    if (view == null)
        throw new UnsupportedOperationException();
    view.setOwner(owner);
    return path;
}
Also used : FileOwnerAttributeView(java.nio.file.attribute.FileOwnerAttributeView)

Example 7 with FileOwnerAttributeView

use of java.nio.file.attribute.FileOwnerAttributeView in project OpenClinica by OpenClinica.

the class SystemController method displayOwnerShipForTomcatSubDirectories.

public ArrayList<HashMap<String, Object>> displayOwnerShipForTomcatSubDirectories(File dir) throws IOException {
    ArrayList<HashMap<String, Object>> listOfHashMaps = new ArrayList<>();
    HashMap<String, Object> hashMap = null;
    File[] files = dir.listFiles();
    for (File file : files) {
        if (file.isDirectory()) {
            hashMap = new HashMap<String, Object>();
            hashMap.put("Read Access", getReadAccess(file));
            hashMap.put("Write Access", getWriteAccess(file));
            Path path = Paths.get(file.getCanonicalPath());
            FileOwnerAttributeView ownerAttributeView = Files.getFileAttributeView(path, FileOwnerAttributeView.class);
            UserPrincipal owner = ownerAttributeView.getOwner();
            // hashMap.put("ownership", owner.getName());
            hashMap.put("Folder Name", file.getName());
            listOfHashMaps.add(hashMap);
            int dirCount = getNumberOfSubFolders(file.getCanonicalPath().toString());
            if (dirCount != 0) {
            // hashMap.put("Sub Folders", displayOwnerShipForTomcatSubDirectories(file));
            }
        }
    }
    return listOfHashMaps;
}
Also used : Path(java.nio.file.Path) FileOwnerAttributeView(java.nio.file.attribute.FileOwnerAttributeView) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) File(java.io.File) UserPrincipal(java.nio.file.attribute.UserPrincipal)

Example 8 with FileOwnerAttributeView

use of java.nio.file.attribute.FileOwnerAttributeView in project jdk8u_jdk by JetBrains.

the class Files method setOwner.

/**
     * Updates the file owner.
     *
     * <p> The {@code path} parameter is associated with a file system that
     * supports {@link FileOwnerAttributeView}. This file attribute view provides
     * access to a file attribute that is the owner of the file.
     *
     * <p> <b>Usage Example:</b>
     * Suppose we want to make "joe" the owner of a file:
     * <pre>
     *     Path path = ...
     *     UserPrincipalLookupService lookupService =
     *         provider(path).getUserPrincipalLookupService();
     *     UserPrincipal joe = lookupService.lookupPrincipalByName("joe");
     *     Files.setOwner(path, joe);
     * </pre>
     *
     * @param   path
     *          The path to the file
     * @param   owner
     *          The new file owner
     *
     * @return  The path
     *
     * @throws  UnsupportedOperationException
     *          if the associated file system does not support the {@code
     *          FileOwnerAttributeView}
     * @throws  IOException
     *          if an I/O error occurs
     * @throws  SecurityException
     *          In the case of the default provider, and a security manager is
     *          installed, it denies {@link RuntimePermission}<tt>("accessUserInformation")</tt>
     *          or its {@link SecurityManager#checkWrite(String) checkWrite}
     *          method denies write access to the file.
     *
     * @see FileSystem#getUserPrincipalLookupService
     * @see java.nio.file.attribute.UserPrincipalLookupService
     */
public static Path setOwner(Path path, UserPrincipal owner) throws IOException {
    FileOwnerAttributeView view = getFileAttributeView(path, FileOwnerAttributeView.class);
    if (view == null)
        throw new UnsupportedOperationException();
    view.setOwner(owner);
    return path;
}
Also used : FileOwnerAttributeView(java.nio.file.attribute.FileOwnerAttributeView)

Example 9 with FileOwnerAttributeView

use of java.nio.file.attribute.FileOwnerAttributeView in project processdash by dtuma.

the class WhoAmI method identifyUserFromFileIO.

private void identifyUserFromFileIO() {
    try {
        File f = File.createTempFile("whoami", ".tmp");
        Path path = Paths.get(f.getAbsolutePath());
        FileOwnerAttributeView ownerAttributeView = Files.getFileAttributeView(path, FileOwnerAttributeView.class);
        UserPrincipal owner = ownerAttributeView.getOwner();
        this.username = discardDomain(owner.getName());
        f.delete();
        logger.info("From NIO, current user is " + username);
    } catch (Throwable t) {
    // this will fail on Java 1.6. Try the next option
    }
}
Also used : Path(java.nio.file.Path) FileOwnerAttributeView(java.nio.file.attribute.FileOwnerAttributeView) File(java.io.File) UserPrincipal(java.nio.file.attribute.UserPrincipal)

Example 10 with FileOwnerAttributeView

use of java.nio.file.attribute.FileOwnerAttributeView in project Bytecoder by mirkosertic.

the class Files method setOwner.

/**
 * Updates the file owner.
 *
 * <p> The {@code path} parameter is associated with a file system that
 * supports {@link FileOwnerAttributeView}. This file attribute view provides
 * access to a file attribute that is the owner of the file.
 *
 * <p> <b>Usage Example:</b>
 * Suppose we want to make "joe" the owner of a file:
 * <pre>
 *     Path path = ...
 *     UserPrincipalLookupService lookupService =
 *         provider(path).getUserPrincipalLookupService();
 *     UserPrincipal joe = lookupService.lookupPrincipalByName("joe");
 *     Files.setOwner(path, joe);
 * </pre>
 *
 * @param   path
 *          The path to the file
 * @param   owner
 *          The new file owner
 *
 * @return  The given path
 *
 * @throws  UnsupportedOperationException
 *          if the associated file system does not support the {@code
 *          FileOwnerAttributeView}
 * @throws  IOException
 *          if an I/O error occurs
 * @throws  SecurityException
 *          In the case of the default provider, and a security manager is
 *          installed, it denies
 *          {@link RuntimePermission}{@code ("accessUserInformation")}
 *          or its {@link SecurityManager#checkWrite(String) checkWrite}
 *          method denies write access to the file.
 *
 * @see FileSystem#getUserPrincipalLookupService
 * @see java.nio.file.attribute.UserPrincipalLookupService
 */
public static Path setOwner(Path path, UserPrincipal owner) throws IOException {
    FileOwnerAttributeView view = getFileAttributeView(path, FileOwnerAttributeView.class);
    if (view == null)
        throw new UnsupportedOperationException();
    view.setOwner(owner);
    return path;
}
Also used : FileOwnerAttributeView(java.nio.file.attribute.FileOwnerAttributeView)

Aggregations

FileOwnerAttributeView (java.nio.file.attribute.FileOwnerAttributeView)11 File (java.io.File)4 Path (java.nio.file.Path)4 PosixFileAttributeView (java.nio.file.attribute.PosixFileAttributeView)4 UserPrincipal (java.nio.file.attribute.UserPrincipal)4 HashMap (java.util.HashMap)4 BasicFileAttributeView (java.nio.file.attribute.BasicFileAttributeView)3 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)3 Date (java.util.Date)3 IOException (java.io.IOException)2 FileStore (java.nio.file.FileStore)2 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1