use of java.nio.file.attribute.UserPrincipal in project jimfs by google.
the class JimfsUnixLikeFileSystemTest method testCopy_toDifferentFileSystem_copyAttributes.
@Test
public void testCopy_toDifferentFileSystem_copyAttributes() throws IOException {
try (FileSystem fs2 = Jimfs.newFileSystem(UNIX_CONFIGURATION)) {
Path foo = fs.getPath("/foo");
byte[] bytes = { 0, 1, 2, 3, 4 };
Files.write(foo, bytes);
Files.getFileAttributeView(foo, BasicFileAttributeView.class).setTimes(FileTime.fromMillis(0), FileTime.fromMillis(1), FileTime.fromMillis(2));
UserPrincipal owner = fs.getUserPrincipalLookupService().lookupPrincipalByName("foobar");
Files.setOwner(foo, owner);
assertThatPath(foo).attribute("owner:owner").is(owner);
Path foo2 = fs2.getPath("/foo");
Files.copy(foo, foo2, COPY_ATTRIBUTES);
assertThatPath(foo).exists();
// when copying with COPY_ATTRIBUTES to a different FileSystem, only basic attributes (that
// is, file times) can actually be copied
assertThatPath(foo2).exists().and().attribute("lastModifiedTime").is(FileTime.fromMillis(0)).and().attribute("lastAccessTime").is(FileTime.fromMillis(1)).and().attribute("creationTime").is(FileTime.fromMillis(2)).and().attribute("owner:owner").isNot(owner).and().attribute("owner:owner").isNot(fs2.getUserPrincipalLookupService().lookupPrincipalByName("foobar")).and().containsBytes(// do this last; it updates the access time
bytes);
}
}
use of java.nio.file.attribute.UserPrincipal in project jimfs by google.
the class OwnerAttributeProvider method set.
@Override
public void set(File file, String view, String attribute, Object value, boolean create) {
if (attribute.equals("owner")) {
checkNotCreate(view, attribute, create);
UserPrincipal user = checkType(view, attribute, value, UserPrincipal.class);
// TODO(cgdecker): Do we really need to do this? Any reason not to allow any UserPrincipal?
if (!(user instanceof UserLookupService.JimfsUserPrincipal)) {
user = createUserPrincipal(user.getName());
}
file.setAttribute("owner", "owner", user);
}
}
use of java.nio.file.attribute.UserPrincipal 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;
}
use of java.nio.file.attribute.UserPrincipal in project java-chassis by ServiceComb.
the class TestFortifyUtils method testIsInSecureResult.
@Test
public void testIsInSecureResult() {
Path file = new File("src/test/resources/config/test.1.properties").toPath();
new MockUp<FortifyUtils>() {
@SuppressWarnings("unused")
public boolean isInSecureDir(Path file, UserPrincipal user, int symlinkDepth) {
return false;
}
};
FortifyUtils.isInSecureResult(file);
Assert.assertNotEquals(false, FortifyUtils.isInSecureResult(file));
}
use of java.nio.file.attribute.UserPrincipal in project java-chassis by ServiceComb.
the class TestFortifyUtils method testIsInSecureDir.
@Test
public void testIsInSecureDir() {
Path file = new File("src/test/resources/config/test.1.properties").toPath();
UserPrincipal user = null;
int symlinkDepth = 5;
FortifyUtils.isInSecureDir(file, user, symlinkDepth);
Assert.assertNotEquals(false, FortifyUtils.isInSecureDir(file, user, symlinkDepth));
}
Aggregations