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