src/share/classes/com/sun/corba/se/impl/io/ValueHandlerImpl.java

changeset 205
b2fff4b7e8cd
parent 158
91006f157c46
child 443
3c73273667ae
     1.1 --- a/src/share/classes/com/sun/corba/se/impl/io/ValueHandlerImpl.java	Fri Sep 24 16:38:05 2010 -0700
     1.2 +++ b/src/share/classes/com/sun/corba/se/impl/io/ValueHandlerImpl.java	Fri Sep 24 22:42:14 2010 -0700
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1998, 2004, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -32,32 +32,22 @@
    1.11  package com.sun.corba.se.impl.io;
    1.12  
    1.13  import javax.rmi.CORBA.Util;
    1.14 -import javax.rmi.PortableRemoteObject;
    1.15  
    1.16  import java.util.Hashtable;
    1.17 -import java.util.Stack;
    1.18  import java.io.IOException;
    1.19 -import java.util.EmptyStackException;
    1.20  
    1.21 -import com.sun.corba.se.impl.util.Utility;
    1.22 -import com.sun.corba.se.impl.io.IIOPInputStream;
    1.23 -import com.sun.corba.se.impl.io.IIOPOutputStream;
    1.24  import com.sun.corba.se.impl.util.RepositoryId;
    1.25  import com.sun.corba.se.impl.util.Utility;
    1.26  
    1.27  import org.omg.CORBA.TCKind;
    1.28  
    1.29 -import org.omg.CORBA.MARSHAL;
    1.30 -import org.omg.CORBA.BAD_PARAM;
    1.31 -import org.omg.CORBA.CompletionStatus;
    1.32  import org.omg.CORBA.portable.IndirectionException;
    1.33  import com.sun.org.omg.SendingContext.CodeBase;
    1.34  import com.sun.org.omg.SendingContext.CodeBaseHelper;
    1.35  
    1.36  import java.security.AccessController;
    1.37  import java.security.PrivilegedAction;
    1.38 -
    1.39 -import com.sun.corba.se.impl.io.IIOPInputStream.ActiveRecursionManager;
    1.40 +import java.security.PrivilegedExceptionAction;
    1.41  
    1.42  import com.sun.corba.se.spi.logging.CORBALogDomains;
    1.43  import com.sun.corba.se.impl.logging.OMGSystemException;
    1.44 @@ -809,65 +799,163 @@
    1.45          return "com.sun.corba.se.impl.io.IIOPOutputStream";
    1.46      }
    1.47  
    1.48 -    private com.sun.corba.se.impl.io.IIOPOutputStream createOutputStream() {
    1.49 -        return (com.sun.corba.se.impl.io.IIOPOutputStream)AccessController.doPrivileged(
    1.50 -            new StreamFactory(getOutputStreamClassName()));
    1.51 +   private IIOPOutputStream createOutputStream() {
    1.52 +        final String name = getOutputStreamClassName();
    1.53 +        try {
    1.54 +             IIOPOutputStream stream = createOutputStreamBuiltIn(name);
    1.55 +             if (stream != null) {
    1.56 +                 return stream;
    1.57 +             }
    1.58 +             return createCustom(IIOPOutputStream.class, name);
    1.59 +        } catch (Throwable t) {
    1.60 +            // Throw exception under the carpet.
    1.61 +            InternalError ie = new InternalError(
    1.62 +                "Error loading " + name
    1.63 +            );
    1.64 +                ie.initCause(t);
    1.65 +                throw ie;
    1.66 +        }
    1.67 +    }
    1.68 +
    1.69 +    /**
    1.70 +     * Construct a built in implementation with priveleges.
    1.71 +     * Returning null indicates a non-built is specified.
    1.72 +     */
    1.73 +    private IIOPOutputStream createOutputStreamBuiltIn(
    1.74 +        final String name
    1.75 +    ) throws Throwable {
    1.76 +        try {
    1.77 +            return AccessController.doPrivileged(
    1.78 +                new PrivilegedExceptionAction<IIOPOutputStream>() {
    1.79 +                    public IIOPOutputStream run() throws IOException {
    1.80 +                        return createOutputStreamBuiltInNoPriv(name);
    1.81 +                    }
    1.82 +                }
    1.83 +            );
    1.84 +        } catch (java.security.PrivilegedActionException exc) {
    1.85 +            throw exc.getCause();
    1.86 +        }
    1.87 +    }
    1.88 +
    1.89 +    /**
    1.90 +     * Returning null indicates a non-built is specified.
    1.91 +     */
    1.92 +    private IIOPOutputStream createOutputStreamBuiltInNoPriv(
    1.93 +        final String name
    1.94 +    ) throws IOException {
    1.95 +        return
    1.96 +            name.equals(
    1.97 +                IIOPOutputStream
    1.98 +                    .class.getName()
    1.99 +            ) ?
   1.100 +            new IIOPOutputStream() :
   1.101 +
   1.102 +            name.equals(
   1.103 +                com.sun.corba.se.impl.orbutil.IIOPOutputStream_1_3
   1.104 +                    .class.getName()
   1.105 +            ) ?
   1.106 +            new com.sun.corba.se.impl.orbutil.IIOPOutputStream_1_3() :
   1.107 +
   1.108 +            name.equals(
   1.109 +                com.sun.corba.se.impl.orbutil.IIOPOutputStream_1_3_1
   1.110 +                    .class.getName()
   1.111 +            ) ?
   1.112 +            new com.sun.corba.se.impl.orbutil.IIOPOutputStream_1_3_1() :
   1.113 +
   1.114 +            null;
   1.115      }
   1.116  
   1.117      protected String getInputStreamClassName() {
   1.118          return "com.sun.corba.se.impl.io.IIOPInputStream";
   1.119      }
   1.120  
   1.121 -    private com.sun.corba.se.impl.io.IIOPInputStream createInputStream() {
   1.122 -        return (com.sun.corba.se.impl.io.IIOPInputStream)AccessController.doPrivileged(
   1.123 -            new StreamFactory(getInputStreamClassName()));
   1.124 +    private IIOPInputStream createInputStream() {
   1.125 +        final String name = getInputStreamClassName();
   1.126 +        try {
   1.127 +             IIOPInputStream stream = createInputStreamBuiltIn(name);
   1.128 +             if (stream != null) {
   1.129 +                 return stream;
   1.130 +             }
   1.131 +             return createCustom(IIOPInputStream.class, name);
   1.132 +        } catch (Throwable t) {
   1.133 +            // Throw exception under the carpet.
   1.134 +            InternalError ie = new InternalError(
   1.135 +                "Error loading " + name
   1.136 +            );
   1.137 +                ie.initCause(t);
   1.138 +                throw ie;
   1.139 +        }
   1.140      }
   1.141  
   1.142      /**
   1.143 -     * Instantiates a class of the given name using the system ClassLoader
   1.144 -     * as part of a PrivilegedAction.
   1.145 -     *
   1.146 -     * It's private final so hopefully people can't grab it outside of
   1.147 -     * this class.
   1.148 -     *
   1.149 -     * If you're worried that someone could subclass ValueHandlerImpl,
   1.150 -     * install his own streams, and snoop what's on the wire:
   1.151 -     * Someone can do that only if he's allowed to use the feature
   1.152 -     * of installing his own javax.rmi.CORBA.Util delegate (via a
   1.153 -     * JVM property or orb.properties file, read the first time the
   1.154 -     * Util class is used).  If he can do that, he can snoop
   1.155 -     * anything on the wire, anyway, without abusing the
   1.156 -     * StreamFactory class.
   1.157 +     * Construct a built in implementation with priveleges.
   1.158 +     * Returning null indicates a non-built is specified.
   1.159       */
   1.160 -    private static final class StreamFactory implements PrivilegedAction {
   1.161 -        private String className;
   1.162 +     private IIOPInputStream createInputStreamBuiltIn(
   1.163 +         final String name
   1.164 +     ) throws Throwable {
   1.165 +         try {
   1.166 +             return AccessController.doPrivileged(
   1.167 +                 new PrivilegedExceptionAction<IIOPInputStream>() {
   1.168 +                     public IIOPInputStream run() throws IOException {
   1.169 +                         return createInputStreamBuiltInNoPriv(name);
   1.170 +                     }
   1.171 +                 }
   1.172 +             );
   1.173 +         } catch (java.security.PrivilegedActionException exc) {
   1.174 +             throw exc.getCause();
   1.175 +         }
   1.176 +     }
   1.177  
   1.178 -        public StreamFactory (String _className) {
   1.179 -            className = _className;
   1.180 -        }
   1.181 +     /**
   1.182 +      * Returning null indicates a non-built is specified.
   1.183 +      */
   1.184 +     private IIOPInputStream createInputStreamBuiltInNoPriv(
   1.185 +         final String name
   1.186 +     ) throws IOException {
   1.187 +         return
   1.188 +             name.equals(
   1.189 +                 IIOPInputStream
   1.190 +                     .class.getName()
   1.191 +             ) ?
   1.192 +             new IIOPInputStream() :
   1.193  
   1.194 -        public Object run() {
   1.195 -            try {
   1.196 -                // Note: We must use the system ClassLoader here
   1.197 -                // since we want to load classes outside of the
   1.198 -                // core JDK when running J2EE Pure ORB and
   1.199 -                // talking to Kestrel.
   1.200 +             name.equals(
   1.201 +                 com.sun.corba.se.impl.orbutil.IIOPInputStream_1_3
   1.202 +                     .class.getName()
   1.203 +             ) ?
   1.204 +             new com.sun.corba.se.impl.orbutil.IIOPInputStream_1_3() :
   1.205 +
   1.206 +             name.equals(
   1.207 +                 com.sun.corba.se.impl.orbutil.IIOPInputStream_1_3_1
   1.208 +                     .class.getName()
   1.209 +             ) ?
   1.210 +             new com.sun.corba.se.impl.orbutil.IIOPInputStream_1_3_1() :
   1.211 +
   1.212 +             null;
   1.213 +     }
   1.214 +
   1.215 +     /**
   1.216 +      * Create a custom implementation without privileges.
   1.217 +      */
   1.218 +     private <T> T createCustom(
   1.219 +         final Class<T> type, final String className
   1.220 +     ) throws Throwable {
   1.221 +           // Note: We use the thread context or system ClassLoader here
   1.222 +           // since we want to load classes outside of the
   1.223 +           // core JDK when running J2EE Pure ORB and
   1.224 +           // talking to Kestrel.
   1.225                  ClassLoader cl = Thread.currentThread().getContextClassLoader();
   1.226                  if (cl == null)
   1.227                      cl = ClassLoader.getSystemClassLoader();
   1.228  
   1.229 -                Class streamClass = cl.loadClass(className);
   1.230 +                Class<?> clazz = cl.loadClass(className);
   1.231 +                Class<? extends T> streamClass = clazz.asSubclass(type);
   1.232  
   1.233                  // Since the ClassLoader should cache the class, this isn't
   1.234                  // as expensive as it looks.
   1.235                  return streamClass.newInstance();
   1.236  
   1.237 -            } catch(Throwable t) {
   1.238 -                InternalError ie = new InternalError( "Error loading " + className ) ;
   1.239 -                ie.initCause( t ) ;
   1.240 -                throw ie ;
   1.241 -            }
   1.242 -        }
   1.243      }
   1.244  
   1.245      /**

mercurial