Package java.nio.file.attribute

Examples of java.nio.file.attribute.UserPrincipalLookupService


        }
        return p;
    }

    private GroupPrincipal toGroup(String name) throws IOException {
        UserPrincipalLookupService lookupService = file.toPath().getFileSystem().getUserPrincipalLookupService();
        return lookupService.lookupPrincipalByGroupName(name);
    }
View Full Code Here


        UserPrincipalLookupService lookupService = file.toPath().getFileSystem().getUserPrincipalLookupService();
        return lookupService.lookupPrincipalByGroupName(name);
    }

    private UserPrincipal toUser(String name) throws IOException {
        UserPrincipalLookupService lookupService = file.toPath().getFileSystem().getUserPrincipalLookupService();
        return lookupService.lookupPrincipalByName(name);
    }
View Full Code Here

        }
        return p;
    }

    private GroupPrincipal toGroup(String name) throws IOException {
        UserPrincipalLookupService lookupService = file.toPath().getFileSystem().getUserPrincipalLookupService();
        return lookupService.lookupPrincipalByGroupName(name);
    }
View Full Code Here

        UserPrincipalLookupService lookupService = file.toPath().getFileSystem().getUserPrincipalLookupService();
        return lookupService.lookupPrincipalByGroupName(name);
    }

    private UserPrincipal toUser(String name) throws IOException {
        UserPrincipalLookupService lookupService = file.toPath().getFileSystem().getUserPrincipalLookupService();
        return lookupService.lookupPrincipalByName(name);
    }
View Full Code Here

        UserPrincipalLookupService lookupService = file.toPath().getFileSystem().getUserPrincipalLookupService();
        return lookupService.lookupPrincipalByGroupName(name);
    }

    private UserPrincipal toUser(String name) throws IOException {
        UserPrincipalLookupService lookupService = file.toPath().getFileSystem().getUserPrincipalLookupService();
        return lookupService.lookupPrincipalByName(name);
    }
View Full Code Here

      throw new CloudsyncException("Can't set create, modify and access time of " + item.getTypeName() + " '" + item.getPath() + "'", e);
    }

    if (permissionType.equals(PermissionType.SET) || permissionType.equals(PermissionType.TRY)) {

      final UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService();

      Map<String, String[]> attributes = item.getAttributes();
      for (String type : attributes.keySet()) {

        GroupPrincipal group;
        UserPrincipal principal;

        try {
          String[] values = attributes.get(type);

          switch (type) {
          case Item.ATTRIBUTE_POSIX:
            PosixFileAttributeView posixView = Files.getFileAttributeView(path, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
            if (posixView != null) {
              group = lookupService.lookupPrincipalByGroupName(values[0]);
              posixView.setGroup(group);
              principal = lookupService.lookupPrincipalByName(values[1]);
              posixView.setOwner(principal);
              if (values.length > 2)
                posixView.setPermissions(toPermissions(Integer.parseInt(values[2])));
            } else {
              String msg = "Can't restore 'posix' permissions on '" + item.getPath() + "'. They are not supported.";
              if (permissionType.equals(PermissionType.TRY))
                LOGGER.log(Level.WARNING, msg);
              else
                throw new CloudsyncException(msg + "\n  try to run with '--permissions try'");
            }
            break;
          case Item.ATTRIBUTE_DOS:
            DosFileAttributeView dosView = Files.getFileAttributeView(path, DosFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
            if (dosView != null) {
              dosView.setArchive(Boolean.parseBoolean(values[0]));
              dosView.setHidden(Boolean.parseBoolean(values[1]));
              dosView.setReadOnly(Boolean.parseBoolean(values[2]));
              dosView.setSystem(Boolean.parseBoolean(values[3]));
            } else {
              String msg = "Can't restore 'dos' permissions on '" + item.getPath() + "'. They are not supported.";
              if (permissionType.equals(PermissionType.TRY))
                LOGGER.log(Level.WARNING, msg);
              else
                throw new CloudsyncException(msg + "\n  try to run with '--permissions try'");
            }
            break;
          case Item.ATTRIBUTE_ACL:
            AclFileAttributeView aclView = Files.getFileAttributeView(path, AclFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
            if (aclView != null) {
              List<AclEntry> acls = aclView.getAcl();
              for (int i = 0; i < values.length; i = i + 4) {

                Builder aclEntryBuilder = AclEntry.newBuilder();

                aclEntryBuilder.setType(AclEntryType.valueOf(values[i]));
                aclEntryBuilder.setPrincipal(lookupService.lookupPrincipalByName(values[i + 1]));

                Set<AclEntryFlag> flags = new HashSet<AclEntryFlag>();
                for (String flag : StringUtils.splitPreserveAllTokens(values[i + 2], ",")) {
                  flags.add(AclEntryFlag.valueOf(flag));
                }
                if (flags.size() > 0)
                  aclEntryBuilder.setFlags(flags);

                Set<AclEntryPermission> aclPermissions = new HashSet<AclEntryPermission>();
                for (String flag : StringUtils.splitPreserveAllTokens(values[i + 3], ",")) {
                  aclPermissions.add(AclEntryPermission.valueOf(flag));
                }
                if (aclPermissions.size() > 0)
                  aclEntryBuilder.setPermissions(aclPermissions);
                acls.add(aclEntryBuilder.build());
              }
              aclView.setAcl(acls);
            } else {
              String msg = "Can't restore 'acl' permissions on '" + item.getPath() + "'. They are not supported.";
              if (permissionType.equals(PermissionType.TRY))
                LOGGER.log(Level.WARNING, msg);
              else
                throw new CloudsyncException(msg + "\n  try to run with '--permissions try'");
            }
            break;
          case Item.ATTRIBUTE_OWNER:
            FileOwnerAttributeView ownerView = Files.getFileAttributeView(path, FileOwnerAttributeView.class, LinkOption.NOFOLLOW_LINKS);
            if (ownerView != null) {
              principal = lookupService.lookupPrincipalByName(values[0]);
              ownerView.setOwner(principal);
            } else {
              String msg = "Can't restore 'owner' permissions on '" + item.getPath() + "'. They are not supported.";
              if (permissionType.equals(PermissionType.TRY))
                LOGGER.log(Level.WARNING, msg);
View Full Code Here

        {
            if (log.isDebugEnabled()) {
                log.debug("chown({}) to {}:{}", path, uid, gid);
            }

            UserPrincipalLookupService lookupService =
                FileSystems.getDefault().getUserPrincipalLookupService();

            // In Java, we can't actually get the unix UID, so we take a username here, rather
            // than a UID. That may cause problems for NPM, which may try to use a UID.
            try {
                UserPrincipal user = lookupService.lookupPrincipalByName(uid);
               
                if (Platform.get().isPosixFilesystem()) {
                    GroupPrincipal group = lookupService.lookupPrincipalByGroupName(gid);
   
                    if (noFollow) {
                        Files.setAttribute(path, "posix:owner", user, LinkOption.NOFOLLOW_LINKS);
                        Files.setAttribute(path, "posix:group", group, LinkOption.NOFOLLOW_LINKS);
                    } else {
View Full Code Here

@RunWith(JUnit4.class)
public class UserLookupServiceTest {

  @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);
  }
View Full Code Here

    assertThat(group1).isNotEqualTo(foo);
  }

  @Test
  public void testServiceNotSupportingGroups() throws IOException {
    UserPrincipalLookupService service = new UserLookupService(false);

    try {
      service.lookupPrincipalByGroupName("group");
      fail();
    } catch (UserPrincipalNotFoundException expected) {
      assertThat(expected.getName()).isEqualTo("group");
    }
  }
View Full Code Here

    };
  }

  protected BlockingAction<Void> chownInternal(String path, final String user, final String group, Handler<AsyncResult<Void>> handler) {
    Path target = vertx.resolveFile(path).toPath();
    UserPrincipalLookupService service = target.getFileSystem().getUserPrincipalLookupService();
    return new BlockingAction<Void>(handler) {
      public Void perform() {

        try {
          final UserPrincipal userPrincipal = user == null ? null : service.lookupPrincipalByName(user);
          final GroupPrincipal groupPrincipal = group == null ? null : service.lookupPrincipalByGroupName(group);
          if (groupPrincipal != null) {
            PosixFileAttributeView view = Files.getFileAttributeView(target, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
            if (view == null) {
              throw new FileSystemException("Change group of file not supported");
            }
View Full Code Here

TOP

Related Classes of java.nio.file.attribute.UserPrincipalLookupService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.