Search in sources :

Example 16 with UserPrincipalLookupService

use of java.nio.file.attribute.UserPrincipalLookupService in project coprhd-controller by CoprHD.

the class KeyStoreExporterImpl method setFilePermissions.

/**
 * Sets the file permissions on the specified path. The group of the file is the
 * user's group
 *
 * @param path the path for which to set permissions
 * @param owner the owner of the specified path
 * @param group group name of the specified path
 * @param permissions the permissions to set
 */
private void setFilePermissions(Path path, String owner, String groupName, Set<PosixFilePermission> permissions) throws IOException {
    UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService();
    UserPrincipal user = lookupService.lookupPrincipalByName(owner);
    GroupPrincipal group = lookupService.lookupPrincipalByGroupName(groupName);
    PosixFileAttributeView attributeView = Files.getFileAttributeView(path, PosixFileAttributeView.class);
    attributeView.setGroup(group);
    attributeView.setOwner(user);
    Files.setPosixFilePermissions(path, permissions);
}
Also used : UserPrincipalLookupService(java.nio.file.attribute.UserPrincipalLookupService) GroupPrincipal(java.nio.file.attribute.GroupPrincipal) UserPrincipal(java.nio.file.attribute.UserPrincipal) PosixFileAttributeView(java.nio.file.attribute.PosixFileAttributeView)

Example 17 with UserPrincipalLookupService

use of java.nio.file.attribute.UserPrincipalLookupService in project coprhd-controller by CoprHD.

the class DbCheckerFileWriter method setFilePermissions.

private static void setFilePermissions(Path path, String owner, String groupName, Set<PosixFilePermission> permissions) throws IOException {
    UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService();
    UserPrincipal user = lookupService.lookupPrincipalByName(owner);
    GroupPrincipal group = lookupService.lookupPrincipalByGroupName(groupName);
    PosixFileAttributeView attributeView = Files.getFileAttributeView(path, PosixFileAttributeView.class);
    attributeView.setGroup(group);
    attributeView.setOwner(user);
    Files.setPosixFilePermissions(path, permissions);
}
Also used : UserPrincipalLookupService(java.nio.file.attribute.UserPrincipalLookupService) GroupPrincipal(java.nio.file.attribute.GroupPrincipal) UserPrincipal(java.nio.file.attribute.UserPrincipal) PosixFileAttributeView(java.nio.file.attribute.PosixFileAttributeView)

Example 18 with UserPrincipalLookupService

use of java.nio.file.attribute.UserPrincipalLookupService in project cloudconductor-agent-redhat by cinovo.

the class FileHelper method chown.

/**
 * @param localFile the local file to use chown on
 * @param owner the file owner to set
 * @param group the file group to set
 * @throws IOException if chown couldn't be edited
 */
public static void chown(File localFile, String owner, String group) throws IOException {
    PosixFileAttributeView view = FileHelper.getFileAttributes(localFile);
    UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService();
    UserPrincipal fileOwner = lookupService.lookupPrincipalByName(owner);
    GroupPrincipal fileGroup = lookupService.lookupPrincipalByGroupName(group);
    view.setOwner(fileOwner);
    view.setGroup(fileGroup);
}
Also used : UserPrincipalLookupService(java.nio.file.attribute.UserPrincipalLookupService) GroupPrincipal(java.nio.file.attribute.GroupPrincipal) UserPrincipal(java.nio.file.attribute.UserPrincipal) PosixFileAttributeView(java.nio.file.attribute.PosixFileAttributeView)

Aggregations

UserPrincipalLookupService (java.nio.file.attribute.UserPrincipalLookupService)18 PosixFileAttributeView (java.nio.file.attribute.PosixFileAttributeView)12 UserPrincipal (java.nio.file.attribute.UserPrincipal)12 GroupPrincipal (java.nio.file.attribute.GroupPrincipal)11 IOException (java.io.IOException)7 Path (java.nio.file.Path)7 FileSystem (java.nio.file.FileSystem)3 FileSystemException (io.vertx.core.file.FileSystemException)2 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)2 Test (org.junit.Test)2 AlluxioException (alluxio.exception.AlluxioException)1 Mode (alluxio.security.authorization.Mode)1 File (java.io.File)1 InvalidPathException (java.nio.file.InvalidPathException)1 UserPrincipalNotFoundException (java.nio.file.attribute.UserPrincipalNotFoundException)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 IgfsException (org.apache.ignite.igfs.IgfsException)1