Search in sources :

Example 11 with UserPrincipal

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);
}
Also used : UserPrincipalLookupService(java.nio.file.attribute.UserPrincipalLookupService) GroupPrincipal(java.nio.file.attribute.GroupPrincipal) UserPrincipal(java.nio.file.attribute.UserPrincipal) Test(org.junit.Test)

Example 12 with UserPrincipal

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);
}
Also used : Path(java.nio.file.Path) BasicFileAttributeView(java.nio.file.attribute.BasicFileAttributeView) UserPrincipal(java.nio.file.attribute.UserPrincipal) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Test(org.junit.Test)

Example 13 with UserPrincipal

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);
}
Also used : UserPrincipal(java.nio.file.attribute.UserPrincipal) UserLookupService.createUserPrincipal(com.google.common.jimfs.UserLookupService.createUserPrincipal)

Example 14 with UserPrincipal

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);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) UserLookupService.createGroupPrincipal(com.google.common.jimfs.UserLookupService.createGroupPrincipal) GroupPrincipal(java.nio.file.attribute.GroupPrincipal) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) UserPrincipal(java.nio.file.attribute.UserPrincipal)

Example 15 with UserPrincipal

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;
}
Also used : Path(java.nio.file.Path) FileOwnerAttributeView(java.nio.file.attribute.FileOwnerAttributeView) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UserPrincipal(java.nio.file.attribute.UserPrincipal)

Aggregations

UserPrincipal (java.nio.file.attribute.UserPrincipal)19 Path (java.nio.file.Path)13 Test (org.junit.Test)7 File (java.io.File)6 IOException (java.io.IOException)4 GroupPrincipal (java.nio.file.attribute.GroupPrincipal)4 UserPrincipalLookupService (java.nio.file.attribute.UserPrincipalLookupService)4 ArrayList (java.util.ArrayList)4 FileOwnerAttributeView (java.nio.file.attribute.FileOwnerAttributeView)3 PosixFileAttributeView (java.nio.file.attribute.PosixFileAttributeView)3 UserLookupService.createUserPrincipal (com.google.common.jimfs.UserLookupService.createUserPrincipal)2 FileSystem (java.nio.file.FileSystem)2 AclEntry (java.nio.file.attribute.AclEntry)2 BasicFileAttributeView (java.nio.file.attribute.BasicFileAttributeView)2 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)2 HashMap (java.util.HashMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 UserLookupService.createGroupPrincipal (com.google.common.jimfs.UserLookupService.createGroupPrincipal)1 FileSystemException (io.vertx.core.file.FileSystemException)1 AclEntryFlag (java.nio.file.attribute.AclEntryFlag)1