summaryrefslogtreecommitdiffstats
path: root/luni/src/main/java/java/lang/SecurityManager.java
diff options
context:
space:
mode:
authorJesse Wilson <jessewilson@google.com>2009-07-24 15:17:03 -0700
committerJesse Wilson <jessewilson@google.com>2009-07-24 15:40:01 -0700
commitf5597e626ecf7949d249dea08c1a2964d890ec11 (patch)
treef9f6aab14a81c9f51729e875f721a33ace6e579b /luni/src/main/java/java/lang/SecurityManager.java
parent0402e94d55d8c3aeec5e4db97ef62aab35f97235 (diff)
downloadlibcore-f5597e626ecf7949d249dea08c1a2964d890ec11.zip
libcore-f5597e626ecf7949d249dea08c1a2964d890ec11.tar.gz
libcore-f5597e626ecf7949d249dea08c1a2964d890ec11.tar.bz2
Integrate luni module (but not tests) to Harmony r772995.
Notable changes - Stripped "@since Android 1.0" from many files. Most files are now 100% the same in Dalvik and Harmony. - AbstractStringBuilder.reverse() supports surrogates - AbstractStringBuilder shares less to waste less memory - Bitset optimized - BufferedInputStream changed to support unsynchronized close() - BufferedOutputStream does flushInternal - BufferedReader supports EBCDIC NEL - Collections.synchronizedList().indexOf() does a copy for more concurrency - Classes in nio module changed: DatagramChannelImpl, SocketChannelImpl and ServerSocketChannelImpl (these depend on internal APIs changed in this update) - DataInputStream/DataOutputStream now use a small buffer to limit the number of times the underlying stream is accessed - Date now has a minutes offset, more efficient toString() - ExposedByteArrayInputStream: new internal class - DeleteOnExit moved to top-level class - FileDescriptor.isValid() now non-native - Float, Double lessThan optimized (fix for compare(-0.0F, 0.0F) still pending) - FileURLConnection now guesses content types from streams - HashMap iterator changes - Hashtable iterator changes - INetworkSystem - removes bind2(), createMulticastSocket, sendStream(), - renames createSocket to createStreamSocket - JarURLConnection rewritten - LinkedHashMap: new iterator - Locale, Currency, TimeZone: now use ICU in Harmony, plain Java in Dalvik - ObjectInputStream: Accessor objects in Harmony, direct native in Dalvik - ProxyClassFile - many changes - String - optimized ascii for toLowerCase, toUpperCase, compare - Timer - rewritten - TreeMap - rewritten - URLClassLoader - new - URLConnection - new guessContentTypeFromStream(), uses org.apache.harmony.awt.www.content to lookup content type handlers
Diffstat (limited to 'luni/src/main/java/java/lang/SecurityManager.java')
-rw-r--r--luni/src/main/java/java/lang/SecurityManager.java137
1 files changed, 45 insertions, 92 deletions
diff --git a/luni/src/main/java/java/lang/SecurityManager.java b/luni/src/main/java/java/lang/SecurityManager.java
index dc624e3..9125850 100644
--- a/luni/src/main/java/java/lang/SecurityManager.java
+++ b/luni/src/main/java/java/lang/SecurityManager.java
@@ -49,8 +49,6 @@ import org.apache.harmony.luni.util.PriviAction;
* operation is not allowed, then they throw a {@link SecurityException}. The
* only exception is {@link #checkTopLevelWindow(Object)}, which returns a
* boolean to indicate permission.
- *
- * @since Android 1.0
*/
public class SecurityManager {
@@ -63,9 +61,8 @@ public class SecurityManager {
/**
* Flag to indicate whether a security check is in progress.
- *
+ *
* @deprecated Use {@link #checkPermission}
- * @since Android 1.0
*/
@Deprecated
protected boolean inCheck;
@@ -75,9 +72,6 @@ public class SecurityManager {
* <p>
* The {@code RuntimePermission("createSecurityManager")} is checked if a
* security manager is installed.
- * </p>
- *
- * @since Android 1.0
*/
public SecurityManager() {
SecurityManager security = System.getSecurityManager();
@@ -94,7 +88,7 @@ public class SecurityManager {
/**
* Checks whether the calling thread is allowed to accept socket
* connections.
- *
+ *
* @param host
* the address of the host that attempts to connect.
* @param port
@@ -104,7 +98,6 @@ public class SecurityManager {
* @throws SecurityException
* if the calling thread is not allowed to accept socket
* connections from {@code host} through {@code port}.
- * @since Android 1.0
*/
public void checkAccept(String host, int port) {
if (host == null) {
@@ -116,12 +109,11 @@ public class SecurityManager {
/**
* Checks whether the calling thread is allowed to modify the specified
* thread.
- *
+ *
* @param thread
* the thread to access.
* @throws SecurityException
* if the calling thread is not allowed to access {@code thread}.
- * @since Android 1.0
*/
public void checkAccess(Thread thread) {
// Only worry about system threads. Dead threads have a null group.
@@ -134,14 +126,13 @@ public class SecurityManager {
/**
* Checks whether the calling thread is allowed to modify the specified
* thread group.
- *
+ *
* @param group
* the thread group to access.
* @throws NullPointerException
* if {@code group} is {@code null}.
* @throws SecurityException
* if the calling thread is not allowed to access {@code group}.
- * @since Android 1.0
*/
public void checkAccess(ThreadGroup group) {
// Only worry about system threads.
@@ -157,7 +148,7 @@ public class SecurityManager {
* Checks whether the calling thread is allowed to establish socket
* connections. A -1 port indicates the caller is trying to resolve the
* hostname.
- *
+ *
* @param host
* the address of the host to connect to.
* @param port
@@ -167,7 +158,6 @@ public class SecurityManager {
* @throws SecurityException
* if the calling thread is not allowed to connect to {@code
* host} through {@code port}.
- * @since Android 1.0
*/
public void checkConnect(String host, int port) {
if (host == null) {
@@ -184,7 +174,7 @@ public class SecurityManager {
* Checks whether the specified security context is allowed to establish
* socket connections. A -1 port indicates the caller is trying to resolve
* the hostname.
- *
+ *
* @param host
* the address of the host to connect to.
* @param port
@@ -196,7 +186,6 @@ public class SecurityManager {
* @throws SecurityException
* if {@code context} is not allowed to connect to {@code host}
* through {@code port}.
- * @since Android 1.0
*/
public void checkConnect(String host, int port, Object context) {
// BEGIN android-added
@@ -214,11 +203,10 @@ public class SecurityManager {
/**
* Checks whether the calling thread is allowed to create a class loader.
- *
+ *
* @throws SecurityException
* if the calling thread is not allowed to create a class
* loader.
- * @since Android 1.0
*/
public void checkCreateClassLoader() {
checkPermission(RuntimePermission.permissionToCreateClassLoader);
@@ -227,12 +215,11 @@ public class SecurityManager {
/**
* Checks whether the calling thread is allowed to delete the file with the
* specified name, which should be passed in canonical form.
- *
+ *
* @param file
* the name of the file to delete.
* @throws SecurityException
* if the calling thread is not allowed to delete {@code file}.
- * @since Android 1.0
*/
public void checkDelete(String file) {
checkPermission(new FilePermission(file, "delete")); //$NON-NLS-1$
@@ -241,12 +228,11 @@ public class SecurityManager {
/**
* Checks whether the calling thread is allowed to execute the specified
* platform specific command.
- *
+ *
* @param cmd
* the command line to execute.
* @throws SecurityException
* if the calling thread is not allowed to execute {@code cmd}.
- * @since Android 1.0
*/
public void checkExec(String cmd) {
checkPermission(new FilePermission(new File(cmd).isAbsolute() ? cmd
@@ -256,14 +242,13 @@ public class SecurityManager {
/**
* Checks whether the calling thread is allowed to terminate the virtual
* machine.
- *
+ *
* @param status
* the status that the virtual machine returns when it is
* terminated.
* @throws SecurityException
* if the calling thread is not allowed to terminate the virtual
* machine with {@code status}.
- * @since Android 1.0
*/
public void checkExit(int status) {
checkPermission(RuntimePermission.permissionToExitVM);
@@ -272,12 +257,11 @@ public class SecurityManager {
/**
* Checks whether the calling thread is allowed to load the specified native
* library.
- *
+ *
* @param libName
* the name of the library to load.
* @throws SecurityException
* if the calling thread is not allowed to load {@code libName}.
- * @since Android 1.0
*/
public void checkLink(String libName) {
if (libName == null) {
@@ -289,12 +273,11 @@ public class SecurityManager {
/**
* Checks whether the calling thread is allowed to listen on the specified
* port.
- *
+ *
* @param port
* the port number to check.
* @throws SecurityException
* if the calling thread is not allowed listen on {@code port}.
- * @since Android 1.0
*/
public void checkListen(int port) {
if (port == 0) {
@@ -312,7 +295,7 @@ public class SecurityManager {
* reflect API). Due to the nature of the check, overriding implementations
* cannot call {@code super.checkMemberAccess()} since the stack would no
* longer be of the expected shape.
- *
+ *
* @param cls
* the class of which members are accessed.
* @param type
@@ -322,7 +305,6 @@ public class SecurityManager {
* @throws SecurityException
* if the calling thread is not allowed to access members of
* {@code cls}.
- * @since Android 1.0
*/
public void checkMemberAccess(Class<?> cls, int type) {
if (cls == null) {
@@ -352,12 +334,11 @@ public class SecurityManager {
/**
* Checks whether the calling thread is allowed to use the specified IP
* multicast group address.
- *
+ *
* @param maddr
* the internet group address to use.
* @throws SecurityException
* if the calling thread is not allowed to use {@code maddr}.
- * @since Android 1.0
*/
public void checkMulticast(InetAddress maddr) {
checkPermission(new SocketPermission(maddr.getHostAddress(),
@@ -367,7 +348,7 @@ public class SecurityManager {
/**
* Checks whether the calling thread is allowed to use the specified IP
* multicast group address.
- *
+ *
* @param maddr
* the internet group address to use.
* @param ttl
@@ -376,7 +357,6 @@ public class SecurityManager {
* @throws SecurityException
* if the calling thread is not allowed to use {@code maddr}.
* @deprecated use {@link #checkMulticast(java.net.InetAddress)}
- * @since Android 1.0
*/
@Deprecated
public void checkMulticast(InetAddress maddr, byte ttl) {
@@ -387,13 +367,12 @@ public class SecurityManager {
/**
* Checks whether the calling thread is allowed to access the specified
* package.
- *
+ *
* @param packageName
* the name of the package to access.
* @throws SecurityException
* if the calling thread is not allowed to access {@code
* packageName}.
- * @since Android 1.0
*/
public void checkPackageAccess(String packageName) {
if (packageName == null) {
@@ -408,13 +387,12 @@ public class SecurityManager {
/**
* Checks whether the calling thread is allowed to define new classes in the
* specified package.
- *
+ *
* @param packageName
* the name of the package to add a class to.
* @throws SecurityException
* if the calling thread is not allowed to add classes to
* {@code packageName}.
- * @since Android 1.0
*/
public void checkPackageDefinition(String packageName) {
if (packageName == null) {
@@ -459,11 +437,10 @@ public class SecurityManager {
/**
* Checks whether the calling thread is allowed to access the system
* properties.
- *
+ *
* @throws SecurityException
* if the calling thread is not allowed to access system
* properties.
- * @since Android 1.0
*/
public void checkPropertiesAccess() {
checkPermission(READ_WRITE_ALL_PROPERTIES_PERMISSION);
@@ -472,13 +449,12 @@ public class SecurityManager {
/**
* Checks whether the calling thread is allowed to access a particular
* system property.
- *
+ *
* @param key
* the name of the property to access.
* @throws SecurityException
* if the calling thread is not allowed to access the {@code
* key} system property.
- * @since Android 1.0
*/
public void checkPropertyAccess(String key) {
checkPermission(new PropertyPermission(key, "read")); //$NON-NLS-1$
@@ -487,12 +463,11 @@ public class SecurityManager {
/**
* Checks whether the calling thread is allowed to read from the file with
* the specified file descriptor.
- *
+ *
* @param fd
* the file descriptor of the file to read from.
* @throws SecurityException
* if the calling thread is not allowed to read from {@code fd}.
- * @since Android 1.0
*/
public void checkRead(FileDescriptor fd) {
if (fd == null) {
@@ -504,13 +479,12 @@ public class SecurityManager {
/**
* Checks whether the calling thread is allowed to read from the file with
* the specified name, which should be passed in canonical form.
- *
+ *
* @param file
* the name of the file or directory to read from.
* @throws SecurityException
* if the calling thread is not allowed to read from {@code
* file}.
- * @since Android 1.0
*/
public void checkRead(String file) {
checkPermission(new FilePermission(file, "read")); //$NON-NLS-1$
@@ -519,14 +493,13 @@ public class SecurityManager {
/**
* Checks whether the given security context is allowed to read from the
* file named by the argument, which should be passed in canonical form.
- *
+ *
* @param file
* the name of the file or directory to check.
* @param context
* the security context to use for the check.
* @throws SecurityException
* if {@code context} is not allowed to read from {@code file}.
- * @since Android 1.0
*/
public void checkRead(String file, Object context) {
checkPermission(new FilePermission(file, "read"), context); //$NON-NLS-1$
@@ -535,13 +508,12 @@ public class SecurityManager {
/**
* Checks whether the calling thread is allowed to perform the security
* operation named by the target.
- *
+ *
* @param target
* the name of the operation to perform.
* @throws SecurityException
* if the calling thread is not allowed to perform
* {@code target}.
- * @since Android 1.0
*/
public void checkSecurityAccess(String target) {
checkPermission(new SecurityPermission(target));
@@ -550,11 +522,10 @@ public class SecurityManager {
/**
* Checks whether the calling thread is allowed to set the net object
* factories.
- *
+ *
* @throws SecurityException
* if the calling thread is not allowed to set the net object
* factories.
- * @since Android 1.0
*/
public void checkSetFactory() {
checkPermission(RuntimePermission.permissionToSetFactory);
@@ -563,14 +534,13 @@ public class SecurityManager {
/**
* Checks whether the calling thread is trusted to show the specified top
* level window.
- *
+ *
* @param window
* the window to show.
* @return {@code true} if the calling thread is allowed to show {@code
* window}; {@code false} otherwise.
* @throws NullPointerException
* if {@code window} is {@code null}.
- * @since Android 1.0
*/
public boolean checkTopLevelWindow(Object window) {
if (window == null) {
@@ -597,11 +567,10 @@ public class SecurityManager {
/**
* Checks whether the calling thread is allowed to access the system
* clipboard.
- *
+ *
* @throws SecurityException
* if the calling thread is not allowed to access the system
* clipboard.
- * @since Android 1.0
*/
public void checkSystemClipboardAccess() {
try {
@@ -623,11 +592,10 @@ public class SecurityManager {
/**
* Checks whether the calling thread is allowed to access the AWT event
* queue.
- *
+ *
* @throws SecurityException
* if the calling thread is not allowed to access the AWT event
* queue.
- * @since Android 1.0
*/
public void checkAwtEventQueueAccess() {
try {
@@ -648,11 +616,10 @@ public class SecurityManager {
/**
* Checks whether the calling thread is allowed to start a new print job.
- *
+ *
* @throws SecurityException
* if the calling thread is not allowed to start a new print
* job.
- * @since Android 1.0
*/
public void checkPrintJobAccess() {
checkPermission(RuntimePermission.permissionToQueuePrintJob);
@@ -661,12 +628,11 @@ public class SecurityManager {
/**
* Checks whether the calling thread is allowed to write to the file with
* the specified file descriptor.
- *
+ *
* @param fd
* the file descriptor of the file to write to.
* @throws SecurityException
* if the calling thread is not allowed to write to {@code fd}.
- * @since Android 1.0
*/
public void checkWrite(FileDescriptor fd) {
if (fd == null) {
@@ -678,13 +644,12 @@ public class SecurityManager {
/**
* Checks whether the calling thread is allowed to write to the file with
* the specified name, which should be passed in canonical form.
- *
+ *
* @param file
* the name of the file or directory to write to.
* @throws SecurityException
- * if the calling thread is not allowed to write to
+ * if the calling thread is not allowed to write to
* {@code file}.
- * @since Android 1.0
*/
public void checkWrite(String file) {
checkPermission(new FilePermission(file, "write")); //$NON-NLS-1$
@@ -692,11 +657,10 @@ public class SecurityManager {
/**
* Indicates if this security manager is currently checking something.
- *
+ *
* @return {@code true} if this security manager is executing a security
* check method; {@code false} otherwise.
* @deprecated Use {@link #checkPermission}.
- * @since Android 1.0
*/
@Deprecated
public boolean getInCheck() {
@@ -707,9 +671,8 @@ public class SecurityManager {
* Returns an array containing one entry for each method in the current
* execution stack. Each entry is the {@code java.lang.Class} which
* represents the class in which the method is defined.
- *
+ *
* @return all classes in the execution stack.
- * @since Android 1.0
*/
@SuppressWarnings("unchecked")
protected Class[] getClassContext() {
@@ -719,10 +682,9 @@ public class SecurityManager {
/**
* Returns the class loader of the first class in the execution stack whose
* class loader is not a system class loader.
- *
+ *
* @return the most recent non-system class loader.
* @deprecated Use {@link #checkPermission}.
- * @since Android 1.0
*/
@Deprecated
protected ClassLoader currentClassLoader() {
@@ -755,11 +717,10 @@ public class SecurityManager {
/**
* Returns the index in the call stack of the first class whose class loader
* is not a system class loader.
- *
+ *
* @return the frame index of the first method whose class was loaded by a
* non-system class loader.
* @deprecated Use {@link #checkPermission}.
- * @since Android 1.0
*/
@Deprecated
protected int classLoaderDepth() {
@@ -791,10 +752,9 @@ public class SecurityManager {
/**
* Returns the first class in the call stack that was loaded by a class
* loader which is not a system class loader.
- *
+ *
* @return the most recent class loaded by a non-system class loader.
* @deprecated Use {@link #checkPermission}.
- * @since Android 1.0
*/
@Deprecated
protected Class<?> currentLoadedClass() {
@@ -827,13 +787,12 @@ public class SecurityManager {
* Returns the index in the call stack of the first method which is
* contained in the class with the specified name. Returns -1 if no methods
* from this class are in the stack.
- *
+ *
* @param name
* the name of the class to look for.
* @return the frame index of the first method found is contained in the
* class identified by {@code name}.
* @deprecated Use {@link #checkPermission}.
- * @since Android 1.0
*/
@Deprecated
protected int classDepth(String name) {
@@ -849,13 +808,12 @@ public class SecurityManager {
/**
* Indicates whether there is a method in the call stack from the class with
* the specified name.
- *
+ *
* @param name
* the name of the class to look for.
* @return {@code true} if a method from the class identified by {@code
* name} is executing; {@code false} otherwise.
* @deprecated Use {@link #checkPermission}.
- * @since Android 1.0
*/
@Deprecated
protected boolean inClass(String name) {
@@ -865,11 +823,10 @@ public class SecurityManager {
/**
* Indicates whether there is a method in the call stack from a class which
* was defined by a non-system class loader.
- *
+ *
* @return {@code true} if a method from a class that was defined by a
* non-system class loader is executing; {@code false} otherwise.
* @deprecated Use {@link #checkPermission}
- * @since Android 1.0
*/
@Deprecated
protected boolean inClassLoader() {
@@ -880,9 +837,8 @@ public class SecurityManager {
* Returns the thread group which should be used to instantiate new threads.
* By default, this is the same as the thread group of the thread running
* this method.
- *
+ *
* @return ThreadGroup the thread group to create new threads in.
- * @since Android 1.0
*/
public ThreadGroup getThreadGroup() {
return Thread.currentThread().getThreadGroup();
@@ -890,12 +846,11 @@ public class SecurityManager {
/**
* Returns an object which encapsulates the security state of the current
- * point in the execution. In the Android reference implementation, this is
- * an {@link java.security.AccessControlContext}.
- *
+ * point in the execution. In our case, this is an {@link
+ * java.security.AccessControlContext}.
+ *
* @return an object that encapsulates information about the current
* execution environment.
- * @since Android 1.0
*/
public Object getSecurityContext() {
return AccessController.getContext();
@@ -904,13 +859,12 @@ public class SecurityManager {
/**
* Checks whether the calling thread is allowed to access the resource being
* guarded by the specified permission object.
- *
+ *
* @param permission
* the permission to check.
* @throws SecurityException
* if the requested {@code permission} is denied according to
* the current security policy.
- * @since Android 1.0
*/
public void checkPermission(Permission permission) {
try {
@@ -924,7 +878,7 @@ public class SecurityManager {
/**
* Checks whether the specified security context is allowed to access the
* resource being guarded by the specified permission object.
- *
+ *
* @param permission
* the permission to check.
* @param context
@@ -934,7 +888,6 @@ public class SecurityManager {
* AccessControlContext} or if the requested {@code permission}
* is denied for {@code context} according to the current
* security policy.
- * @since Android 1.0
*/
public void checkPermission(Permission permission, Object context) {
try {