jdk/test/java/nio/file/Path/CheckPermissions.java
changeset 8249 c3d31a2ce7c6
parent 8248 09e47b898040
parent 8219 4a1c655bfb69
child 8250 a36beda9b9de
equal deleted inserted replaced
8248:09e47b898040 8249:c3d31a2ce7c6
     1 /*
       
     2  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 /* @test
       
    25  * @bug 6866804
       
    26  * @summary Unit test for java.nio.file.Path
       
    27  * @library ..
       
    28  * @build CheckPermissions
       
    29  * @run main/othervm CheckPermissions
       
    30  */
       
    31 
       
    32 import java.nio.ByteBuffer;
       
    33 import java.nio.file.*;
       
    34 import java.nio.file.attribute.*;
       
    35 import java.nio.channels.SeekableByteChannel;
       
    36 import java.security.Permission;
       
    37 import java.io.*;
       
    38 import java.util.*;
       
    39 
       
    40 /**
       
    41  * Checks each method that accesses the file system does the right permission
       
    42  * check when there is a security manager set.
       
    43  */
       
    44 
       
    45 public class CheckPermissions {
       
    46 
       
    47     static class Checks {
       
    48         private List<Permission> permissionsChecked = new ArrayList<Permission>();
       
    49         private Set<String>  propertiesChecked = new HashSet<String>();
       
    50         private List<String> readsChecked   = new ArrayList<String>();
       
    51         private List<String> writesChecked  = new ArrayList<String>();
       
    52         private List<String> deletesChecked = new ArrayList<String>();
       
    53         private List<String> execsChecked   = new ArrayList<String>();
       
    54 
       
    55         List<Permission> permissionsChecked()  { return permissionsChecked; }
       
    56         Set<String> propertiesChecked()        { return propertiesChecked; }
       
    57         List<String> readsChecked()            { return readsChecked; }
       
    58         List<String> writesChecked()           { return writesChecked; }
       
    59         List<String> deletesChecked()          { return deletesChecked; }
       
    60         List<String> execsChecked()            { return execsChecked; }
       
    61     }
       
    62 
       
    63     static ThreadLocal<Checks> myChecks =
       
    64         new ThreadLocal<Checks>() {
       
    65             @Override protected Checks initialValue() {
       
    66                 return null;
       
    67             }
       
    68         };
       
    69 
       
    70     static void prepare() {
       
    71         myChecks.set(new Checks());
       
    72     }
       
    73 
       
    74     static void assertCheckPermission(Class<? extends Permission> type,
       
    75                                       String name)
       
    76     {
       
    77         for (Permission perm: myChecks.get().permissionsChecked()) {
       
    78             if (type.isInstance(perm) && perm.getName().equals(name))
       
    79                 return;
       
    80         }
       
    81         throw new RuntimeException(type.getName() + "\"" + name + "\") not checked");
       
    82     }
       
    83 
       
    84     static void assertCheckPropertyAccess(String key) {
       
    85         if (!myChecks.get().propertiesChecked().contains(key))
       
    86             throw new RuntimeException("Property " + key + " not checked");
       
    87     }
       
    88 
       
    89     static void assertChecked(Path file, List<String> list) {
       
    90         String s = file.toString();
       
    91         for (String f: list) {
       
    92             if (f.endsWith(s))
       
    93                 return;
       
    94         }
       
    95         throw new RuntimeException("Access not checked");
       
    96     }
       
    97 
       
    98     static void assertCheckRead(Path file) {
       
    99         assertChecked(file, myChecks.get().readsChecked());
       
   100     }
       
   101 
       
   102     static void assertCheckWrite(Path file) {
       
   103         assertChecked(file, myChecks.get().writesChecked());
       
   104     }
       
   105 
       
   106     static void assertCheckDelete(Path file) {
       
   107         assertChecked(file, myChecks.get().deletesChecked());
       
   108     }
       
   109 
       
   110     static void assertCheckExec(Path file) {
       
   111         assertChecked(file, myChecks.get().execsChecked());
       
   112     }
       
   113 
       
   114     static class LoggingSecurityManager extends SecurityManager {
       
   115         static void install() {
       
   116             System.setSecurityManager(new LoggingSecurityManager());
       
   117         }
       
   118 
       
   119         @Override
       
   120         public void checkPermission(Permission perm) {
       
   121             Checks checks = myChecks.get();
       
   122             if (checks != null)
       
   123                 checks.permissionsChecked().add(perm);
       
   124         }
       
   125 
       
   126         @Override
       
   127         public void checkPropertyAccess(String key) {
       
   128             Checks checks = myChecks.get();
       
   129             if (checks != null)
       
   130                 checks.propertiesChecked().add(key);
       
   131         }
       
   132 
       
   133         @Override
       
   134         public void checkRead(String file) {
       
   135             Checks checks = myChecks.get();
       
   136             if (checks != null)
       
   137                 checks.readsChecked().add(file);
       
   138         }
       
   139 
       
   140         @Override
       
   141         public void checkWrite(String file) {
       
   142             Checks checks = myChecks.get();
       
   143             if (checks != null)
       
   144                 checks.writesChecked().add(file);
       
   145         }
       
   146 
       
   147         @Override
       
   148         public void checkDelete(String file) {
       
   149             Checks checks = myChecks.get();
       
   150             if (checks != null)
       
   151                 checks.deletesChecked().add(file);
       
   152         }
       
   153 
       
   154         @Override
       
   155         public void checkExec(String file) {
       
   156             Checks checks = myChecks.get();
       
   157             if (checks != null)
       
   158                 checks.execsChecked().add(file);
       
   159         }
       
   160     }
       
   161 
       
   162     static void testBasicFileAttributeView(BasicFileAttributeView view, Path file)
       
   163         throws IOException
       
   164     {
       
   165         prepare();
       
   166         view.readAttributes();
       
   167         assertCheckRead(file);
       
   168 
       
   169         prepare();
       
   170         FileTime now = FileTime.fromMillis(System.currentTimeMillis());
       
   171         view.setTimes(null, now, now);
       
   172         assertCheckWrite(file);
       
   173     }
       
   174 
       
   175     static void testPosixFileAttributeView(PosixFileAttributeView view, Path file)
       
   176         throws IOException
       
   177     {
       
   178         prepare();
       
   179         PosixFileAttributes attrs = view.readAttributes();
       
   180         assertCheckRead(file);
       
   181         assertCheckPermission(RuntimePermission.class, "accessUserInformation");
       
   182 
       
   183         prepare();
       
   184         view.setPermissions(attrs.permissions());
       
   185         assertCheckWrite(file);
       
   186         assertCheckPermission(RuntimePermission.class, "accessUserInformation");
       
   187 
       
   188         prepare();
       
   189         view.setOwner(attrs.owner());
       
   190         assertCheckWrite(file);
       
   191         assertCheckPermission(RuntimePermission.class, "accessUserInformation");
       
   192 
       
   193         prepare();
       
   194         view.setOwner(attrs.owner());
       
   195         assertCheckWrite(file);
       
   196         assertCheckPermission(RuntimePermission.class, "accessUserInformation");
       
   197     }
       
   198 
       
   199     public static void main(String[] args) throws IOException {
       
   200         Path dir = Paths.get(System.getProperty("test.dir", "."));
       
   201         Path file = dir.resolve("file1234").createFile();
       
   202         try {
       
   203             LoggingSecurityManager.install();
       
   204 
       
   205             // -- checkAccess --
       
   206 
       
   207             prepare();
       
   208             file.checkAccess();
       
   209             assertCheckRead(file);
       
   210 
       
   211             prepare();
       
   212             file.checkAccess(AccessMode.READ);
       
   213             assertCheckRead(file);
       
   214 
       
   215             prepare();
       
   216             file.checkAccess(AccessMode.WRITE);
       
   217             assertCheckWrite(file);
       
   218 
       
   219             prepare();
       
   220             try {
       
   221                 file.checkAccess(AccessMode.EXECUTE);
       
   222             } catch (AccessDeniedException x) { }
       
   223             assertCheckExec(file);
       
   224 
       
   225             prepare();
       
   226             try {
       
   227                 file.checkAccess(AccessMode.READ, AccessMode.WRITE, AccessMode.EXECUTE);
       
   228             } catch (AccessDeniedException x) { }
       
   229             assertCheckRead(file);
       
   230             assertCheckWrite(file);
       
   231             assertCheckExec(file);
       
   232 
       
   233             // -- copyTo --
       
   234 
       
   235             Path target = dir.resolve("target1234");
       
   236             prepare();
       
   237             file.copyTo(target);
       
   238             try {
       
   239                 assertCheckRead(file);
       
   240                 assertCheckWrite(target);
       
   241             } finally {
       
   242                 target.delete();
       
   243             }
       
   244 
       
   245             if (TestUtil.supportsLinks(dir)) {
       
   246                 Path link = dir.resolve("link1234").createSymbolicLink(file);
       
   247                 try {
       
   248                     prepare();
       
   249                     link.copyTo(target, LinkOption.NOFOLLOW_LINKS);
       
   250                     try {
       
   251                         assertCheckRead(link);
       
   252                         assertCheckWrite(target);
       
   253                         assertCheckPermission(LinkPermission.class, "symbolic");
       
   254                     } finally {
       
   255                         target.delete();
       
   256                     }
       
   257                 } finally {
       
   258                     link.delete();
       
   259                 }
       
   260             }
       
   261 
       
   262             // -- createDirectory --
       
   263 
       
   264             Path subdir = dir.resolve("subdir1234");
       
   265             prepare();
       
   266             subdir.createDirectory();
       
   267             try {
       
   268                 assertCheckWrite(subdir);
       
   269             } finally {
       
   270                 subdir.delete();
       
   271             }
       
   272 
       
   273             // -- createFile --
       
   274 
       
   275             Path fileToCreate = dir.resolve("file7890");
       
   276             prepare();
       
   277             try {
       
   278                 fileToCreate.createFile();
       
   279                 assertCheckWrite(fileToCreate);
       
   280             } finally {
       
   281                 fileToCreate.delete();
       
   282             }
       
   283 
       
   284             // -- createSymbolicLink --
       
   285 
       
   286             if (TestUtil.supportsLinks(dir)) {
       
   287                 prepare();
       
   288                 Path link = dir.resolve("link1234").createSymbolicLink(file);
       
   289                 try {
       
   290                     assertCheckWrite(link);
       
   291                     assertCheckPermission(LinkPermission.class, "symbolic");
       
   292                 } finally {
       
   293                     link.delete();
       
   294                 }
       
   295             }
       
   296 
       
   297             // -- delete/deleteIfExists --
       
   298 
       
   299             Path fileToDelete = dir.resolve("file7890");
       
   300 
       
   301             fileToDelete.createFile();
       
   302             prepare();
       
   303             fileToDelete.delete();
       
   304             assertCheckDelete(fileToDelete);
       
   305 
       
   306             fileToDelete.createFile();
       
   307             prepare();
       
   308             fileToDelete.deleteIfExists();
       
   309             assertCheckDelete(fileToDelete);
       
   310 
       
   311             // -- exists/notExists --
       
   312 
       
   313             prepare();
       
   314             file.exists();
       
   315             assertCheckRead(file);
       
   316 
       
   317             prepare();
       
   318             file.notExists();
       
   319             assertCheckRead(file);
       
   320 
       
   321             // -- getFileStore --
       
   322 
       
   323             prepare();
       
   324             file.getFileStore();
       
   325             assertCheckRead(file);
       
   326             assertCheckPermission(RuntimePermission.class, "getFileStoreAttributes");
       
   327 
       
   328             // -- isSameFile --
       
   329 
       
   330             prepare();
       
   331             file.isSameFile(dir);
       
   332             assertCheckRead(file);
       
   333             assertCheckRead(dir);
       
   334 
       
   335             // -- moveTo --
       
   336 
       
   337             Path target2 = dir.resolve("target1234");
       
   338             prepare();
       
   339             file.moveTo(target2);
       
   340             try {
       
   341                 assertCheckWrite(file);
       
   342                 assertCheckWrite(target2);
       
   343             } finally {
       
   344                 // restore file
       
   345                 target2.moveTo(file);
       
   346             }
       
   347 
       
   348             // -- newByteChannel --
       
   349 
       
   350             SeekableByteChannel sbc;
       
   351 
       
   352             prepare();
       
   353             sbc = file.newByteChannel();
       
   354             try {
       
   355                 assertCheckRead(file);
       
   356             } finally {
       
   357                 sbc.close();
       
   358             }
       
   359             prepare();
       
   360             sbc = file.newByteChannel(StandardOpenOption.WRITE);
       
   361             try {
       
   362                 assertCheckWrite(file);
       
   363             } finally {
       
   364                 sbc.close();
       
   365             }
       
   366             prepare();
       
   367             sbc = file.newByteChannel(StandardOpenOption.READ, StandardOpenOption.WRITE);
       
   368             try {
       
   369                 assertCheckRead(file);
       
   370                 assertCheckWrite(file);
       
   371             } finally {
       
   372                 sbc.close();
       
   373             }
       
   374 
       
   375             prepare();
       
   376             sbc = file.newByteChannel(StandardOpenOption.DELETE_ON_CLOSE);
       
   377             try {
       
   378                 assertCheckRead(file);
       
   379                 assertCheckDelete(file);
       
   380             } finally {
       
   381                 sbc.close();
       
   382             }
       
   383             file.createFile(); // restore file
       
   384 
       
   385 
       
   386             // -- newInputStream/newOutptuStream --
       
   387 
       
   388             prepare();
       
   389             InputStream in = file.newInputStream();
       
   390             try {
       
   391                 assertCheckRead(file);
       
   392             } finally {
       
   393                 in.close();
       
   394             }
       
   395             prepare();
       
   396             OutputStream out = file.newOutputStream();
       
   397             try {
       
   398                 assertCheckWrite(file);
       
   399             } finally {
       
   400                 out.close();
       
   401             }
       
   402 
       
   403             // -- newDirectoryStream --
       
   404 
       
   405             prepare();
       
   406             DirectoryStream<Path> stream = dir.newDirectoryStream();
       
   407             try {
       
   408                 assertCheckRead(dir);
       
   409 
       
   410                 if (stream instanceof SecureDirectoryStream<?>) {
       
   411                     Path entry;
       
   412                     SecureDirectoryStream<Path> sds =
       
   413                         (SecureDirectoryStream<Path>)stream;
       
   414 
       
   415                     // newByteChannel
       
   416                     entry = file.getName();
       
   417                     prepare();
       
   418                     sbc = sds.newByteChannel(entry, EnumSet.of(StandardOpenOption.READ));
       
   419                     try {
       
   420                         assertCheckRead(file);
       
   421                     } finally {
       
   422                         sbc.close();
       
   423                     }
       
   424                     prepare();
       
   425                     sbc = sds.newByteChannel(entry, EnumSet.of(StandardOpenOption.WRITE));
       
   426                     try {
       
   427                         assertCheckWrite(file);
       
   428                     } finally {
       
   429                         sbc.close();
       
   430                     }
       
   431 
       
   432                     // deleteFile
       
   433                     entry = file.getName();
       
   434                     prepare();
       
   435                     sds.deleteFile(entry);
       
   436                     assertCheckDelete(file);
       
   437                     dir.resolve(entry).createFile();  // restore file
       
   438 
       
   439                     // deleteDirectory
       
   440                     entry = Paths.get("subdir1234");
       
   441                     dir.resolve(entry).createDirectory();
       
   442                     prepare();
       
   443                     sds.deleteDirectory(entry);
       
   444                     assertCheckDelete(dir.resolve(entry));
       
   445 
       
   446                     // move
       
   447                     entry = Paths.get("tempname1234");
       
   448                     prepare();
       
   449                     sds.move(file.getName(), sds, entry);
       
   450                     assertCheckWrite(file);
       
   451                     assertCheckWrite(dir.resolve(entry));
       
   452                     sds.move(entry, sds, file.getName());  // restore file
       
   453 
       
   454                     // newDirectoryStream
       
   455                     entry = Paths.get("subdir1234");
       
   456                     dir.resolve(entry).createDirectory();
       
   457                     try {
       
   458                         prepare();
       
   459                         sds.newDirectoryStream(entry).close();
       
   460                         assertCheckRead(dir.resolve(entry));
       
   461                     } finally {
       
   462                         dir.resolve(entry).delete();
       
   463                     }
       
   464 
       
   465                     // getFileAttributeView to access attributes of directory
       
   466                     testBasicFileAttributeView(sds
       
   467                         .getFileAttributeView(BasicFileAttributeView.class), dir);
       
   468                     testPosixFileAttributeView(sds
       
   469                         .getFileAttributeView(PosixFileAttributeView.class), dir);
       
   470 
       
   471                     // getFileAttributeView to access attributes of entry
       
   472                     entry = file.getName();
       
   473                     testBasicFileAttributeView(sds
       
   474                         .getFileAttributeView(entry, BasicFileAttributeView.class), file);
       
   475                     testPosixFileAttributeView(sds
       
   476                         .getFileAttributeView(entry, PosixFileAttributeView.class), file);
       
   477 
       
   478                 } else {
       
   479                     System.out.println("SecureDirectoryStream not tested");
       
   480                 }
       
   481 
       
   482             } finally {
       
   483                 stream.close();
       
   484             }
       
   485 
       
   486             // -- toAbsolutePath --
       
   487 
       
   488             prepare();
       
   489             file.getName().toAbsolutePath();
       
   490             assertCheckPropertyAccess("user.dir");
       
   491 
       
   492             // -- toRealPath --
       
   493 
       
   494             prepare();
       
   495             file.toRealPath(true);
       
   496             assertCheckRead(file);
       
   497 
       
   498             prepare();
       
   499             file.toRealPath(false);
       
   500             assertCheckRead(file);
       
   501 
       
   502             prepare();
       
   503             Paths.get(".").toRealPath(true);
       
   504             assertCheckPropertyAccess("user.dir");
       
   505 
       
   506             prepare();
       
   507             Paths.get(".").toRealPath(false);
       
   508             assertCheckPropertyAccess("user.dir");
       
   509 
       
   510             // -- register --
       
   511 
       
   512             WatchService watcher = FileSystems.getDefault().newWatchService();
       
   513             try {
       
   514                 prepare();
       
   515                 dir.register(watcher, StandardWatchEventKind.ENTRY_DELETE);
       
   516                 assertCheckRead(dir);
       
   517             } finally {
       
   518                 watcher.close();
       
   519             }
       
   520 
       
   521             // -- getAttribute/setAttribute/readAttributes --
       
   522 
       
   523             prepare();
       
   524             file.getAttribute("size");
       
   525             assertCheckRead(file);
       
   526 
       
   527             prepare();
       
   528             file.setAttribute("lastModifiedTime",
       
   529                 FileTime.fromMillis(System.currentTimeMillis()));
       
   530             assertCheckWrite(file);
       
   531 
       
   532             prepare();
       
   533             file.readAttributes("*");
       
   534             assertCheckRead(file);
       
   535 
       
   536             // -- BasicFileAttributeView --
       
   537             testBasicFileAttributeView(file
       
   538                 .getFileAttributeView(BasicFileAttributeView.class), file);
       
   539 
       
   540             // -- PosixFileAttributeView --
       
   541 
       
   542             {
       
   543                 PosixFileAttributeView view =
       
   544                     file.getFileAttributeView(PosixFileAttributeView.class);
       
   545                 if (view != null &&
       
   546                     file.getFileStore().supportsFileAttributeView(PosixFileAttributeView.class))
       
   547                 {
       
   548                     testPosixFileAttributeView(view, file);
       
   549                 } else {
       
   550                     System.out.println("PosixFileAttributeView not tested");
       
   551                 }
       
   552             }
       
   553 
       
   554             // -- DosFileAttributeView --
       
   555 
       
   556             {
       
   557                 DosFileAttributeView view =
       
   558                     file.getFileAttributeView(DosFileAttributeView.class);
       
   559                 if (view != null &&
       
   560                     file.getFileStore().supportsFileAttributeView(DosFileAttributeView.class))
       
   561                 {
       
   562                     prepare();
       
   563                     view.readAttributes();
       
   564                     assertCheckRead(file);
       
   565 
       
   566                     prepare();
       
   567                     view.setArchive(false);
       
   568                     assertCheckWrite(file);
       
   569 
       
   570                     prepare();
       
   571                     view.setHidden(false);
       
   572                     assertCheckWrite(file);
       
   573 
       
   574                     prepare();
       
   575                     view.setReadOnly(false);
       
   576                     assertCheckWrite(file);
       
   577 
       
   578                     prepare();
       
   579                     view.setSystem(false);
       
   580                     assertCheckWrite(file);
       
   581                 } else {
       
   582                     System.out.println("DosFileAttributeView not tested");
       
   583                 }
       
   584             }
       
   585 
       
   586             // -- FileOwnerAttributeView --
       
   587 
       
   588             {
       
   589                 FileOwnerAttributeView view =
       
   590                     file.getFileAttributeView(FileOwnerAttributeView.class);
       
   591                 if (view != null &&
       
   592                     file.getFileStore().supportsFileAttributeView(FileOwnerAttributeView.class))
       
   593                 {
       
   594                     prepare();
       
   595                     UserPrincipal owner = view.getOwner();
       
   596                     assertCheckRead(file);
       
   597                     assertCheckPermission(RuntimePermission.class, "accessUserInformation");
       
   598 
       
   599                     prepare();
       
   600                     view.setOwner(owner);
       
   601                     assertCheckWrite(file);
       
   602                     assertCheckPermission(RuntimePermission.class, "accessUserInformation");
       
   603 
       
   604                 } else {
       
   605                     System.out.println("FileOwnerAttributeView not tested");
       
   606                 }
       
   607             }
       
   608 
       
   609             // -- UserDefinedFileAttributeView --
       
   610 
       
   611             {
       
   612                 UserDefinedFileAttributeView view =
       
   613                     file.getFileAttributeView(UserDefinedFileAttributeView.class);
       
   614                 if (view != null &&
       
   615                     file.getFileStore().supportsFileAttributeView(UserDefinedFileAttributeView.class))
       
   616                 {
       
   617                     prepare();
       
   618                     view.write("test", ByteBuffer.wrap(new byte[100]));
       
   619                     assertCheckWrite(file);
       
   620                     assertCheckPermission(RuntimePermission.class,
       
   621                                                "accessUserDefinedAttributes");
       
   622 
       
   623                     prepare();
       
   624                     view.read("test", ByteBuffer.allocate(100));
       
   625                     assertCheckRead(file);
       
   626                     assertCheckPermission(RuntimePermission.class,
       
   627                                                "accessUserDefinedAttributes");
       
   628 
       
   629                     prepare();
       
   630                     view.size("test");
       
   631                     assertCheckRead(file);
       
   632                     assertCheckPermission(RuntimePermission.class,
       
   633                                                "accessUserDefinedAttributes");
       
   634 
       
   635                     prepare();
       
   636                     view.list();
       
   637                     assertCheckRead(file);
       
   638                     assertCheckPermission(RuntimePermission.class,
       
   639                                                "accessUserDefinedAttributes");
       
   640 
       
   641                     prepare();
       
   642                     view.delete("test");
       
   643                     assertCheckWrite(file);
       
   644                     assertCheckPermission(RuntimePermission.class,
       
   645                                                "accessUserDefinedAttributes");
       
   646                 } else {
       
   647                     System.out.println("UserDefinedFileAttributeView not tested");
       
   648                 }
       
   649             }
       
   650 
       
   651             // -- AclFileAttributeView --
       
   652             {
       
   653                 AclFileAttributeView view =
       
   654                     file.getFileAttributeView(AclFileAttributeView.class);
       
   655                 if (view != null &&
       
   656                     file.getFileStore().supportsFileAttributeView(AclFileAttributeView.class))
       
   657                 {
       
   658                     prepare();
       
   659                     List<AclEntry> acl = view.getAcl();
       
   660                     assertCheckRead(file);
       
   661                     assertCheckPermission(RuntimePermission.class, "accessUserInformation");
       
   662                     prepare();
       
   663                     view.setAcl(acl);
       
   664                     assertCheckWrite(file);
       
   665                     assertCheckPermission(RuntimePermission.class, "accessUserInformation");
       
   666                 } else {
       
   667                     System.out.println("AclFileAttributeView not tested");
       
   668                 }
       
   669             }
       
   670 
       
   671             // -- UserPrincipalLookupService
       
   672 
       
   673             UserPrincipalLookupService lookupService =
       
   674                 FileSystems.getDefault().getUserPrincipalLookupService();
       
   675             UserPrincipal owner = Attributes.getOwner(file);
       
   676 
       
   677             prepare();
       
   678             lookupService.lookupPrincipalByName(owner.getName());
       
   679             assertCheckPermission(RuntimePermission.class,
       
   680                                        "lookupUserInformation");
       
   681 
       
   682             try {
       
   683                 UserPrincipal group = Attributes.readPosixFileAttributes(file).group();
       
   684                 prepare();
       
   685                 lookupService.lookupPrincipalByGroupName(group.getName());
       
   686                 assertCheckPermission(RuntimePermission.class,
       
   687                                            "lookupUserInformation");
       
   688             } catch (UnsupportedOperationException ignore) {
       
   689                 System.out.println("lookupPrincipalByGroupName not tested");
       
   690             }
       
   691 
       
   692 
       
   693         } finally {
       
   694             file.deleteIfExists();
       
   695         }
       
   696     }
       
   697 }