本文整理汇总了Java中java.nio.file.attribute.AclEntry类的典型用法代码示例。如果您正苦于以下问题:Java AclEntry类的具体用法?Java AclEntry怎么用?Java AclEntry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AclEntry类属于java.nio.file.attribute包,在下文中一共展示了AclEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeFileNonReadable
import java.nio.file.attribute.AclEntry; //导入依赖的package包/类
private static void makeFileNonReadable(String file) throws IOException {
Path filePath = Paths.get(file);
Set<String> supportedAttr = filePath.getFileSystem().supportedFileAttributeViews();
if (supportedAttr.contains("posix")) {
Files.setPosixFilePermissions(filePath, PosixFilePermissions.fromString("-w--w----"));
} else if (supportedAttr.contains("acl")) {
UserPrincipal fileOwner = Files.getOwner(filePath);
AclFileAttributeView view = Files.getFileAttributeView(filePath, AclFileAttributeView.class);
AclEntry entry = AclEntry.newBuilder()
.setType(AclEntryType.DENY)
.setPrincipal(fileOwner)
.setPermissions(AclEntryPermission.READ_DATA)
.build();
List<AclEntry> acl = view.getAcl();
acl.add(0, entry);
view.setAcl(acl);
}
}
示例2: addRestorePermissions
import java.nio.file.attribute.AclEntry; //导入依赖的package包/类
/**
* Add the proper File-System permissions to a file so that SQL Server can run a RESTORE query.
*
* @param username The username that SQL Server runs as, e.g. "NETWORK SERVICE"
* @param file The file whose permissions will be modified.
* @throws IOException
*/
public static void addRestorePermissions(String username, Path file) throws IOException
{
AclFileAttributeView aclAttr = Files.getFileAttributeView(file, AclFileAttributeView.class);
UserPrincipalLookupService currULS = file.getFileSystem().getUserPrincipalLookupService();
UserPrincipal principal = currULS.lookupPrincipalByName(username);
AclEntry.Builder builder = AclEntry.newBuilder();
builder.setPermissions(EnumSet.of(AclEntryPermission.READ_DATA,
AclEntryPermission.READ_ACL,
AclEntryPermission.READ_ATTRIBUTES,
AclEntryPermission.READ_NAMED_ATTRS,
AclEntryPermission.EXECUTE,
AclEntryPermission.SYNCHRONIZE));
builder.setPrincipal(principal);
builder.setType(AclEntryType.ALLOW);
aclAttr.setAcl(Collections.singletonList(builder.build()));
}
示例3: protectPrivateKeyFile
import java.nio.file.attribute.AclEntry; //导入依赖的package包/类
@Override
protected void protectPrivateKeyFile(File sshKey) throws ServerException {
try {
AclFileAttributeView attributes =
Files.getFileAttributeView(sshKey.toPath(), AclFileAttributeView.class);
AclEntry.Builder builder = AclEntry.newBuilder();
builder.setType(ALLOW);
String ownerName = System.getProperty(OWNER_NAME_PROPERTY);
UserPrincipal userPrincipal =
FileSystems.getDefault().getUserPrincipalLookupService().lookupPrincipalByName(ownerName);
builder.setPrincipal(userPrincipal);
builder.setPermissions(
READ_DATA, APPEND_DATA, READ_NAMED_ATTRS, READ_ATTRIBUTES, DELETE, READ_ACL, SYNCHRONIZE);
AclEntry entry = builder.build();
List<AclEntry> aclEntryList = new ArrayList<>();
aclEntryList.add(entry);
attributes.setAcl(aclEntryList);
} catch (IOException e) {
throw new ServerException("Failed to set file permissions");
}
}
示例4: getAclAttributes
import java.nio.file.attribute.AclEntry; //导入依赖的package包/类
private static List<FileAttribute<List<AclEntry>>> getAclAttributes(Path file) throws IOException {
if (Files.exists(file) && supportsFileOwnerAttributeView(file, AclFileAttributeView.class)) {
AclFileAttributeView aclView = Files.getFileAttributeView(file, AclFileAttributeView.class);
if (aclView != null) {
final List<AclEntry> entries = aclView.getAcl();
return Collections.singletonList(new FileAttribute<List<AclEntry>>() {
@Override
public List<AclEntry> value() {
return entries;
}
@Override
public String name() {
return "acl:acl";
}
});
}
}
return Collections.emptyList();
}
示例5: createConfigurationAccessACLEntry
import java.nio.file.attribute.AclEntry; //导入依赖的package包/类
private AclEntry createConfigurationAccessACLEntry(UserPrincipal user) {
AclEntry entry = AclEntry
.newBuilder()
.setType(AclEntryType.ALLOW)
.setPrincipal(user)
.setPermissions(
AclEntryPermission.WRITE_NAMED_ATTRS,
AclEntryPermission.WRITE_DATA,
AclEntryPermission.WRITE_ATTRIBUTES,
AclEntryPermission.READ_ATTRIBUTES,
AclEntryPermission.APPEND_DATA,
AclEntryPermission.READ_DATA,
AclEntryPermission.READ_NAMED_ATTRS,
AclEntryPermission.READ_ACL,
AclEntryPermission.SYNCHRONIZE,
AclEntryPermission.DELETE)
.setFlags(AclEntryFlag.FILE_INHERIT)
.build();
return entry;
}
示例6: testView
import java.nio.file.attribute.AclEntry; //导入依赖的package包/类
@Test
public void testView() throws IOException {
AclFileAttributeView view =
provider.view(
fileLookup(),
ImmutableMap.<String, FileAttributeView>of(
"owner", new OwnerAttributeProvider().view(fileLookup(), NO_INHERITED_VIEWS)));
assertNotNull(view);
assertThat(view.name()).isEqualTo("acl");
assertThat(view.getAcl()).isEqualTo(defaultAcl);
view.setAcl(ImmutableList.<AclEntry>of());
view.setOwner(FOO);
assertThat(view.getAcl()).isEqualTo(ImmutableList.<AclEntry>of());
assertThat(view.getOwner()).isEqualTo(FOO);
assertThat(file.getAttribute("acl", "acl")).isEqualTo(ImmutableList.<AclEntry>of());
}
示例7: restrictAccess
import java.nio.file.attribute.AclEntry; //导入依赖的package包/类
private void restrictAccess() throws Exception
{
UserPrincipal user = getDefaultFileOwner();
Path path = Paths.get(file);
AclFileAttributeView aclAttr = Files.getFileAttributeView(path,
AclFileAttributeView.class);
System.out.println("owner: " + aclAttr.getOwner());
UserPrincipalLookupService upls = path.getFileSystem()
.getUserPrincipalLookupService();
// UserPrincipal user = upls.lookupPrincipalByName(System
// .getProperty("user.name"));//
// aclAttr.getOwner();//upls.lookupPrincipalByName("[email protected]");//System.getProperty("user.name"));
AclEntry.Builder builder = AclEntry.newBuilder();
builder.setPermissions(EnumSet.of(AclEntryPermission.READ_DATA,
AclEntryPermission.WRITE_DATA, AclEntryPermission.APPEND_DATA,
AclEntryPermission.READ_NAMED_ATTRS,
AclEntryPermission.WRITE_NAMED_ATTRS,
AclEntryPermission.READ_ATTRIBUTES,
AclEntryPermission.WRITE_ATTRIBUTES,
AclEntryPermission.READ_ACL, AclEntryPermission.SYNCHRONIZE));
builder.setPrincipal(user);
builder.setType(AclEntryType.ALLOW);
aclAttr.setOwner(user);
aclAttr.setAcl(Collections.singletonList(builder.build()));
}
示例8: getOwnerPermissions
import java.nio.file.attribute.AclEntry; //导入依赖的package包/类
private Set<AclEntryPermission> getOwnerPermissions(Collection<AclEntry> entries, UserPrincipal owner) {
Set<AclEntryPermission> set = new HashSet<>();
for (AclEntry aclEntry : entries) {
if (aclEntry.principal().equals(owner)) {
Set<AclEntryPermission> permissions = aclEntry.permissions();
for (AclEntryPermission aclEntryPermission : permissions) {
set.add(aclEntryPermission);
}
}
}
return set;
}
示例9: defaultValues
import java.nio.file.attribute.AclEntry; //导入依赖的package包/类
@Override
public ImmutableMap<String, ?> defaultValues(Map<String, ?> userProvidedDefaults) {
Object userProvidedAcl = userProvidedDefaults.get("acl:acl");
ImmutableList<AclEntry> acl = DEFAULT_ACL;
if (userProvidedAcl != null) {
acl = toAcl(checkType("acl", "acl", userProvidedAcl, List.class));
}
return ImmutableMap.of("acl:acl", acl);
}
示例10: toAcl
import java.nio.file.attribute.AclEntry; //导入依赖的package包/类
@SuppressWarnings("unchecked") // only cast after checking each element's type
private static ImmutableList<AclEntry> toAcl(List<?> list) {
ImmutableList<?> copy = ImmutableList.copyOf(list);
for (Object obj : copy) {
if (!(obj instanceof AclEntry)) {
throw new IllegalArgumentException(
"invalid element for attribute 'acl:acl': should be List<AclEntry>, "
+ "found element of type " + obj.getClass());
}
}
return (ImmutableList<AclEntry>) copy;
}
示例11: getAclEntry
import java.nio.file.attribute.AclEntry; //导入依赖的package包/类
private AclEntry getAclEntry(UserPrincipal user, Set<AclEntryPermission> permissions) throws IOException {
return AclEntry.newBuilder().setPermissions(permissions)
.setPrincipal(user)
.setType(AclEntryType.ALLOW)
.build();
}
示例12: saveWindowsfilePermissions
import java.nio.file.attribute.AclEntry; //导入依赖的package包/类
/**
* if os is windows then posix will not be called and we need to find permission in different manner
*
* @param file local file path
*/
private void saveWindowsfilePermissions(final Path file) throws IOException {
Set<AclEntryPermission> aclEntryPermissions;
String userType;
String userDisplay;
StringBuilder permission;
final AclFileAttributeView view = Files.getFileAttributeView(file, AclFileAttributeView.class);
final List<AclEntry> aclEntries = view.getAcl();
final StringBuilder userList = new StringBuilder();
final StringBuilder userDisplayList = new StringBuilder();
final Map<String, Set<Integer>> stringSetMap = new HashMap<>();
for (final AclEntry aclEntry : aclEntries) {
/*
If a file has no Windoze dacl entries, as may happen on a network-mounted file system, there won't be a principal entry.
A principal is a combination of security provider, like NT AUTHORITY, and user name, e.g. NT AUTHORITY\Gracie.
This code is looking for the user name -- the second half of the principal. With no principal, there is no
second half of the principal.
*/
final String[] principalFields = aclEntry.principal().getName().split("\\\\");
if (principalFields.length < 2) {
continue;
}
userDisplay = principalFields[1];
Set<Integer> newSet = stringSetMap.get(userDisplay);
aclEntryPermissions = aclEntry.permissions();
if (newSet == null) {
newSet = new HashSet<>();
}
for (final AclEntryPermission aclEntryPermission : aclEntryPermissions) {
newSet.add(aclEntryPermission.ordinal());
}
stringSetMap.put(userDisplay, newSet);
}
final int setSize = stringSetMap.size();
int userCount = 1;
for (final Map.Entry<String, Set<Integer>> entry: stringSetMap.entrySet()) {
int index = 1;
final Set<Integer> ordinals = entry.getValue();
final String key = entry.getKey();
userType = key.replaceAll(" ", "").toLowerCase();
permission = new StringBuilder();
for (final int ord : ordinals) {
if (ordinals.size() == index) {
permission.append(ord);
} else {
permission.append(ord).append("-");
}
index++;
}
if (setSize == userCount) {
userDisplayList.append(key);
userList.append(userType);
} else {
userDisplayList.append(key).append("-");
userList.append(userType).append("-");
}
metadataMap.put("x-amz-meta-ds3-" + userType, permission.toString());
userCount++;
}
metadataMap.put("x-amz-meta-ds3-userList", userList.toString());
metadataMap.put("x-amz-meta-ds3-userListDisplay", userDisplayList.toString());
}
示例13: getLocalAclEntries
import java.nio.file.attribute.AclEntry; //导入依赖的package包/类
private List<AclEntry> getLocalAclEntries(ItemType type, List<AclEntry> parentAclList, List<AclEntry> childAclList)
{
List<AclEntry> aclList = new ArrayList<>();
for (AclEntry childEntry : childAclList)
{
boolean found = false;
for (AclEntry parentEntry : parentAclList)
{
if (!parentEntry.type().equals(childEntry.type())) continue;
if (!parentEntry.principal().equals(childEntry.principal())) continue;
if (!parentEntry.permissions().equals(childEntry.permissions())) continue;
if (!parentEntry.flags().equals(childEntry.flags()))
{
if (parentEntry.flags().contains(AclEntryFlag.INHERIT_ONLY))
{
found = true;
break;
}
else
{
if (type.equals(ItemType.FOLDER))
{
if (parentEntry.flags().contains(AclEntryFlag.DIRECTORY_INHERIT))
{
found = true;
break;
}
}
else
{
if (parentEntry.flags().contains(AclEntryFlag.FILE_INHERIT))
{
found = true;
break;
}
}
}
continue;
}
found = true;
break;
}
if (found) continue;
// System.out.println("CHILD: "+childEntry.toString());
/*
* System.out.println("\n\n");
* System.out.println("CHILD: "+childEntry.toString());
*
* for(AclEntry parentEntry : parentAclList){
*
* System.out.println("PARENT: "+parentEntry.toString()); }
*
* System.out.println("\n\n");
*/
aclList.add(childEntry);
}
return aclList;
}
示例14: getAcl
import java.nio.file.attribute.AclEntry; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public List<AclEntry> getAcl() throws IOException {
return (List<AclEntry>) lookupFile().getAttribute("acl", "acl");
}
示例15: setAcl
import java.nio.file.attribute.AclEntry; //导入依赖的package包/类
@Override
public void setAcl(List<AclEntry> acl) throws IOException {
checkNotNull(acl);
lookupFile().setAttribute("acl", "acl", ImmutableList.copyOf(acl));
}