当前位置: 首页>>代码示例>>Java>>正文


Java UserPrincipalLookupService.lookupPrincipalByGroupName方法代码示例

本文整理汇总了Java中java.nio.file.attribute.UserPrincipalLookupService.lookupPrincipalByGroupName方法的典型用法代码示例。如果您正苦于以下问题:Java UserPrincipalLookupService.lookupPrincipalByGroupName方法的具体用法?Java UserPrincipalLookupService.lookupPrincipalByGroupName怎么用?Java UserPrincipalLookupService.lookupPrincipalByGroupName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.file.attribute.UserPrincipalLookupService的用法示例。


在下文中一共展示了UserPrincipalLookupService.lookupPrincipalByGroupName方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
 
开发者ID:google,项目名称:jimfs,代码行数:18,代码来源:UserLookupServiceTest.java

示例2: 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) {
		}
	}

}
 
开发者ID:iotracks,项目名称:iofabric,代码行数:21,代码来源:Start.java

示例3: 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;
    }
}
 
开发者ID:perlundq,项目名称:yajsync,代码行数:14,代码来源:UnixFileAttributeManager.java

示例4: 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);
    }
}
 
开发者ID:perlundq,项目名称:yajsync,代码行数:16,代码来源:PosixFileAttributeManager.java

示例5: 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);
}
 
开发者ID:cinovo,项目名称:cloudconductor-agent-redhat,代码行数:15,代码来源:FileHelper.java

示例6: testServiceNotSupportingGroups

import java.nio.file.attribute.UserPrincipalLookupService; //导入方法依赖的package包/类
@Test
public void testServiceNotSupportingGroups() throws IOException {
  UserPrincipalLookupService service = new UserLookupService(false);

  try {
    service.lookupPrincipalByGroupName("group");
    fail();
  } catch (UserPrincipalNotFoundException expected) {
    assertThat(expected.getName()).isEqualTo("group");
  }
}
 
开发者ID:google,项目名称:jimfs,代码行数:12,代码来源:UserLookupServiceTest.java

示例7: defineFilePosixAttributeView

import java.nio.file.attribute.UserPrincipalLookupService; //导入方法依赖的package包/类
/**
 * Define file posix attribute view on a path/file.
 *
 * @param path Target path
 * @param filePermissions Permissions to apply
 * @param fileOwner File owner
 * @param fileGroup File group
 * @throws IOException If IO error during definition of file attribute view
 */
public static void defineFilePosixAttributeView(final Path path,
        final Set<PosixFilePermission> filePermissions,
        final String fileOwner,
        final String fileGroup) throws IOException {
    final PosixFileAttributeView view = Files.getFileAttributeView(path, PosixFileAttributeView.class);
    if (view != null) {
        final UserPrincipalLookupService lookupService = FileSystems.getDefault()
                .getUserPrincipalLookupService();
        if (fileOwner != null) {
            final UserPrincipal userPrincipal = lookupService.lookupPrincipalByName(fileOwner);
            if (userPrincipal != null) {
                // If not sudoers member, it will throw Operation not permitted
                // Only processes with an effective user ID equal to the user ID
                // of the file or with appropriate privileges may change the ownership of a file.
                // If _POSIX_CHOWN_RESTRICTED is in effect for path
                view.setOwner(userPrincipal);
            }
        }
        if (fileGroup != null) {
            final GroupPrincipal groupPrincipal = lookupService.lookupPrincipalByGroupName(fileGroup);
            if (groupPrincipal != null) {
                // The current user id should be members of this group,
                // if not will raise Operation not permitted
                view.setGroup(groupPrincipal);
            }
        }
        if (filePermissions != null) {
            view.setPermissions(filePermissions);
        }
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:41,代码来源:FileUtils.java

示例8: setGroup

import java.nio.file.attribute.UserPrincipalLookupService; //导入方法依赖的package包/类
@Override
public void setGroup(String group) throws IOException {
  UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService();
  GroupPrincipal groupPrincipal = lookupService.lookupPrincipalByGroupName(group);
  Files.getFileAttributeView(file.toPath(), PosixFileAttributeView.class).setGroup(groupPrincipal);
}
 
开发者ID:apache,项目名称:twill,代码行数:7,代码来源:LocalLocation.java


注:本文中的java.nio.file.attribute.UserPrincipalLookupService.lookupPrincipalByGroupName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。