use of java.nio.file.attribute.PosixFilePermission in project aion by aionnetwork.
the class Keystore method create.
public static String create(String password, ECKey key) {
Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxr-----");
FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute(perms);
if (!Files.exists(PATH)) {
try {
Files.createDirectory(PATH, attr);
} catch (IOException e) {
LOG.error("keystore folder create failed!");
return "";
}
}
String address = ByteUtil.toHexString(key.getAddress());
if (exist(address)) {
return ADDR_PREFIX;
} else {
byte[] content = new KeystoreFormat().toKeystore(key, password);
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
df.setTimeZone(TimeZone.getTimeZone("UTC"));
String iso_date = df.format(new Date(System.currentTimeMillis()));
String fileName = "UTC--" + iso_date + "--" + address;
try {
Path keyFile = PATH.resolve(fileName);
if (!Files.exists(keyFile))
keyFile = Files.createFile(keyFile, attr);
String path = keyFile.toString();
FileOutputStream fos = new FileOutputStream(path);
fos.write(content);
fos.close();
return StringUtils.toJsonHex(address);
} catch (IOException e) {
LOG.error("fail to create keystore");
return ADDR_PREFIX;
}
}
}
use of java.nio.file.attribute.PosixFilePermission in project packr by libgdx.
the class ArchiveUtilsTest method assertPosixPermissions.
private void assertPosixPermissions(Path path, PosixFilePermission... permissions) throws IOException {
final PosixFileAttributeView fileAttributeView = Files.getFileAttributeView(path, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
if (fileAttributeView == null) {
return;
}
Set<PosixFilePermission> permissionSet = new LinkedHashSet<>(Arrays.asList(permissions));
assertEquals(permissionSet, fileAttributeView.readAttributes().permissions(), "Permissions for path=" + path + ", don't match expected.");
}
use of java.nio.file.attribute.PosixFilePermission in project hive by apache.
the class TestPreUpgradeTool method testUpgradeExternalTableNoReadPermissionForTable.
@Test
public void testUpgradeExternalTableNoReadPermissionForTable() throws Exception {
int[][] data = { { 1, 2 }, { 3, 4 }, { 5, 6 } };
runStatementOnDriver("drop table if exists TExternal");
runStatementOnDriver("create table TExternal (a int, b int) stored as orc tblproperties('transactional'='false')");
// this needs major compaction
runStatementOnDriver("insert into TExternal" + makeValuesClause(data));
String tableDir = getWarehouseDir() + "/texternal";
File tablePath = new File(tableDir);
try {
Set<PosixFilePermission> perms = PosixFilePermissions.fromString("-w-------");
Files.setPosixFilePermissions(tablePath.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(tablePath.toPath(), perms);
}
}
use of java.nio.file.attribute.PosixFilePermission 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.PosixFilePermission in project spring-boot by spring-projects.
the class AbstractBootArchiveTests method launchScriptCanBePrepended.
@Test
void launchScriptCanBePrepended() throws IOException {
this.task.getMainClass().set("com.example.Main");
this.task.launchScript();
executeTask();
Map<String, String> properties = new HashMap<>();
properties.put("initInfoProvides", this.task.getArchiveBaseName().get());
properties.put("initInfoShortDescription", this.project.getDescription());
properties.put("initInfoDescription", this.project.getDescription());
File archiveFile = this.task.getArchiveFile().get().getAsFile();
assertThat(Files.readAllBytes(archiveFile.toPath())).startsWith(new DefaultLaunchScript(null, properties).toByteArray());
try (ZipFile zipFile = new ZipFile(archiveFile)) {
assertThat(zipFile.getEntries().hasMoreElements()).isTrue();
}
try {
Set<PosixFilePermission> permissions = Files.getPosixFilePermissions(archiveFile.toPath());
assertThat(permissions).contains(PosixFilePermission.OWNER_EXECUTE);
} catch (UnsupportedOperationException ex) {
// Windows, presumably. Continue
}
}
Aggregations