You are viewing a plain text version of this content. The canonical link for it is here.
Posted to yoko-commits@incubator.apache.org by ri...@apache.org on 2007/03/05 12:53:34 UTC

svn commit: r514660 - in /incubator/yoko/trunk: rmi-impl/src/main/java/org/apache/yoko/rmi/impl/UtilImpl.java rmi-spec/src/main/java/org/apache/yoko/rmispec/util/UtilLoader.java

Author: rickmcguire
Date: Mon Mar  5 04:53:32 2007
New Revision: 514660

URL: http://svn.apache.org/viewvc?view=rev&rev=514660
Log:
YOKO-302 Cannot run yoko without permission to create a security manager


Modified:
    incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/UtilImpl.java
    incubator/yoko/trunk/rmi-spec/src/main/java/org/apache/yoko/rmispec/util/UtilLoader.java

Modified: incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/UtilImpl.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/UtilImpl.java?view=diff&rev=514660&r1=514659&r2=514660
==============================================================================
--- incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/UtilImpl.java (original)
+++ incubator/yoko/trunk/rmi-impl/src/main/java/org/apache/yoko/rmi/impl/UtilImpl.java Mon Mar  5 04:53:32 2007
@@ -1,20 +1,20 @@
 /**
-*
-* 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.
-*/
+ *
+ * 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.yoko.rmi.impl;
 
@@ -31,15 +31,17 @@
 import java.rmi.ServerException;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
 import java.util.logging.Logger;
 
-import javax.rmi.PortableRemoteObject;
 import javax.rmi.CORBA.Stub;
 import javax.rmi.CORBA.Tie;
 import javax.rmi.CORBA.Util;
 import javax.rmi.CORBA.UtilDelegate;
 import javax.rmi.CORBA.ValueHandler;
+import javax.rmi.PortableRemoteObject;
 
+import org.apache.yoko.rmi.util.GetSystemPropertyAction;
 import org.omg.CORBA.Any;
 import org.omg.CORBA.MARSHAL;
 import org.omg.CORBA.TCKind;
@@ -47,26 +49,25 @@
 import org.omg.CORBA.portable.IDLEntity;
 import org.omg.CORBA.portable.UnknownException;
 
-import org.apache.yoko.rmi.util.GetSystemPropertyAction;
-
 public class UtilImpl implements UtilDelegate {
     static final Logger logger = Logger.getLogger(UtilImpl.class.getName());
 
     // Note: this field must be declared before the static intializer that calls Util.loadClass
     // since that method will call loadClass0 which uses this field... if it is below the static
     // initializer the _secman field will be null
-    private static final SecMan _secman = new SecMan();
+    private static final SecMan _secman = getSecMan();
 
     static final Class JAVAX_TRANSACTION_USERTRANSACTION_CLASS;
+
     static {
-	Class  userTransactionClass;
-	try {
-	    userTransactionClass = Util.loadClass("javax.transaction.userTransaction", null, null);
-	}
-	catch(ClassNotFoundException e) {
-	    userTransactionClass = null;
-	}
-	JAVAX_TRANSACTION_USERTRANSACTION_CLASS = userTransactionClass;
+        Class userTransactionClass;
+        try {
+            userTransactionClass = Util.loadClass("javax.transaction.userTransaction", null, null);
+        }
+        catch (ClassNotFoundException e) {
+            userTransactionClass = null;
+        }
+        JAVAX_TRANSACTION_USERTRANSACTION_CLASS = userTransactionClass;
     }
 
     /**
@@ -126,17 +127,17 @@
         buf.append(ex.minor);
 
         switch (ex.completed.value()) {
-        case org.omg.CORBA.CompletionStatus._COMPLETED_YES:
-            buf.append(" Yes");
-            break;
-
-        case org.omg.CORBA.CompletionStatus._COMPLETED_NO:
-            buf.append(" No");
-            break;
-
-        case org.omg.CORBA.CompletionStatus._COMPLETED_MAYBE:
-            buf.append(" Maybe");
-            break;
+            case org.omg.CORBA.CompletionStatus._COMPLETED_YES:
+                buf.append(" Yes");
+                break;
+
+            case org.omg.CORBA.CompletionStatus._COMPLETED_NO:
+                buf.append(" No");
+                break;
+
+            case org.omg.CORBA.CompletionStatus._COMPLETED_MAYBE:
+                buf.append(" Maybe");
+                break;
         }
 
         String exceptionMessage = buf.toString();
@@ -144,8 +145,8 @@
         try {
 
             rex = (RemoteException) newInstance(exclz,
-                    new Class[] { String.class },
-                    new Object[] { exceptionMessage });
+                    new Class[]{String.class},
+                    new Object[]{exceptionMessage});
 
             rex.detail = ex;
 
@@ -236,18 +237,15 @@
 
     /**
      * Write an org.omg.CORBA.Any containing the given object.
-     *
+     * <p/>
      * The object is not converted or translated, simply written. Thus, it must
      * be either an IDL-generated entity, a Serializable value or an
      * org.omg.CORBA.Object. Specifically, a Remote objects and Servants cannot
      * be written, but their corresponding Stubs can.
      *
-     * @param out
-     *            The stream to which the value should be written
-     * @param obj
-     *            The object/value to write
-     * @exception org.omg.CORBA.MARSHAL
-     *                if the value cannot be written
+     * @param out The stream to which the value should be written
+     * @param obj The object/value to write
+     * @throws org.omg.CORBA.MARSHAL if the value cannot be written
      */
     public void writeAny(org.omg.CORBA.portable.OutputStream out, Object obj)
             throws org.omg.CORBA.SystemException {
@@ -309,44 +307,44 @@
 
         switch (typecode.kind().value()) {
 
-        case TCKind._tk_null:
-        case TCKind._tk_void:
-            return null;
-
-        case TCKind._tk_value:
-        case TCKind._tk_value_box:
-            return any.extract_Value();
-
-        case TCKind._tk_abstract_interface:
-            org.omg.CORBA_2_3.portable.InputStream in23 = (org.omg.CORBA_2_3.portable.InputStream) any
-                    .create_input_stream();
-            return in23.read_abstract_interface();
-
-        case TCKind._tk_string:
-            return any.extract_string();
-
-        case TCKind._tk_objref:
-            org.omg.CORBA.Object ref = any.extract_Object();
-            return ref;
+            case TCKind._tk_null:
+            case TCKind._tk_void:
+                return null;
+
+            case TCKind._tk_value:
+            case TCKind._tk_value_box:
+                return any.extract_Value();
+
+            case TCKind._tk_abstract_interface:
+                org.omg.CORBA_2_3.portable.InputStream in23 = (org.omg.CORBA_2_3.portable.InputStream) any
+                        .create_input_stream();
+                return in23.read_abstract_interface();
+
+            case TCKind._tk_string:
+                return any.extract_string();
+
+            case TCKind._tk_objref:
+                org.omg.CORBA.Object ref = any.extract_Object();
+                return ref;
 
-        case TCKind._tk_any:
-            return any.extract_any();
+            case TCKind._tk_any:
+                return any.extract_any();
 
-        default:
-            String id = "<unknown>";
-            try {
-                id = typecode.id();
-            } catch (org.omg.CORBA.TypeCodePackage.BadKind ex) {
-            }
+            default:
+                String id = "<unknown>";
+                try {
+                    id = typecode.id();
+                } catch (org.omg.CORBA.TypeCodePackage.BadKind ex) {
+                }
 
-            throw new MARSHAL("cannot extract " + id + " ("
-                    + typecode.kind().value() + ") value from Any");
+                throw new MARSHAL("cannot extract " + id + " ("
+                        + typecode.kind().value() + ") value from Any");
         }
     }
 
     /**
      * Write a remote object. It must already be exported.
-     *
+     * <p/>
      * This method accepts values of org.omg.CORBA.Object (including stubs), and
      * instances of java.rmi.Remote for objects that have already been exported.
      */
@@ -475,7 +473,7 @@
 
         // ignore standard extensions
         if (JAVAX_TRANSACTION_USERTRANSACTION_CLASS != null &&
-        	theLoader == JAVAX_TRANSACTION_USERTRANSACTION_CLASS.getClassLoader())
+                theLoader == JAVAX_TRANSACTION_USERTRANSACTION_CLASS.getClassLoader())
             return null;
 
         RMIState state = RMIState.current();
@@ -499,7 +497,7 @@
             // ignore
         }
 
-        return (String)AccessController.doPrivileged(new GetSystemPropertyAction("java.rmi.server.codebase"));
+        return (String) AccessController.doPrivileged(new GetSystemPropertyAction("java.rmi.server.codebase"));
     }
 
     static class SecMan extends java.rmi.RMISecurityManager {
@@ -508,6 +506,20 @@
         }
     }
 
+    private static SecMan getSecMan() {
+        try {
+            return (SecMan) AccessController
+                    .doPrivileged(new java.security.PrivilegedExceptionAction() {
+                        public Object run() {
+                            return new SecMan();
+                        }
+                    });
+        } catch (PrivilegedActionException e) {
+            throw new RuntimeException(e);
+        }
+
+    }
+
     public Class loadClass(String name, String codebase, ClassLoader loader)
             throws ClassNotFoundException {
         try {
@@ -560,7 +572,7 @@
                 logger.finer("trying RMIClassLoader");
 
                 URLClassLoader url_loader = new URLClassLoader(
-                        new URL[] { new URL(codebase) }, loader);
+                        new URL[]{new URL(codebase)}, loader);
 
                 result = url_loader.loadClass(name);
 
@@ -594,7 +606,7 @@
 
         } else {
 
-            codebase = (String)AccessController.doPrivileged(new GetSystemPropertyAction("java.rmi.server.codebase"));
+            codebase = (String) AccessController.doPrivileged(new GetSystemPropertyAction("java.rmi.server.codebase"));
 
             if (codebase != null) {
                 try {
@@ -717,7 +729,7 @@
 
     /**
      * Copy a single object, maintaining internal reference integrity.
-     *
+     * <p/>
      * This is done by writing and reading the object to/from a temporary
      * stream. As such, this should be called after the receiving context's
      * class-loaders etc. have been set up.
@@ -767,7 +779,7 @@
 
     /**
      * Copy an array of objects, maintaining internal reference integrity.
-     *
+     * <p/>
      * This is done by writing and reading the object array to/from a temporary
      * stream. As such, this should be called after the receiving context's
      * class-loaders etc. have been set up.
@@ -861,7 +873,7 @@
 	Class[] rmiToCorba;
 	try {
 	    rmiToCorba = new Class[] {
-		    Util.loadClass("javax.transaction.HeuresticMixexException", null, null),
+		    Util.loadClass("javax.transaction.HeuresticMixedException", null, null),
 		    org.omg.CosTransactions.HeuristicMixed.class,
 
 		    Util.loadClass("javax.transaction.HeuristicRollbackException", null, null),
@@ -918,7 +930,7 @@
             javax.transaction.TransactionRolledbackException.class,
 
             org.omg.CORBA.INVALID_TRANSACTION.class,
-            javax.transaction.InvalidTransactionException.class };
+            javax.transaction.InvalidTransactionException.class};
 
     static final java.util.Map CORBA_TO_RMI_MAP = new java.util.HashMap();
 

Modified: incubator/yoko/trunk/rmi-spec/src/main/java/org/apache/yoko/rmispec/util/UtilLoader.java
URL: http://svn.apache.org/viewvc/incubator/yoko/trunk/rmi-spec/src/main/java/org/apache/yoko/rmispec/util/UtilLoader.java?view=diff&rev=514660&r1=514659&r2=514660
==============================================================================
--- incubator/yoko/trunk/rmi-spec/src/main/java/org/apache/yoko/rmispec/util/UtilLoader.java (original)
+++ incubator/yoko/trunk/rmi-spec/src/main/java/org/apache/yoko/rmispec/util/UtilLoader.java Mon Mar  5 04:53:32 2007
@@ -1,29 +1,29 @@
 /**
-*
-* 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.
-*/
+ *
+ * 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.yoko.rmispec.util;
 
-import java.lang.reflect.InvocationTargetException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
 import java.util.logging.Logger;
 
 public class UtilLoader {
@@ -32,7 +32,7 @@
     // Note: this field must be declared before the static intializer that calls Util.loadClass
     // since that method will call loadClass0 which uses this field... if it is below the static
     // initializer the _secman field will be null
-    private static final SecMan _secman = new SecMan();
+    private static final SecMan _secman = getSecMan();
 
     static public Class loadClass(String name, String codebase, ClassLoader loader)
             throws ClassNotFoundException {
@@ -75,7 +75,7 @@
                 logger.finer("trying RMIClassLoader");
 
                 URLClassLoader url_loader = new URLClassLoader(
-                        new URL[] { new URL(codebase) }, loader);
+                        new URL[]{new URL(codebase)}, loader);
 
                 result = url_loader.loadClass(name);
 
@@ -109,7 +109,7 @@
 
         } else {
 
-            codebase = (String)AccessController.doPrivileged(new GetSystemPropertyAction("java.rmi.server.codebase"));
+            codebase = (String) AccessController.doPrivileged(new GetSystemPropertyAction("java.rmi.server.codebase"));
 
             if (codebase != null) {
                 try {
@@ -158,6 +158,20 @@
         public Class[] getClassContext() {
             return super.getClassContext();
         }
+    }
+
+    private static SecMan getSecMan() {
+        try {
+            return (SecMan) AccessController
+                    .doPrivileged(new java.security.PrivilegedExceptionAction() {
+                        public Object run() {
+                            return new SecMan();
+                        }
+                    });
+        } catch (PrivilegedActionException e) {
+            throw new RuntimeException(e);
+        }
+
     }
 }