This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[PATCH] support security.manager property
- From: Casey Marshall <csm at gnu dot org>
- To: java-patches at gcc dot gnu dot org
- Date: Thu, 29 Jul 2004 22:11:45 -0700
- Subject: [PATCH] support security.manager property
This patch provides support of the security.manager system property
which, under other VMs, tells the runtime to install a SecurityManager
on startup. If the property is specified, but empty, an instance of
java.lang.SecurityManager is created; otherwise, the property is taken
to be a the name of a class that
Note that this patch will only work if there is a real SecurityManager
and a real AccessController; otherwise there is a nasty boostrap
problem that prevents the SecurityManager instance from being
created.
A nice property of this change is that natively linked binaries (read:
gcjappletviewer) can have a security manager set at compile-time.
2004-07-29 Casey Marshall <csm@gnu.org>
* prims.cc (_Jv_RunMain): install a security manager if the
`security.manager' property is set.
--
Casey Marshall || csm@gnu.org
Index: prims.cc
===================================================================
RCS file: /cvsroot/gcc/gcc/libjava/prims.cc,v
retrieving revision 1.95
diff -u -r1.95 prims.cc
--- prims.cc 24 Jul 2004 01:17:28 -0000 1.95
+++ prims.cc 27 Jul 2004 07:00:16 -0000
@@ -62,6 +62,8 @@
#include <gnu/gcj/runtime/VMClassLoader.h>
#include <gnu/gcj/runtime/FinalizerThread.h>
#include <gnu/java/lang/MainThread.h>
+#include <java/lang/ClassCastException.h>
+#include <java/lang/SecurityManager.h>
#ifdef USE_LTDL
#include <ltdl.h>
@@ -1047,6 +1049,29 @@
// for `main'; that way it will be set up if `main' is a JNI method.
runtime = java::lang::Runtime::getRuntime ();
+ // Set the default security manager if the "security.manager"
+ // property has been set.
+ java::lang::String *smgr = java::lang::System::getProperty
+ (JvNewStringLatin1 ("security.manager"));
+ if (smgr != NULL)
+ {
+ using java::lang::Runtime;
+ // If the property is set, but empty, create the default
+ // security manager.
+ if (smgr->length() == 0)
+ java::lang::Runtime::securityManager =
+ new java::lang::SecurityManager();
+ // Otherwise, take the property to be a class name.
+ else
+ {
+ java::lang::Class *clazz = java::lang::Class::forName (smgr);
+ if (!java::lang::SecurityManager::class$.isAssignableFrom (clazz))
+ throw new java::lang::ClassCastException();
+ java::lang::Runtime::securityManager =
+ (java::lang::SecurityManager *) clazz->newInstance();
+ }
+ }
+
#ifdef DISABLE_MAIN_ARGS
arg_vec = JvConvertArgv (0, 0);
#else