當前位置: 首頁>>代碼示例>>Java>>正文


Java UserPrincipalLookupService.lookupPrincipalByName方法代碼示例

本文整理匯總了Java中java.nio.file.attribute.UserPrincipalLookupService.lookupPrincipalByName方法的典型用法代碼示例。如果您正苦於以下問題:Java UserPrincipalLookupService.lookupPrincipalByName方法的具體用法?Java UserPrincipalLookupService.lookupPrincipalByName怎麽用?Java UserPrincipalLookupService.lookupPrincipalByName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.nio.file.attribute.UserPrincipalLookupService的用法示例。


在下文中一共展示了UserPrincipalLookupService.lookupPrincipalByName方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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()));
}
 
開發者ID:kervinpierre,項目名稱:mssqlapplylogs,代碼行數:27,代碼來源:FSHelper.java

示例3: 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;
    }
}
 
開發者ID:perlundq,項目名稱:yajsync,代碼行數:14,代碼來源:UnixFileAttributeManager.java

示例4: 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);
    }
}
 
開發者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: 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());
}
 
開發者ID:damiencarol,項目名稱:jsr203-hadoop,代碼行數:9,代碼來源:HadoopFileOwnerAttributeView.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


注:本文中的java.nio.file.attribute.UserPrincipalLookupService.lookupPrincipalByName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。