< prev index next >

test/java/lang/Class/getDeclaredField/FieldSetAccessibleTest.java

Print this page


   1 /*
   2  * Copyright (c) 2014, 2016, 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  */


 363             return builder.perms;
 364         }
 365     }
 366 
 367     // Policy for the test...
 368     public static class SimplePolicy extends Policy {
 369 
 370         final Permissions permissions;
 371         final Permissions allPermissions;
 372         final ThreadLocal<AtomicBoolean> allowAll;
 373         public SimplePolicy(TestCase test, ThreadLocal<AtomicBoolean> allowAll) {
 374             this.allowAll = allowAll;
 375 
 376             // Permission needed by the tested code exercised in the test
 377             permissions = new Permissions();
 378             permissions.add(new RuntimePermission("fileSystemProvider"));
 379             permissions.add(new RuntimePermission("createClassLoader"));
 380             permissions.add(new RuntimePermission("closeClassLoader"));
 381             permissions.add(new RuntimePermission("getClassLoader"));
 382             permissions.add(new RuntimePermission("accessDeclaredMembers"));

 383             permissions.add(new ReflectPermission("suppressAccessChecks"));
 384             permissions.add(new PropertyPermission("*", "read"));
 385             permissions.add(new FilePermission("<<ALL FILES>>", "read"));
 386 
 387             // these are used for configuring the test itself...
 388             allPermissions = new Permissions();
 389             allPermissions.add(new java.security.AllPermission());
 390         }
 391 
 392         @Override
 393         public boolean implies(ProtectionDomain domain, Permission permission) {
 394             if (allowAll.get().get()) return allPermissions.implies(permission);
 395             if (permissions.implies(permission)) return true;
 396             if (permission instanceof java.lang.RuntimePermission) {
 397                 if (permission.getName().startsWith("accessClassInPackage.")) {
 398                     // add these along to the set of permission we have, when we
 399                     // discover that we need them.
 400                     permissions.add(permission);
 401                     return true;
 402                 }
   1 /*
   2  * Copyright (c) 2014, 2017, 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  */


 363             return builder.perms;
 364         }
 365     }
 366 
 367     // Policy for the test...
 368     public static class SimplePolicy extends Policy {
 369 
 370         final Permissions permissions;
 371         final Permissions allPermissions;
 372         final ThreadLocal<AtomicBoolean> allowAll;
 373         public SimplePolicy(TestCase test, ThreadLocal<AtomicBoolean> allowAll) {
 374             this.allowAll = allowAll;
 375 
 376             // Permission needed by the tested code exercised in the test
 377             permissions = new Permissions();
 378             permissions.add(new RuntimePermission("fileSystemProvider"));
 379             permissions.add(new RuntimePermission("createClassLoader"));
 380             permissions.add(new RuntimePermission("closeClassLoader"));
 381             permissions.add(new RuntimePermission("getClassLoader"));
 382             permissions.add(new RuntimePermission("accessDeclaredMembers"));
 383             permissions.add(new RuntimePermission("accessSystemModules"));
 384             permissions.add(new ReflectPermission("suppressAccessChecks"));
 385             permissions.add(new PropertyPermission("*", "read"));
 386             permissions.add(new FilePermission("<<ALL FILES>>", "read"));
 387 
 388             // these are used for configuring the test itself...
 389             allPermissions = new Permissions();
 390             allPermissions.add(new java.security.AllPermission());
 391         }
 392 
 393         @Override
 394         public boolean implies(ProtectionDomain domain, Permission permission) {
 395             if (allowAll.get().get()) return allPermissions.implies(permission);
 396             if (permissions.implies(permission)) return true;
 397             if (permission instanceof java.lang.RuntimePermission) {
 398                 if (permission.getName().startsWith("accessClassInPackage.")) {
 399                     // add these along to the set of permission we have, when we
 400                     // discover that we need them.
 401                     permissions.add(permission);
 402                     return true;
 403                 }
< prev index next >