本文整理匯總了Java中java.nio.file.attribute.UserPrincipalLookupService類的典型用法代碼示例。如果您正苦於以下問題:Java UserPrincipalLookupService類的具體用法?Java UserPrincipalLookupService怎麽用?Java UserPrincipalLookupService使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
UserPrincipalLookupService類屬於java.nio.file.attribute包,在下文中一共展示了UserPrincipalLookupService類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testUserLookupService
import java.nio.file.attribute.UserPrincipalLookupService; //導入依賴的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: addRestorePermissions
import java.nio.file.attribute.UserPrincipalLookupService; //導入依賴的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: setupEnvironment
import java.nio.file.attribute.UserPrincipalLookupService; //導入依賴的package包/類
/**
* creates and grants permission to daemon files directory
*/
private static void setupEnvironment() {
final File daemonFilePath = new File("/var/run/iofabric");
if (!daemonFilePath.exists()) {
try {
daemonFilePath.mkdirs();
UserPrincipalLookupService lookupservice = FileSystems.getDefault().getUserPrincipalLookupService();
final GroupPrincipal group = lookupservice.lookupPrincipalByGroupName("iofabric");
Files.getFileAttributeView(daemonFilePath.toPath(), PosixFileAttributeView.class,
LinkOption.NOFOLLOW_LINKS).setGroup(group);
Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxrwx---");
Files.setPosixFilePermissions(daemonFilePath.toPath(), perms);
} catch (Exception e) {
}
}
}
示例4: chown
import java.nio.file.attribute.UserPrincipalLookupService; //導入依賴的package包/類
@Override
public void chown(String path, String username, String groupname) throws IOException {
java.nio.file.Path p = FileSystems.getDefault().getPath(path);
PosixFileAttributeView view = Files.getFileAttributeView(p, PosixFileAttributeView.class);
UserPrincipalLookupService service = p.getFileSystem().getUserPrincipalLookupService();
if(!StringUtils.isBlank(username)) {
view.setOwner(service.lookupPrincipalByName(username));
}
if(!StringUtils.isBlank(groupname)) {
view.setGroup(service.lookupPrincipalByGroupName(groupname));
}
}
示例5: setWindowsPermissions
import java.nio.file.attribute.UserPrincipalLookupService; //導入依賴的package包/類
private void setWindowsPermissions(Path path) {
try {
AclFileAttributeView aclAttr = Files.getFileAttributeView(path, AclFileAttributeView.class);
UserPrincipalLookupService lookupService = path.getFileSystem().getUserPrincipalLookupService();
aclAttr.setAcl(Arrays.asList(
getAclEntry(lookupService.lookupPrincipalByName("SYSTEM"), Collections.emptySet()),
getAclEntry(lookupService.lookupPrincipalByName(System.getProperty("user.name")), EnumSet.allOf(AclEntryPermission.class))
));
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
示例6: restrictAccess
import java.nio.file.attribute.UserPrincipalLookupService; //導入依賴的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()));
}
示例7: testGetUserPrincipalLookupServiceWillReturnTheServiceIfNotNull
import java.nio.file.attribute.UserPrincipalLookupService; //導入依賴的package包/類
@Test
public void testGetUserPrincipalLookupServiceWillReturnTheServiceIfNotNull() {
UserPrincipalLookupService service = context.mock(UserPrincipalLookupService.class);
context.checking(new Expectations() {{
allowing(cloudHostSettings).getUserPrincipalLookupService();
will(returnValue(service));
}});
Assert.assertEquals(service, impl.getUserPrincipalLookupService());
}
示例8: change
import java.nio.file.attribute.UserPrincipalLookupService; //導入依賴的package包/類
public void change(Event e, Object[] delta, Changer.ChangeMode mode) {
if (mode == Changer.ChangeMode.SET) {
Path pth = Paths.get(skUtilities.getDefaultPath(path.getSingle(e)));
try {
UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService();
Files.setOwner(pth, lookupService.lookupPrincipalByName((String) delta[0]));
} catch (Exception x) {
skUtilities.prSysE("File: '" + pth + "' doesn't exist, or is not readable!", getClass().getSimpleName(), x);
}
}
}
示例9: getUserPrincipalFrom
import java.nio.file.attribute.UserPrincipalLookupService; //導入依賴的package包/類
private UserPrincipal getUserPrincipalFrom(String userName) throws IOException
{
try {
if (_isCacheEnabled) {
return _nameToUserPrincipal.get(userName);
}
UserPrincipalLookupService service =
FileSystems.getDefault().getUserPrincipalLookupService();
return service.lookupPrincipalByName(userName);
} catch (IOException | UnsupportedOperationException e) {
return null;
}
}
示例10: getGroupPrincipalFrom
import java.nio.file.attribute.UserPrincipalLookupService; //導入依賴的package包/類
private GroupPrincipal getGroupPrincipalFrom(String groupName) throws IOException
{
try {
if (_isCacheEnabled) {
return _nameToGroupPrincipal.get(groupName);
}
UserPrincipalLookupService service =
FileSystems.getDefault().getUserPrincipalLookupService();
return service.lookupPrincipalByGroupName(groupName);
} catch (IOException | UnsupportedOperationException e) {
return null;
}
}
示例11: getUserPrincipalFrom
import java.nio.file.attribute.UserPrincipalLookupService; //導入依賴的package包/類
private UserPrincipal getUserPrincipalFrom(String userName) throws IOException
{
try {
UserPrincipal principal = _nameToUserPrincipal.get(userName);
if (principal == null) {
UserPrincipalLookupService service =
FileSystems.getDefault().getUserPrincipalLookupService();
principal = service.lookupPrincipalByName(userName);
_nameToUserPrincipal.put(userName, principal);
}
return principal;
} catch (UnsupportedOperationException e) {
throw new IOException(e);
}
}
示例12: getGroupPrincipalFrom
import java.nio.file.attribute.UserPrincipalLookupService; //導入依賴的package包/類
private GroupPrincipal getGroupPrincipalFrom(String groupName) throws IOException
{
try {
GroupPrincipal principal = _nameToGroupPrincipal.get(groupName);
if (principal == null) {
UserPrincipalLookupService service =
FileSystems.getDefault().getUserPrincipalLookupService();
principal = service.lookupPrincipalByGroupName(groupName);
_nameToGroupPrincipal.put(groupName, principal);
}
return principal;
} catch (UnsupportedOperationException e) {
throw new IOException(e);
}
}
示例13: chown
import java.nio.file.attribute.UserPrincipalLookupService; //導入依賴的package包/類
/**
* @param localFile the local file to use chown on
* @param owner the file owner to set
* @param group the file group to set
* @throws IOException if chown couldn't be edited
*/
public static void chown(File localFile, String owner, String group) throws IOException {
PosixFileAttributeView view = FileHelper.getFileAttributes(localFile);
UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService();
UserPrincipal fileOwner = lookupService.lookupPrincipalByName(owner);
GroupPrincipal fileGroup = lookupService.lookupPrincipalByGroupName(group);
view.setOwner(fileOwner);
view.setGroup(fileGroup);
}
示例14: getOwner
import java.nio.file.attribute.UserPrincipalLookupService; //導入依賴的package包/類
@Override
public UserPrincipal getOwner() throws IOException {
UserPrincipalLookupService ls = this.path.getFileSystem()
.getUserPrincipalLookupService();
FileStatus fileStatus = path.getFileSystem().getHDFS()
.getFileStatus(path.getRawResolvedPath());
return ls.lookupPrincipalByName(fileStatus.getOwner());
}
示例15: testGetPosixViewSetOwner
import java.nio.file.attribute.UserPrincipalLookupService; //導入依賴的package包/類
/**
* Test UserPrincipalLookupService support.
*
* @throws IOException
*/
@Test
public void testGetPosixViewSetOwner() throws IOException {
Path rootPath = Paths.get(clusterUri);
UserPrincipalLookupService lus = rootPath.getFileSystem()
.getUserPrincipalLookupService();
assertNotNull(lus);
}