• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This code is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License version 2 only, as
8  * published by the Free Software Foundation.  Oracle designates this
9  * particular file as subject to the "Classpath" exception as provided
10  * by Oracle in the LICENSE file that accompanied this code.
11  *
12  * This code is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15  * version 2 for more details (a copy is included in the LICENSE file that
16  * accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License version
19  * 2 along with this work; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21  *
22  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23  * or visit www.oracle.com if you need additional information or have any
24  * questions.
25  */
26 
27 package java.security;
28 
29 import sun.security.util.Debug;
30 import jdk.internal.reflect.CallerSensitive;
31 import jdk.internal.reflect.Reflection;
32 
33 // Android-changed: Stubbed the implementation.  Android doesn't support SecurityManager.
34 // See comments in java.lang.SecurityManager for details.
35 /**
36  * Android doesn't support {@link SecurityManager}. Do not use this class.
37  */
38 public final class AccessController {
39 
AccessController()40     private AccessController() { }
41 
42     /**
43      * Calls {@code action.run()}.
44      */
doPrivileged(PrivilegedAction<T> action)45     public static <T> T doPrivileged(PrivilegedAction<T> action) {
46         return action.run();
47     }
48 
49     /**
50      * Calls {@code action.run()}.
51      */
doPrivilegedWithCombiner(PrivilegedAction<T> action)52     public static <T> T doPrivilegedWithCombiner(PrivilegedAction<T> action) {
53         return action.run();
54     }
55 
56 
57     /**
58      * Calls {@code action.run()}.
59      */
doPrivileged(PrivilegedAction<T> action, AccessControlContext context)60     public static <T> T doPrivileged(PrivilegedAction<T> action,
61                                      AccessControlContext context) {
62         return action.run();
63     }
64 
65     /**
66      * Calls {@code action.run()}.
67      *
68      * @hide
69      */
doPrivilegedWithCombiner(PrivilegedAction<T> action, AccessControlContext context, Permission... perms)70     public static <T> T doPrivilegedWithCombiner(PrivilegedAction<T> action,
71         AccessControlContext context, Permission... perms) {
72         return doPrivileged(action);
73     }
74 
75     /**
76      * Calls {@code action.run()}.
77      */
78     public static <T> T
doPrivileged(PrivilegedExceptionAction<T> action)79         doPrivileged(PrivilegedExceptionAction<T> action)
80         throws PrivilegedActionException {
81         try {
82             return action.run();
83         } catch (Exception e) {
84             throw new PrivilegedActionException(e);
85         }
86     }
87 
88 
89     /**
90      * Calls {@code action.run()}.
91      */
doPrivilegedWithCombiner(PrivilegedExceptionAction<T> action)92     public static <T> T doPrivilegedWithCombiner(PrivilegedExceptionAction<T> action)
93         throws PrivilegedActionException
94     {
95         return doPrivileged(action);
96     }
97 
98 
99     /**
100      * Calls {@code action.run()}.
101      */
102     public static <T> T
doPrivileged(PrivilegedExceptionAction<T> action, AccessControlContext context)103         doPrivileged(PrivilegedExceptionAction<T> action,
104                      AccessControlContext context)
105         throws PrivilegedActionException {
106         return doPrivileged(action);
107     }
108 
109     /**
110      * Calls {@code action.run()}.
111      *
112      * @hide
113      */
doPrivileged(PrivilegedExceptionAction<T> action, AccessControlContext context, Permission... perms)114     public static <T> T doPrivileged(PrivilegedExceptionAction<T> action,
115                                      AccessControlContext context, Permission... perms)
116         throws PrivilegedActionException
117     {
118         return doPrivileged(action);
119     }
120 
121     /**
122      * Calls {@code action.run()}.
123      *
124      * @hide
125      */
doPrivilegedWithCombiner(PrivilegedExceptionAction<T> action, AccessControlContext context, Permission... perms)126     public static <T> T doPrivilegedWithCombiner(PrivilegedExceptionAction<T> action,
127             AccessControlContext context,
128             Permission... perms)
129             throws PrivilegedActionException
130     {
131         return doPrivileged(action);
132     }
133 
134     /**
135      * Calls {@code action.run()}.
136      *
137      * @hide
138      */
doPrivileged(PrivilegedAction<T> action, AccessControlContext context, Permission... perms)139     public static <T> T doPrivileged(PrivilegedAction<T> action,
140             AccessControlContext context, Permission... perms) {
141         return doPrivileged(action);
142     }
143 
getContext()144     public static AccessControlContext getContext() {
145         return new AccessControlContext(null);
146     }
147 
checkPermission(Permission perm)148     public static void checkPermission(Permission perm)
149                  throws AccessControlException {
150     }
151 }
152