test/jdk/java/security/AccessController/LimitedDoPrivileged.java
author prr
Fri, 25 May 2018 12:12:24 -0700
changeset 50347 b2f046ae8eb6
parent 47216 71c04702a3d5
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17946
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
     1
/*
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
     4
 *
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
     8
 *
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    13
 * accompanied this code).
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    14
 *
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    18
 *
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    21
 * questions.
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    22
 */
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    23
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    24
/*
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    25
 * @test
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    26
 * @bug 8014097
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    27
 * @summary Test the limited privilege scope version of doPrivileged
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    28
 */
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    29
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    30
import java.security.*;
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    31
import java.util.*;
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    32
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    33
public class LimitedDoPrivileged {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    34
    /*
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    35
     * Test variations of doPrivileged() and doPrivileged() with a limited privilege scope
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    36
     * in a sandbox with the usual default permission to read the system properties for the
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    37
     * file and path separators.
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    38
     *
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    39
     * By passing in an "assigned" AccessControlContext that has
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    40
     * no default permissions we can test how code privileges are being scoped.
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    41
     */
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    42
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    43
    private static final ProtectionDomain domain =
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    44
        new ProtectionDomain(null, null, null, null);
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    45
    private static final AccessControlContext acc =
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    46
        new AccessControlContext(new ProtectionDomain[] { domain });
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    47
    private static final PropertyPermission pathPerm =
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    48
        new PropertyPermission("path.separator", "read");
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    49
    private static final PropertyPermission filePerm =
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    50
        new PropertyPermission("file.separator", "read");
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    51
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    52
    public static void main(String[] args) throws Exception {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    53
        /*
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    54
         * Verify that we have the usual default property read permission.
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    55
         */
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    56
        AccessController.getContext().checkPermission(filePerm);
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    57
        AccessController.getContext().checkPermission(pathPerm);
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    58
        System.out.println("test 1 passed");
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    59
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    60
        /*
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    61
         * Inject the "no permission" AccessControlContext.
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    62
         */
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    63
        AccessController.doPrivileged(new PrivilegedAction() {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    64
            public Object run() {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    65
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    66
                /*
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    67
                 * Verify that we no longer have the "file.separator" permission.
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    68
                 */
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    69
                try {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    70
                    AccessController.getContext().checkPermission(pathPerm);
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    71
                } catch (AccessControlException ace) {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    72
                    System.out.println("test 2 passed");
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    73
                }
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    74
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    75
                /*
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    76
                 * Verify that we can give ourselves limited privilege to read
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    77
                 * any system property starting with "path.".
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    78
                 */
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    79
                AccessController.doPrivileged
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    80
                    (new PrivilegedAction() {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    81
                        public Object run() {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    82
                            AccessController.getContext().checkPermission(pathPerm);
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    83
                            return null;
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    84
                        }
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    85
                }, null, new PropertyPermission("path.*", "read"));
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    86
                System.out.println("test 3 passed");
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    87
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    88
                /*
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    89
                 * Verify that if we give ourselves limited privilege to read
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    90
                 * any system property starting with "path." it won't give us the
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    91
                 * the ability to read "file.separator".
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    92
                 */
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    93
                try {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    94
                    AccessController.doPrivileged
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    95
                        (new PrivilegedAction() {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    96
                            public Object run() {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    97
                                AccessController.getContext().checkPermission(filePerm);
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    98
                                return null;
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
    99
                            }
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   100
                    }, null, new PropertyPermission("path.*", "read"));
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   101
                } catch (AccessControlException ace) {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   102
                    System.out.println("test 4 passed");
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   103
                }
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   104
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   105
                /*
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   106
                 * Verify that capturing and passing in the context with no default
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   107
                 * system property permission grants will prevent access that succeeded
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   108
                 * earlier without the context assignment.
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   109
                 */
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   110
                final AccessControlContext context = AccessController.getContext();
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   111
                try {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   112
                    AccessController.doPrivileged
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   113
                        (new PrivilegedAction() {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   114
                            public Object run() {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   115
                                AccessController.getContext().checkPermission(pathPerm);
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   116
                                return null;
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   117
                            }
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   118
                    }, context, new PropertyPermission("path.*", "read"));
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   119
                } catch (AccessControlException ace) {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   120
                    System.out.println("test 5 passed");
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   121
                }
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   122
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   123
                /*
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   124
                 * Verify that we can give ourselves full privilege to read
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   125
                 * any system property starting with "path.".
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   126
                 */
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   127
                AccessController.doPrivileged
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   128
                     (new PrivilegedAction() {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   129
                        public Object run() {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   130
                            AccessController.getContext().checkPermission(pathPerm);
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   131
                            return null;
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   132
                        }
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   133
                });
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   134
                System.out.println("test 6 passed");
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   135
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   136
                /*
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   137
                 * Verify that capturing and passing in the context with no default
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   138
                 * system property permission grants will prevent access that succeeded
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   139
                 * earlier without the context assignment.
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   140
                 */
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   141
                try {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   142
                    AccessController.doPrivileged
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   143
                        (new PrivilegedAction() {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   144
                            public Object run() {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   145
                                AccessController.getContext().checkPermission(pathPerm);
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   146
                                return null;
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   147
                            }
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   148
                    }, context);
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   149
                } catch (AccessControlException ace) {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   150
                    System.out.println("test 7 passed");
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   151
                }
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   152
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   153
                /*
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   154
                 * Verify that we can give ourselves limited privilege to read
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   155
                 * any system property starting with "path." when a limited
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   156
                 * privilege scope context is captured and passed to a regular
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   157
                 * doPrivileged() as an assigned context.
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   158
                 */
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   159
                AccessController.doPrivileged
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   160
                     (new PrivilegedAction() {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   161
                        public Object run() {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   162
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   163
                            /*
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   164
                             * Capture the limited privilege scope and inject it into the
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   165
                             * regular doPrivileged().
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   166
                             */
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   167
                            final AccessControlContext limitedContext = AccessController.getContext();
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   168
                            AccessController.doPrivileged
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   169
                                (new PrivilegedAction() {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   170
                                    public Object run() {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   171
                                        AccessController.getContext().checkPermission(pathPerm);
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   172
                                        return null;
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   173
                                }
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   174
                            }, limitedContext);
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   175
                            return null;
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   176
                        }
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   177
                }, null, new PropertyPermission("path.*", "read"));
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   178
                System.out.println("test 8 passed");
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   179
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   180
                /*
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   181
                 * Verify that we can give ourselves limited privilege to read
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   182
                 * any system property starting with "path." it won't give us the
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   183
                 * the ability to read "file.separator" when a limited
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   184
                 * privilege scope context is captured and passed to a regular
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   185
                 * doPrivileged() as an assigned context.
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   186
                 */
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   187
                AccessController.doPrivileged
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   188
                     (new PrivilegedAction() {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   189
                        public Object run() {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   190
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   191
                            /*
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   192
                             * Capture the limited privilege scope and inject it into the
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   193
                             * regular doPrivileged().
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   194
                             */
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   195
                            final AccessControlContext limitedContext = AccessController.getContext();
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   196
                            try {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   197
                                AccessController.doPrivileged
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   198
                                    (new PrivilegedAction() {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   199
                                        public Object run() {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   200
                                            AccessController.getContext().checkPermission(filePerm);
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   201
                                            return null;
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   202
                                    }
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   203
                                }, limitedContext);
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   204
                            } catch (AccessControlException ace) {
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   205
                                System.out.println("test 9 passed");
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   206
                            }
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   207
                            return null;
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   208
                        }
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   209
                }, null, new PropertyPermission("path.*", "read"));
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   210
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   211
                return null;
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   212
            }
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   213
        }, acc);
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   214
    }
7791613dcbfd 8014097: add doPrivileged methods with limited privilege scope
jdn
parents:
diff changeset
   215
}