本文整理匯總了Java中java.nio.file.attribute.UserPrincipal類的典型用法代碼示例。如果您正苦於以下問題:Java UserPrincipal類的具體用法?Java UserPrincipal怎麽用?Java UserPrincipal使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
UserPrincipal類屬於java.nio.file.attribute包,在下文中一共展示了UserPrincipal類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testUserLookupService
import java.nio.file.attribute.UserPrincipal; //導入依賴的package包/類
@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);
}
示例2: makeFileNonReadable
import java.nio.file.attribute.UserPrincipal; //導入依賴的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);
}
}
示例3: checkAccessAllowed
import java.nio.file.attribute.UserPrincipal; //導入依賴的package包/類
@Override
public boolean checkAccessAllowed(CloudPath path, UserPrincipal userOrGroup,
Set<AclEntryPermission> checkPermissions) {
// Get the view for the path
CloudFileAttributesView cloudFileAttributeView = Files.getFileAttributeView(path, CloudFileAttributesView.class);
if (cloudFileAttributeView == null) {
LOG.warn("Could not get {} attribute view from path {}", CloudFileAttributesView.class, path);
return false;
}
CloudAclFileAttributes aclFileAttributes;
try {
aclFileAttributes = cloudFileAttributeView.readAttributes();
} catch (IOException e) {
LOG.warn("Could not read ACL file attributes for {}", path);
return false;
}
return checkAccessAllowed(aclFileAttributes.getAclSet(), userOrGroup, checkPermissions);
}
開發者ID:brdara,項目名稱:java-cloud-filesystem-provider,代碼行數:22,代碼來源:DefaultAclCheckingSecurityManager.java
示例4: hasNextInternal
import java.nio.file.attribute.UserPrincipal; //導入依賴的package包/類
boolean hasNextInternal(boolean advance) {
while (advance && (hasNext = currentIterator.hasNext())) {
nextEntry = currentIterator.next();
// When no principal class then iterate across the whole set
if (principalClass == null) {
return hasNext;
}
// GroupPrincipal inherits from UserPrincipal so we would like to constrain the
// Class.isAssignableFrom call when we are looking for UserPrincipal to exclude GroupPrincipal
boolean lookingForUserPrincipal = UserPrincipal.class.isAssignableFrom(principalClass) &&
!GroupPrincipal.class.isAssignableFrom(principalClass);
// Check if this is the class type we are looking for
if (principalClass.isAssignableFrom(nextEntry.getPrincipalClass()) &&
(!lookingForUserPrincipal || !GroupPrincipal.class.isAssignableFrom(nextEntry.getPrincipalClass()))) {
return hasNext;
}
}
return hasNext;
}
示例5: hasPermissions
import java.nio.file.attribute.UserPrincipal; //導入依賴的package包/類
boolean hasPermissions(EnumSet<AclEntryPermission> permissions) {
CloudHostConfiguration cloudHostConfiguration = cloudPath.getFileSystem().getCloudHostConfiguration();
CloudHostSecurityManager cloudHostSecurityManager = cloudHostConfiguration.getCloudHostSecurityManager();
UserGroupLookupService<?> userPrincipalLookupService =
cloudHostConfiguration.getUserGroupLookupService();
if (cloudHostSecurityManager == null) {
// No security manager, allow access
LOG.debug("No {} found in cloud host configuration {}, default action is to allow all access",
CloudHostSecurityManager.class, cloudHostConfiguration);
return true;
}
UserPrincipal currentUser = null; // Anonymous
if (userPrincipalLookupService != null) {
currentUser = userPrincipalLookupService.getCurrentUser();
} else {
LOG.debug("Cannot find current user, no {} in cloud host configuration {}",
UserGroupLookupService.class, cloudHostConfiguration);
currentUser = AnonymousUserPrincipal.INSTANCE;
}
return cloudHostSecurityManager.checkAccessAllowed(cloudPath, currentUser, permissions);
}
示例6: testDoesUserHaveAccessFailsForAUserWithAnAnonymousGroupAllowRuleButAnonymousUserDenyRule
import java.nio.file.attribute.UserPrincipal; //導入依賴的package包/類
@Test
public void testDoesUserHaveAccessFailsForAUserWithAnAnonymousGroupAllowRuleButAnonymousUserDenyRule() {
UserPrincipal user = new TestUserImpl("user1");
CloudAclEntry<GroupPrincipal> entry1 = new CloudAclEntryBuilder<GroupPrincipal>(GroupPrincipal.class)
.addPermission(AclEntryPermission.ADD_FILE)
.setType(AclEntryType.ALLOW)
.setPrincipal(AnonymousGroupPrincipal.INSTANCE)
.build();
CloudAclEntry<UserPrincipal> entry2 = new CloudAclEntryBuilder<UserPrincipal>(UserPrincipal.class)
.addPermission(AclEntryPermission.ADD_FILE)
.setType(AclEntryType.DENY)
.setPrincipal(new AnonymousUserPrincipal())
.build();
CloudAclEntrySet assetPermissions = new CloudAclEntrySet(AnonymousUserPrincipal.INSTANCE, entry1, entry2);
Assert.assertFalse(mgr.doesUserHaveAccess(assetPermissions, user, null, EnumSet.of(AclEntryPermission.ADD_FILE)));
}
開發者ID:brdara,項目名稱:java-cloud-filesystem-provider,代碼行數:17,代碼來源:DefaultAclCheckingSecurityManagerTest.java
示例7: testDoesUserHaveAccessFailsForAUserGroupWithAnAllowRuleAndAUserWithADenyRule
import java.nio.file.attribute.UserPrincipal; //導入依賴的package包/類
@Test
public void testDoesUserHaveAccessFailsForAUserGroupWithAnAllowRuleAndAUserWithADenyRule() {
UserPrincipal user = new TestUserImpl("user1");
CloudAclEntry<UserPrincipal> entry1 = new CloudAclEntryBuilder<UserPrincipal>(UserPrincipal.class)
.addPermission(AclEntryPermission.ADD_FILE)
.setType(AclEntryType.DENY)
.setPrincipal(user)
.build();
GroupPrincipal group1 = new TestGroupImpl("group1");
GroupPrincipal group2 = new TestGroupImpl("group2");
Set<GroupPrincipal> userGroups = Sets.newHashSet(group1, group2);
CloudAclEntry<GroupPrincipal> entry2 = new CloudAclEntryBuilder<GroupPrincipal>(GroupPrincipal.class)
.addPermission(AclEntryPermission.ADD_FILE)
.setType(AclEntryType.ALLOW)
.setPrincipal(group2)
.build();
CloudAclEntrySet assetPermissions = new CloudAclEntrySet(AnonymousUserPrincipal.INSTANCE, entry1, entry2);
Assert.assertFalse(mgr.doesUserHaveAccess(assetPermissions, user, userGroups, EnumSet.of(AclEntryPermission.ADD_FILE)));
}
開發者ID:brdara,項目名稱:java-cloud-filesystem-provider,代碼行數:20,代碼來源:DefaultAclCheckingSecurityManagerTest.java
示例8: TestUserImpl
import java.nio.file.attribute.UserPrincipal; //導入依賴的package包/類
@Test
public void testDoesUserHaveAccessSucceedsForAUserPrincipalWithMultipleCheckPermissionsAndMultipleAssetPermissionsAllowed() {
UserPrincipal user = new TestUserImpl("user1");
CloudAclEntry<UserPrincipal> entry1 = new CloudAclEntryBuilder<UserPrincipal>(UserPrincipal.class)
.addPermissions(AclEntryPermission.ADD_FILE, AclEntryPermission.ADD_SUBDIRECTORY, AclEntryPermission.WRITE_ACL)
.setType(AclEntryType.ALLOW)
.setPrincipal(user)
.build();
CloudAclEntrySet assetPermissions = new CloudAclEntrySet(AnonymousUserPrincipal.INSTANCE, entry1);
Assert.assertTrue(mgr.doesUserHaveAccess(assetPermissions, user, null,
EnumSet.of(AclEntryPermission.ADD_FILE, AclEntryPermission.WRITE_ACL)));
Assert.assertTrue(mgr.doesUserHaveAccess(assetPermissions, user, null,
EnumSet.of(AclEntryPermission.ADD_SUBDIRECTORY, AclEntryPermission.WRITE_ACL)));
Assert.assertTrue(mgr.doesUserHaveAccess(assetPermissions, user, null,
EnumSet.of(AclEntryPermission.ADD_FILE, AclEntryPermission.ADD_SUBDIRECTORY, AclEntryPermission.WRITE_ACL)));
}
開發者ID:brdara,項目名稱:java-cloud-filesystem-provider,代碼行數:17,代碼來源:DefaultAclCheckingSecurityManagerTest.java
示例9: testIsConflictingAclWillDetermineThatAnAllowAndDenyForTheSamePermissionsForAUserConflicts
import java.nio.file.attribute.UserPrincipal; //導入依賴的package包/類
@Test
public void testIsConflictingAclWillDetermineThatAnAllowAndDenyForTheSamePermissionsForAUserConflicts() {
UserPrincipal user1 = new TestUserImpl("user1");
UserPrincipal user2 = new TestUserImpl("user1");
CloudAclEntry<UserPrincipal> cloudAclEntry1 = new CloudAclEntryBuilder<UserPrincipal>(UserPrincipal.class)
.setPrincipal(user1)
.setType(AclEntryType.DENY)
.addPermissions(AclEntryPermission.ADD_FILE, AclEntryPermission.ADD_SUBDIRECTORY)
.build();
CloudAclEntry<UserPrincipal> cloudAclEntry2 = new CloudAclEntryBuilder<UserPrincipal>(UserPrincipal.class)
.setPrincipal(user2)
.setType(AclEntryType.ALLOW)
.addPermissions(AclEntryPermission.DELETE, AclEntryPermission.ADD_SUBDIRECTORY)
.build();
Assert.assertTrue(checker.isConflictingAcl(cloudAclEntry1, cloudAclEntry2));
}
開發者ID:brdara,項目名稱:java-cloud-filesystem-provider,代碼行數:20,代碼來源:DefaultCloudAclEntryConflictCheckerTest.java
示例10: testIsConflictingAclWillDetermineThatAnAllowAndDenyForDifferentUsersDoesNotConflict
import java.nio.file.attribute.UserPrincipal; //導入依賴的package包/類
@Test
public void testIsConflictingAclWillDetermineThatAnAllowAndDenyForDifferentUsersDoesNotConflict() {
UserPrincipal user1 = new TestUserImpl("user1");
UserPrincipal user2 = new TestUserImpl("user2");
CloudAclEntry<UserPrincipal> cloudAclEntry1 = new CloudAclEntryBuilder<UserPrincipal>(UserPrincipal.class)
.setPrincipal(user1)
.setType(AclEntryType.DENY)
.addPermissions(AclEntryPermission.ADD_FILE, AclEntryPermission.ADD_SUBDIRECTORY)
.build();
CloudAclEntry<UserPrincipal> cloudAclEntry2 = new CloudAclEntryBuilder<UserPrincipal>(UserPrincipal.class)
.setPrincipal(user2)
.setType(AclEntryType.ALLOW)
.addPermissions(AclEntryPermission.DELETE, AclEntryPermission.ADD_SUBDIRECTORY)
.build();
Assert.assertFalse(checker.isConflictingAcl(cloudAclEntry1, cloudAclEntry2));
}
開發者ID:brdara,項目名稱:java-cloud-filesystem-provider,代碼行數:20,代碼來源:DefaultCloudAclEntryConflictCheckerTest.java
示例11: testIsConflictingAclWillReturnFalseForAUserNotInAGroup
import java.nio.file.attribute.UserPrincipal; //導入依賴的package包/類
@Test
public void testIsConflictingAclWillReturnFalseForAUserNotInAGroup() {
UserPrincipal user1 = new TestUserImpl("user1");
GroupPrincipal group2 = new TestGroupImpl("group1");
CloudAclEntry<UserPrincipal> cloudAclEntry1 = new CloudAclEntryBuilder<UserPrincipal>(UserPrincipal.class)
.setPrincipal(user1)
.setType(AclEntryType.DENY)
.addPermissions(AclEntryPermission.ADD_FILE, AclEntryPermission.ADD_SUBDIRECTORY)
.build();
CloudAclEntry<GroupPrincipal> cloudAclEntry2 = new CloudAclEntryBuilder<GroupPrincipal>(GroupPrincipal.class)
.setPrincipal(group2)
.setType(AclEntryType.ALLOW)
.addPermissions(AclEntryPermission.ADD_SUBDIRECTORY)
.build();
Assert.assertFalse(checker.isConflictingAcl(cloudAclEntry1, cloudAclEntry2));
}
開發者ID:brdara,項目名稱:java-cloud-filesystem-provider,代碼行數:20,代碼來源:DefaultCloudAclEntryConflictCheckerTest.java
示例12: testIsConflictingAclWillReturnFalseByDefaultForAUserInAGroupWithConflictingPermissions
import java.nio.file.attribute.UserPrincipal; //導入依賴的package包/類
@Test
public void testIsConflictingAclWillReturnFalseByDefaultForAUserInAGroupWithConflictingPermissions() {
UserPrincipal user1 = new TestUserImpl("user1");
TestGroupImpl group2 = new TestGroupImpl("group1");
group2.addMember(user1);
Assert.assertTrue(group2.isMember(user1));
CloudAclEntry<UserPrincipal> cloudAclEntry1 = new CloudAclEntryBuilder<UserPrincipal>(UserPrincipal.class)
.setPrincipal(user1)
.setType(AclEntryType.DENY)
.addPermissions(AclEntryPermission.ADD_FILE, AclEntryPermission.ADD_SUBDIRECTORY)
.build();
CloudAclEntry<GroupPrincipal> cloudAclEntry2 = new CloudAclEntryBuilder<GroupPrincipal>(GroupPrincipal.class)
.setPrincipal(group2)
.setType(AclEntryType.ALLOW)
.addPermissions(AclEntryPermission.ADD_SUBDIRECTORY)
.build();
Assert.assertFalse(checker.isConflictingAcl(cloudAclEntry1, cloudAclEntry2));
}
開發者ID:brdara,項目名稱:java-cloud-filesystem-provider,代碼行數:22,代碼來源:DefaultCloudAclEntryConflictCheckerTest.java
示例13: DefaultCloudAclEntryConflictChecker
import java.nio.file.attribute.UserPrincipal; //導入依賴的package包/類
@Test
public void testIsConflictingAclWillReturnTrueIfTheGroupMembershipCheckIsEnabledForAUserInAGroupWithConflictingPermissions() {
checker = new DefaultCloudAclEntryConflictChecker(true);
UserPrincipal user1 = new TestUserImpl("user1");
TestGroupImpl group2 = new TestGroupImpl("group1");
group2.addMember(user1);
Assert.assertTrue(group2.isMember(user1));
CloudAclEntry<UserPrincipal> cloudAclEntry1 = new CloudAclEntryBuilder<UserPrincipal>(UserPrincipal.class)
.setPrincipal(user1)
.setType(AclEntryType.DENY)
.addPermissions(AclEntryPermission.ADD_FILE, AclEntryPermission.ADD_SUBDIRECTORY)
.build();
CloudAclEntry<GroupPrincipal> cloudAclEntry2 = new CloudAclEntryBuilder<GroupPrincipal>(GroupPrincipal.class)
.setPrincipal(group2)
.setType(AclEntryType.ALLOW)
.addPermissions(AclEntryPermission.ADD_SUBDIRECTORY)
.build();
Assert.assertTrue(checker.isConflictingAcl(cloudAclEntry1, cloudAclEntry2));
}
開發者ID:brdara,項目名稱:java-cloud-filesystem-provider,代碼行數:23,代碼來源:DefaultCloudAclEntryConflictCheckerTest.java
示例14: testMergeAclForTwoAllowRulesWillMergeThePermissionsAndFlagsOfTwoAclsForTheSameUser
import java.nio.file.attribute.UserPrincipal; //導入依賴的package包/類
@Test
public void testMergeAclForTwoAllowRulesWillMergeThePermissionsAndFlagsOfTwoAclsForTheSameUser() {
CloudAclEntry<UserPrincipal> cloudAclEntry1 = new CloudAclEntryBuilder<UserPrincipal>(UserPrincipal.class)
.setPrincipal(new TestUserImpl("user1"))
.setType(AclEntryType.ALLOW)
.addPermissions(AclEntryPermission.ADD_FILE, AclEntryPermission.ADD_SUBDIRECTORY)
.addFlag(AclEntryFlag.DIRECTORY_INHERIT)
.build();
CloudAclEntry<UserPrincipal> cloudAclEntry2 = new CloudAclEntryBuilder<UserPrincipal>(UserPrincipal.class)
.setPrincipal(new TestUserImpl("user1"))
.setType(AclEntryType.ALLOW)
.addPermissions(AclEntryPermission.DELETE)
.addFlag(AclEntryFlag.FILE_INHERIT)
.build();
CloudAclEntry<?> mergedAcl = checker.mergeAcl(new ConflictingCloudAclEntry(cloudAclEntry1, cloudAclEntry2));
Assert.assertEquals("user1", ((TestUserImpl)mergedAcl.getPrincipal()).getName());
Assert.assertEquals(AclEntryType.ALLOW, mergedAcl.getType());
Assert.assertEquals(EnumSet.of(AclEntryPermission.DELETE, AclEntryPermission.ADD_FILE, AclEntryPermission.ADD_SUBDIRECTORY),
mergedAcl.getPermissions());
Assert.assertEquals(EnumSet.of(AclEntryFlag.DIRECTORY_INHERIT, AclEntryFlag.FILE_INHERIT), mergedAcl.getFlags());
}
開發者ID:brdara,項目名稱:java-cloud-filesystem-provider,代碼行數:24,代碼來源:DefaultCloudAclEntryConflictCheckerTest.java
示例15: testMergeAclForTwoDenyRulesWillMergeThePermissionsAndFlagsOfTwoAclsForTheSameUser
import java.nio.file.attribute.UserPrincipal; //導入依賴的package包/類
@Test
public void testMergeAclForTwoDenyRulesWillMergeThePermissionsAndFlagsOfTwoAclsForTheSameUser() {
CloudAclEntry<UserPrincipal> cloudAclEntry1 = new CloudAclEntryBuilder<UserPrincipal>(UserPrincipal.class)
.setPrincipal(new TestUserImpl("user1"))
.setType(AclEntryType.DENY)
.addPermissions(AclEntryPermission.ADD_FILE, AclEntryPermission.ADD_SUBDIRECTORY)
.addFlag(AclEntryFlag.DIRECTORY_INHERIT)
.build();
CloudAclEntry<UserPrincipal> cloudAclEntry2 = new CloudAclEntryBuilder<UserPrincipal>(UserPrincipal.class)
.setPrincipal(new TestUserImpl("user1"))
.setType(AclEntryType.DENY)
.addPermissions(AclEntryPermission.DELETE)
.addFlag(AclEntryFlag.FILE_INHERIT)
.build();
CloudAclEntry<?> mergedAcl = checker.mergeAcl(new ConflictingCloudAclEntry(cloudAclEntry1, cloudAclEntry2));
Assert.assertEquals("user1", ((TestUserImpl)mergedAcl.getPrincipal()).getName());
Assert.assertEquals(AclEntryType.DENY, mergedAcl.getType());
Assert.assertEquals(EnumSet.of(AclEntryPermission.DELETE, AclEntryPermission.ADD_FILE, AclEntryPermission.ADD_SUBDIRECTORY),
mergedAcl.getPermissions());
Assert.assertEquals(EnumSet.of(AclEntryFlag.DIRECTORY_INHERIT, AclEntryFlag.FILE_INHERIT), mergedAcl.getFlags());
}
開發者ID:brdara,項目名稱:java-cloud-filesystem-provider,代碼行數:24,代碼來源:DefaultCloudAclEntryConflictCheckerTest.java