harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From var...@apache.org
Subject svn commit: r500183 - in /harmony/enhanced: classlib/trunk/modules/luni/make/ classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/
Date Fri, 26 Jan 2007 08:47:46 GMT
Author: varlax
Date: Fri Jan 26 00:47:46 2007
New Revision: 500183

URL: http://svn.apache.org/viewvc?view=rev&rev=500183
Log:
Fixed HARMONY-3049 [DRL VM] Not possible to set custom security manager via system property
Tested on Win32, SUSE9@ia32

Added:
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityManager2Test.java
Modified:
    harmony/enhanced/classlib/trunk/modules/luni/make/exclude.linux.x86.ibm
    harmony/enhanced/classlib/trunk/modules/luni/make/exclude.windows.x86.ibm
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/ClassLoader.java
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/System.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/make/exclude.linux.x86.ibm
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/make/exclude.linux.x86.ibm?view=diff&rev=500183&r1=500182&r2=500183
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/make/exclude.linux.x86.ibm (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/make/exclude.linux.x86.ibm Fri Jan 26 00:47:46
2007
@@ -1,2 +1,3 @@
 org/apache/harmony/tests/internal/net/www/protocol/http/HttpURLConnectionTest.java
 tests/api/java/net/SocketTest.java
+org/apache/harmony/luni/tests/java/lang/SecurityManager2Test.java
\ No newline at end of file

Modified: harmony/enhanced/classlib/trunk/modules/luni/make/exclude.windows.x86.ibm
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/make/exclude.windows.x86.ibm?view=diff&rev=500183&r1=500182&r2=500183
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/make/exclude.windows.x86.ibm (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/make/exclude.windows.x86.ibm Fri Jan 26 00:47:46
2007
@@ -0,0 +1 @@
+org/apache/harmony/luni/tests/java/lang/SecurityManager2Test.java
\ No newline at end of file

Added: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityManager2Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityManager2Test.java?view=auto&rev=500183
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityManager2Test.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityManager2Test.java
Fri Jan 26 00:47:46 2007
@@ -0,0 +1,49 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.luni.tests.java.lang;
+
+import java.security.Permission;
+
+import junit.framework.TestCase;
+import tests.support.Support_Exec;
+
+public class SecurityManager2Test extends TestCase {
+
+    public void test_SecurityManager_via_SystemProperty() throws Exception {
+        String[] arg = new String[] {
+                "-Djava.security.manager=" + MySecurityManager.class.getName(),
+                TestForSystemProperty.class.getName() };
+
+        Support_Exec.execJava(arg, null, true);
+    }
+
+    public static class TestForSystemProperty {
+
+        public static void main(String[] args) {
+            assertEquals(MySecurityManager.class, System.getSecurityManager()
+                    .getClass());
+        }
+    }
+
+    /**
+     * Custom security manager
+     */
+    public static class MySecurityManager extends SecurityManager {
+        public void checkPermission(Permission perm) {
+        }
+    }
+}

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/ClassLoader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/ClassLoader.java?view=diff&rev=500183&r1=500182&r2=500183
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/ClassLoader.java
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/ClassLoader.java
Fri Jan 26 00:47:46 2007
@@ -633,7 +633,32 @@
                 "Recursive invocation while initializing system class loader");
         }
         systemClassLoader = SystemClassLoader.getInstance();
-        String className = System.getProperty("java.system.class.loader");
+        
+        String smName = System.getPropertyUnsecure("java.security.manager");
+        if (smName != null) {
+            try {
+                final Class<SecurityManager> smClass;
+                if ("".equals(smName) || "default".equalsIgnoreCase(smName)) {
+                    smClass = java.lang.SecurityManager.class;
+                } else {
+                    smClass = (Class<SecurityManager>)systemClassLoader.loadClass(smName);
+                    if (!SecurityManager.class.isAssignableFrom(smClass)) {
+                        throw new Error(smClass
+                            + " must inherit java.lang.SecurityManager");
+                    }
+                }   
+                AccessController.doPrivileged(new PrivilegedExceptionAction() {
+                    public Object run() throws Exception {
+                        System.setSecurityManager(smClass.newInstance());
+                        return null;
+                    }
+                });
+            } catch (Exception e) {
+                throw (Error)new InternalError().initCause(e);
+            }
+        }
+
+        String className = System.getPropertyUnsecure("java.system.class.loader");
         if (className != null) {
             try {
                 final Class<?> userClassLoader = systemClassLoader

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/System.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/System.java?view=diff&rev=500183&r1=500182&r2=500183
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/System.java
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/System.java
Fri Jan 26 00:47:46 2007
@@ -49,6 +49,10 @@
     private System() {
     }
 
+    static String getPropertyUnsecure(String key) {
+        return getPropertiesUnsecure().getProperty(key);
+    }
+
     /**
      * @com.intel.drl.spec_ref
      */



Mime
View raw message