• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 /*
18  * Copyright (C) 2008 The Android Open Source Project
19  *
20  * Licensed under the Apache License, Version 2.0 (the "License");
21  * you may not use this file except in compliance with the License.
22  * You may obtain a copy of the License at
23  *
24  *      http://www.apache.org/licenses/LICENSE-2.0
25  *
26  * Unless required by applicable law or agreed to in writing, software
27  * distributed under the License is distributed on an "AS IS" BASIS,
28  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29  * See the License for the specific language governing permissions and
30  * limitations under the License.
31  */
32 
33 package java.security;
34 
35 /**
36  * Legacy security code; do not use.
37  */
38 public final class AccessController {
AccessController()39     private AccessController() { }
40 
41     /**
42      * Calls {@code action.run()}.
43      */
doPrivileged(PrivilegedAction<T> action)44     public static <T> T doPrivileged(PrivilegedAction<T> action) {
45         return action.run();
46     }
47 
48     /**
49      * Calls {@code action.run()}.
50      */
doPrivileged(PrivilegedAction<T> action, AccessControlContext context)51     public static <T> T doPrivileged(PrivilegedAction<T> action, AccessControlContext context) {
52         return action.run();
53     }
54 
55     /**
56      * Calls {@code action.run()}.
57      */
doPrivileged(PrivilegedExceptionAction<T> action)58     public static <T> T doPrivileged(PrivilegedExceptionAction<T> action) throws PrivilegedActionException {
59         try {
60             return action.run();
61         } catch (RuntimeException e) {
62             throw e; // so we don't wrap RuntimeExceptions with PrivilegedActionException
63         } catch (Exception e) {
64             throw new PrivilegedActionException(e);
65         }
66     }
67 
68     /**
69      * Calls {@code action.run()}.
70      */
doPrivileged(PrivilegedExceptionAction<T> action, AccessControlContext context)71     public static <T> T doPrivileged(PrivilegedExceptionAction<T> action, AccessControlContext context) throws PrivilegedActionException {
72         return doPrivileged(action);
73     }
74 
75     /**
76      * Calls {@code action.run()}.
77      */
doPrivilegedWithCombiner(PrivilegedAction<T> action)78     public static <T> T doPrivilegedWithCombiner(PrivilegedAction<T> action) {
79         return action.run();
80     }
81 
82     /**
83      * Calls {@code action.run()}.
84      */
doPrivilegedWithCombiner(PrivilegedExceptionAction<T> action)85     public static <T> T doPrivilegedWithCombiner(PrivilegedExceptionAction<T> action) throws PrivilegedActionException {
86         return doPrivileged(action);
87     }
88 
checkPermission(Permission permission)89     public static void checkPermission(Permission permission) throws AccessControlException { }
90 
getContext()91     public static AccessControlContext getContext() { return new AccessControlContext(null); }
92 }
93