use of java.nio.file.attribute.UserPrincipal in project jimfs by google.
the class UserLookupServiceTest method testUserLookupService.
@Test
public void testUserLookupService() throws IOException {
UserPrincipalLookupService service = new UserLookupService(true);
UserPrincipal bob1 = service.lookupPrincipalByName("bob");
UserPrincipal bob2 = service.lookupPrincipalByName("bob");
UserPrincipal alice = service.lookupPrincipalByName("alice");
assertThat(bob1).isEqualTo(bob2);
assertThat(bob1).isNotEqualTo(alice);
GroupPrincipal group1 = service.lookupPrincipalByGroupName("group");
GroupPrincipal group2 = service.lookupPrincipalByGroupName("group");
GroupPrincipal foo = service.lookupPrincipalByGroupName("foo");
assertThat(group1).isEqualTo(group2);
assertThat(group1).isNotEqualTo(foo);
}
use of java.nio.file.attribute.UserPrincipal in project jimfs by google.
the class JimfsUnixLikeFileSystemTest method testCopy_withCopyAttributes.
@Test
public void testCopy_withCopyAttributes() throws IOException {
Path foo = path("/foo");
Files.createFile(foo);
Files.getFileAttributeView(foo, BasicFileAttributeView.class).setTimes(FileTime.fromMillis(100), FileTime.fromMillis(1000), FileTime.fromMillis(10000));
assertThat(Files.getAttribute(foo, "lastModifiedTime")).isEqualTo(FileTime.fromMillis(100));
UserPrincipal zero = fs.getUserPrincipalLookupService().lookupPrincipalByName("zero");
Files.setAttribute(foo, "owner:owner", zero);
Path bar = path("/bar");
Files.copy(foo, bar, COPY_ATTRIBUTES);
BasicFileAttributes attributes = Files.readAttributes(bar, BasicFileAttributes.class);
assertThat(attributes.lastModifiedTime()).isEqualTo(FileTime.fromMillis(100));
assertThat(attributes.lastAccessTime()).isEqualTo(FileTime.fromMillis(1000));
assertThat(attributes.creationTime()).isEqualTo(FileTime.fromMillis(10000));
assertThat(Files.getAttribute(bar, "owner:owner")).isEqualTo(zero);
Path baz = path("/baz");
Files.copy(foo, baz);
// test that attributes are not copied when COPY_ATTRIBUTES is not specified
attributes = Files.readAttributes(baz, BasicFileAttributes.class);
assertThat(attributes.lastModifiedTime()).isNotEqualTo(FileTime.fromMillis(100));
assertThat(attributes.lastAccessTime()).isNotEqualTo(FileTime.fromMillis(1000));
assertThat(attributes.creationTime()).isNotEqualTo(FileTime.fromMillis(10000));
assertThat(Files.getAttribute(baz, "owner:owner")).isNotEqualTo(zero);
}
use of java.nio.file.attribute.UserPrincipal in project jimfs by google.
the class OwnerAttributeProvider method defaultValues.
@Override
public ImmutableMap<String, ?> defaultValues(Map<String, ?> userProvidedDefaults) {
Object userProvidedOwner = userProvidedDefaults.get("owner:owner");
UserPrincipal owner = DEFAULT_OWNER;
if (userProvidedOwner != null) {
if (userProvidedOwner instanceof String) {
owner = createUserPrincipal((String) userProvidedOwner);
} else {
throw invalidType("owner", "owner", userProvidedOwner, String.class, UserPrincipal.class);
}
}
return ImmutableMap.of("owner:owner", owner);
}
use of java.nio.file.attribute.UserPrincipal in project jimfs by google.
the class PosixAttributeProvider method defaultValues.
@SuppressWarnings("unchecked")
@Override
public ImmutableMap<String, ?> defaultValues(Map<String, ?> userProvidedDefaults) {
Object userProvidedGroup = userProvidedDefaults.get("posix:group");
UserPrincipal group = DEFAULT_GROUP;
if (userProvidedGroup != null) {
if (userProvidedGroup instanceof String) {
group = createGroupPrincipal((String) userProvidedGroup);
} else {
throw new IllegalArgumentException("invalid type " + userProvidedGroup.getClass().getName() + " for attribute 'posix:group': should be one of " + String.class + " or " + GroupPrincipal.class);
}
}
Object userProvidedPermissions = userProvidedDefaults.get("posix:permissions");
Set<PosixFilePermission> permissions = DEFAULT_PERMISSIONS;
if (userProvidedPermissions != null) {
if (userProvidedPermissions instanceof String) {
permissions = Sets.immutableEnumSet(PosixFilePermissions.fromString((String) userProvidedPermissions));
} else if (userProvidedPermissions instanceof Set) {
permissions = toPermissions((Set<?>) userProvidedPermissions);
} else {
throw new IllegalArgumentException("invalid type " + userProvidedPermissions.getClass().getName() + " for attribute 'posix:permissions': should be one of " + String.class + " or " + Set.class);
}
}
return ImmutableMap.of("posix:group", group, "posix:permissions", permissions);
}
use of java.nio.file.attribute.UserPrincipal in project OpenClinica by OpenClinica.
the class SystemController method displayOwnerShipForTomcatDirectory.
public ArrayList<HashMap<String, Object>> displayOwnerShipForTomcatDirectory(File file) throws IOException {
ArrayList<HashMap<String, Object>> listOfHashMaps = new ArrayList<>();
HashMap<String, Object> hashMap = null;
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;
}
Aggregations