Package java.nio.file.attribute

Examples of java.nio.file.attribute.UserPrincipal


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

        GroupPrincipal group;
        UserPrincipal principal;

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

          switch (type) {
View Full Code Here


                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) {
View Full Code Here

           
            // This is a bit gross -- we can't actually get the real Unix UID of the user or group, but some
            // code -- notably NPM -- expects that this is returned as a number. So, returned the hashed
            // value, which is the best that we can do without native code.
            if (attrs.containsKey("owner")) {
                UserPrincipal up = (UserPrincipal)attrs.get("owner");
                put("uid", this, up.hashCode());
            } else {
                put("uid", this, 0);
            }
            if (attrs.containsKey("group")) {
                GroupPrincipal gp = (GroupPrincipal)attrs.get("group");
View Full Code Here

  @SuppressWarnings("unchecked")
  @Override
  public Object get(File file, String attribute) {
    switch (attribute) {
      case "uid":
        UserPrincipal user = (UserPrincipal) file.getAttribute("owner", "owner");
        return getUniqueId(user);
      case "gid":
        GroupPrincipal group = (GroupPrincipal) file.getAttribute("posix", "group");
        return getUniqueId(group);
      case "mode":
View Full Code Here

  @Override
  public ImmutableMap<String, ?> defaultValues(Map<String, ?> userProvidedDefaults) {
    Object userProvidedOwner = userProvidedDefaults.get("owner:owner");

    UserPrincipal owner = DEFAULT_OWNER;
    if (userProvidedOwner != null) {
      if (userProvidedOwner instanceof String) {
        owner = createUserPrincipal((String) userProvidedOwner);
      } else {
        throw invalidType("owner", "owner", userProvidedOwner, String.class, UserPrincipal.class);
View Full Code Here

  }

  @Override
  public void set(File file, String view, String attribute, Object value, boolean create) {
    if (attribute.equals("owner")) {
      UserPrincipal user = checkType(view, attribute, value, UserPrincipal.class);
      // TODO(cgdecker): Do we really need to do this? Any reason not to allow any UserPrincipal?
      if (!(user instanceof UserLookupService.JimfsUserPrincipal)) {
        user = createUserPrincipal(user.getName());
      }
      file.setAttribute("owner", "owner", user);
    }
  }
View Full Code Here

  @SuppressWarnings("unchecked")
  @Override
  public ImmutableMap<String, ?> defaultValues(Map<String, ?> userProvidedDefaults) {
    Object userProvidedGroup = userProvidedDefaults.get("posix:group");

    UserPrincipal group = DEFAULT_GROUP;
    if (userProvidedGroup != null) {
      if (userProvidedGroup instanceof String) {
        group = createGroupPrincipal((String) userProvidedGroup);
      } else {
        throw new IllegalArgumentException("invalid type " + userProvidedGroup.getClass()
View Full Code Here

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

        FileTime.fromMillis(1000),
        FileTime.fromMillis(10000));

    assertThat(Files.getAttribute(foo, "lastModifiedTime")).isEqualTo(FileTime.fromMillis(100));

    UserPrincipal zero = fs.getUserPrincipalLookupService().lookupPrincipalByName("zero");
    Files.setAttribute(foo, "owner:owner", zero);

    Path bar = path("/bar");
    Files.copy(foo, bar, COPY_ATTRIBUTES);
View Full Code Here

      byte[] bytes = {0, 1, 2, 3, 4};
      Files.write(foo, bytes);
      Files.getFileAttributeView(foo, BasicFileAttributeView.class)
          .setTimes(FileTime.fromMillis(0), FileTime.fromMillis(1), FileTime.fromMillis(2));

      UserPrincipal owner = fs.getUserPrincipalLookupService().lookupPrincipalByName("foobar");
      Files.setOwner(foo, owner);

      assertThatPath(foo)
          .attribute("owner:owner").is(owner);
View Full Code Here

TOP

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

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.