use of java.nio.file.attribute.PosixFilePermission in project hive by apache.
the class TestPreUpgradeTool method testUpgradeExternalTableNoReadPermissionForDatabase.
@Test
public void testUpgradeExternalTableNoReadPermissionForDatabase() throws Exception {
int[][] data = { { 1, 2 }, { 3, 4 }, { 5, 6 } };
runStatementOnDriver("drop database if exists test cascade");
runStatementOnDriver("drop table if exists TExternal");
runStatementOnDriver("create database test");
runStatementOnDriver("create table test.TExternal (a int, b int) stored as orc tblproperties" + "('transactional'='false')");
// this needs major compaction
runStatementOnDriver("insert into test.TExternal" + makeValuesClause(data));
String dbDir = getWarehouseDir() + "/test.db";
File dbPath = new File(dbDir);
try {
Set<PosixFilePermission> perms = PosixFilePermissions.fromString("-w-------");
Files.setPosixFilePermissions(dbPath.toPath(), perms);
String[] args = { "-location", getTestDataDir(), "-execute" };
PreUpgradeTool.pollIntervalMs = 1;
PreUpgradeTool.hiveConf = hiveConf;
Exception expected = null;
try {
PreUpgradeTool.main(args);
} catch (Exception e) {
expected = e;
}
Assert.assertNotNull(expected);
Assert.assertTrue(expected instanceof HiveException);
Assert.assertTrue(expected.getMessage().contains("Pre-upgrade tool requires " + "read-access to databases and tables to determine if a table has to be compacted."));
} finally {
Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxrw----");
Files.setPosixFilePermissions(dbPath.toPath(), perms);
}
}
use of java.nio.file.attribute.PosixFilePermission in project SSM by Intel-bigdata.
the class InterpreterSettingManager method saveToFile.
public void saveToFile() throws IOException {
String jsonString;
synchronized (interpreterSettings) {
InterpreterInfoSaving info = new InterpreterInfoSaving();
info.interpreterBindings = interpreterBindings;
info.interpreterSettings = interpreterSettings;
info.interpreterRepositories = interpreterRepositories;
jsonString = gson.toJson(info);
}
if (!Files.exists(interpreterBindingPath)) {
Files.createFile(interpreterBindingPath);
try {
Set<PosixFilePermission> permissions = EnumSet.of(OWNER_READ, OWNER_WRITE);
Files.setPosixFilePermissions(interpreterBindingPath, permissions);
} catch (UnsupportedOperationException e) {
// File system does not support Posix file permissions (likely windows) - continue anyway.
logger.warn("unable to setPosixFilePermissions on '{}'.", interpreterBindingPath);
}
;
}
FileOutputStream fos = new FileOutputStream(interpreterBindingPath.toFile(), false);
OutputStreamWriter out = new OutputStreamWriter(fos);
out.append(jsonString);
out.close();
fos.close();
}
use of java.nio.file.attribute.PosixFilePermission in project ats-framework by Axway.
the class LocalFileSystemOperations method getPermissions.
private String getPermissions(String sourceFile) {
int ownerPermissions = 0;
int groupPermissions = 0;
int othersPermissions = 0;
try {
Path path = Paths.get(sourceFile);
PosixFileAttributes attr;
attr = Files.readAttributes(path, PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
Set<PosixFilePermission> filePermissions = attr.permissions();
if (filePermissions.contains(PosixFilePermission.OWNER_READ)) {
ownerPermissions += 4;
}
if (filePermissions.contains(PosixFilePermission.OWNER_WRITE)) {
ownerPermissions += 2;
}
if (filePermissions.contains(PosixFilePermission.OWNER_EXECUTE)) {
ownerPermissions += 1;
}
if (filePermissions.contains(PosixFilePermission.GROUP_READ)) {
groupPermissions += 4;
}
if (filePermissions.contains(PosixFilePermission.GROUP_WRITE)) {
groupPermissions += 2;
}
if (filePermissions.contains(PosixFilePermission.GROUP_EXECUTE)) {
groupPermissions += 1;
}
if (filePermissions.contains(PosixFilePermission.OTHERS_READ)) {
othersPermissions += 4;
}
if (filePermissions.contains(PosixFilePermission.OTHERS_WRITE)) {
othersPermissions += 2;
}
if (filePermissions.contains(PosixFilePermission.OTHERS_EXECUTE)) {
othersPermissions += 1;
}
} catch (IOException ioe) {
throw new FileSystemOperationException("Could not get permissions for file '" + sourceFile + "'", ioe);
}
return "0" + ownerPermissions + groupPermissions + othersPermissions;
}
use of java.nio.file.attribute.PosixFilePermission in project syncany by syncany.
the class FileLockedScenarioTest method testPermissionDeniedNotReadable.
@Test
public void testPermissionDeniedNotReadable() throws Exception {
if (EnvironmentUtil.isWindows()) {
// Not possible in windows
return;
}
// Setup
TransferSettings testConnection = TestConfigUtil.createTestLocalConnection();
TestClient clientA = new TestClient("A", testConnection);
// Run
File noReadPermissionFile = clientA.createNewFile("no-read-permission-file");
Path filePath = Paths.get(noReadPermissionFile.getAbsolutePath());
Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>();
perms.add(PosixFilePermission.OWNER_READ);
perms.add(PosixFilePermission.GROUP_READ);
perms.add(PosixFilePermission.OTHERS_READ);
Files.setPosixFilePermissions(filePath, perms);
runUpAndTestForConsistentDatabase(testConnection, clientA);
// Tear down
clientA.deleteTestData();
}
use of java.nio.file.attribute.PosixFilePermission in project jPOS by jpos.
the class SshService method checkAuthorizedKeys.
private void checkAuthorizedKeys(String s) throws IOException {
String OS = System.getProperty("os.name").toLowerCase();
if ((OS.indexOf("win") >= 0)) {
log.info("Windows Detected, ignoring file permissions check: " + OS);
return;
}
Path file = Paths.get(s);
PosixFileAttributes attrs = Files.getFileAttributeView(file, PosixFileAttributeView.class).readAttributes();
Set<PosixFilePermission> perms = attrs.permissions();
if (perms.contains(GROUP_WRITE) || perms.contains(OTHERS_WRITE) || (perms.contains(OWNER_WRITE) && !Files.isWritable(file)))
throw new IllegalArgumentException(String.format("Invalid permissions '%s' for file '%s'", PosixFilePermissions.toString(perms), s));
}
Aggregations