maguro      2005/04/12 17:29:56

  Modified:    modules/core/src/java/org/openejb/corba/sunorb
                        SunORBConfigAdapter.java
  Added:       modules/core/src/java/org/openejb/corba/sunorb
                        OpenEJBORB.java OpenEJBPOA.java
  Log:

  The primary port of the IOR must be zero if the CSI component contains a 
secure transport mechanism.  Much of this is to work around the Sun ORB.
  
  Revision  Changes    Path
  1.5       +57 -24    
openejb/modules/core/src/java/org/openejb/corba/sunorb/SunORBConfigAdapter.java
  
  Index: SunORBConfigAdapter.java
  ===================================================================
  RCS file: 
/home/projects/openejb/scm/openejb/modules/core/src/java/org/openejb/corba/sunorb/SunORBConfigAdapter.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SunORBConfigAdapter.java  12 Apr 2005 15:27:49 -0000      1.4
  +++ SunORBConfigAdapter.java  12 Apr 2005 21:29:56 -0000      1.5
  @@ -52,6 +52,7 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.omg.CORBA.ORB;
   import org.omg.CSIIOP.EstablishTrustInClient;
   import org.omg.Security.Confidentiality;
   import org.omg.Security.EstablishTrustInTarget;
  @@ -95,8 +96,8 @@
           return (String[]) list.toArray(new String[list.size()]);
       }
   
  -    public Properties translateToProps(TSSConfig config) throws 
ConfigException {
  -        Properties props = new Properties();
  +    public Properties translateToProps(TSSConfig config, Properties props) 
throws ConfigException {
  +        Properties result = new Properties();
   
           String supProp = "";
           String reqProp = "";
  @@ -110,10 +111,6 @@
                       supProp = "Integrity";
                       reqProp = "Integrity";
   
  -                    props.put("com.sun.CORBA.connection.ORBListenSocket", 
"IIOP_SSL:" + Short.toString(sslConfig.getPort()));
  -//                    props.put("org.omg.CORBA.ORBInitialPort", "0");
  -                    props.put("com.sun.CORBA.ORBServerPort", "0");
  -
                       if ((supports & NoProtection.value) != 0) {
                           supProp += ",NoProtection";
                       }
  @@ -145,28 +142,58 @@
           
System.setProperty("org.openejb.corba.ssl.SocketProperties.supports", supProp);
           
System.setProperty("org.openejb.corba.ssl.SocketProperties.requires", reqProp);
   
  -        props.put("com.sun.CORBA.connection.ORBSocketFactoryClass", 
"org.openejb.corba.sunorb.OpenEJBSocketFactory");
  -        
props.put("org.omg.PortableInterceptor.ORBInitializerClass.org.openejb.corba.transaction.TransactionInitializer",
 "");
  -        
props.put("org.omg.PortableInterceptor.ORBInitializerClass.org.openejb.corba.security.SecurityInitializer",
 "");
  -        
props.put("org.omg.PortableInterceptor.ORBInitializerClass.org.openejb.corba.sunorb.SunORBInitializer",
 "");
  +        result.put("com.sun.CORBA.connection.ORBSocketFactoryClass", 
"org.openejb.corba.sunorb.OpenEJBSocketFactory");
  +        
result.put("org.omg.PortableInterceptor.ORBInitializerClass.org.openejb.corba.transaction.TransactionInitializer",
 "");
  +        
result.put("org.omg.PortableInterceptor.ORBInitializerClass.org.openejb.corba.security.SecurityInitializer",
 "");
  +        
result.put("org.omg.PortableInterceptor.ORBInitializerClass.org.openejb.corba.sunorb.SunORBInitializer",
 "");
   
           if (log.isDebugEnabled()) {
               log.debug("translateToProps(TSSConfig)");
  -            for (Enumeration iter = props.keys(); iter.hasMoreElements();) {
  +            for (Enumeration iter = result.keys(); iter.hasMoreElements();) {
                   String key = (String) iter.nextElement();
  -                log.debug(key + " = " + props.getProperty(key));
  +                log.debug(key + " = " + result.getProperty(key));
               }
           }
   
  -        return props;
  +        result.putAll(props);
  +
  +        return result;
  +    }
  +
  +    /**
  +     * This post processing is performed to override the default listening
  +     * end points so that only SSL ports are opened if the TSS config is
  +     * configured to use SSL
  +     *
  +     * @param config Target Security Server configuration
  +     * @param orb    the ORB to be post processed
  +     * @throws ConfigException thrown if any error occurs
  +     */
  +    public void postProcess(TSSConfig config, ORB orb) throws 
ConfigException {
  +        if (config != null) {
  +            TSSTransportMechConfig transportMech = 
config.getTransport_mech();
  +            if (transportMech != null) {
  +                if (transportMech instanceof TSSSSLTransportConfig) {
  +                    TSSSSLTransportConfig sslConfig = 
(TSSSSLTransportConfig) transportMech;
  +                    OpenEJBORB o = (OpenEJBORB) orb;
  +
  +                    try {
  +                        
o.getServerGIOP().getEndpoint(OpenEJBSocketFactory.IIOP_SSL, 
sslConfig.getPort(), null);
  +                    } catch (Throwable e) {
  +                        log.error(e);
  +                        throw new ConfigException(e);
  +                    }
  +                }
  +            }
  +        }
       }
   
       public String[] translateToArgs(CSSConfig config, List args) throws 
ConfigException {
           return (String[]) args.toArray(new String[args.size()]);
       }
   
  -    public Properties translateToProps(CSSConfig config) throws 
ConfigException {
  -        Properties props = new Properties();
  +    public Properties translateToProps(CSSConfig config, Properties props) 
throws ConfigException {
  +        Properties result = new Properties();
   
           String supProp = "";
           String reqProp = "";
  @@ -212,22 +239,28 @@
               supProp = "NoProtection";
               reqProp = "NoProtection";
           }
  +
           
System.setProperty("org.openejb.corba.ssl.SocketProperties.supports", supProp);
           
System.setProperty("org.openejb.corba.ssl.SocketProperties.requires", reqProp);
   
  -        props.put("com.sun.CORBA.connection.ORBSocketFactoryClass", 
"org.openejb.corba.sunorb.OpenEJBSocketFactory");
  -        
props.put("org.omg.PortableInterceptor.ORBInitializerClass.org.openejb.corba.transaction.TransactionInitializer",
 "");
  -        
props.put("org.omg.PortableInterceptor.ORBInitializerClass.org.openejb.corba.security.SecurityInitializer",
 "");
  -        
props.put("org.omg.PortableInterceptor.ORBInitializerClass.org.openejb.corba.sunorb.SunORBInitializer",
 "");
  +        result.put("com.sun.CORBA.connection.ORBSocketFactoryClass", 
"org.openejb.corba.sunorb.OpenEJBSocketFactory");
  +        
result.put("org.omg.PortableInterceptor.ORBInitializerClass.org.openejb.corba.transaction.TransactionInitializer",
 "");
  +        
result.put("org.omg.PortableInterceptor.ORBInitializerClass.org.openejb.corba.security.SecurityInitializer",
 "");
  +        
result.put("org.omg.PortableInterceptor.ORBInitializerClass.org.openejb.corba.sunorb.SunORBInitializer",
 "");
   
           if (log.isDebugEnabled()) {
               log.debug("translateToProps(CSSConfig)");
  -            for (Enumeration iter = props.keys(); iter.hasMoreElements();) {
  +            for (Enumeration iter = result.keys(); iter.hasMoreElements();) {
                   String key = (String) iter.nextElement();
  -                log.debug(key + " = " + props.getProperty(key));
  +                log.debug(key + " = " + result.getProperty(key));
               }
           }
   
  -        return props;
  +        result.putAll(props);
  +
  +        return result;
  +    }
  +
  +    public void postProcess(CSSConfig config, ORB orb) throws 
ConfigException {
       }
   }
  
  
  
  1.1                  
openejb/modules/core/src/java/org/openejb/corba/sunorb/OpenEJBORB.java
  
  Index: OpenEJBORB.java
  ===================================================================
  /**
   * Redistribution and use of this software and associated documentation
   * ("Software"), with or without modification, are permitted provided
   * that the following conditions are met:
   *
   * 1. Redistributions of source code must retain copyright
   *    statements and notices.  Redistributions must also contain a
   *    copy of this document.
   *
   * 2. Redistributions in binary form must reproduce the
   *    above copyright notice, this list of conditions and the
   *    following disclaimer in the documentation and/or other
   *    materials provided with the distribution.
   *
   * 3. The name "OpenEJB" must not be used to endorse or promote
   *    products derived from this Software without prior written
   *    permission of The OpenEJB Group.  For written permission,
   *    please contact [EMAIL PROTECTED]
   *
   * 4. Products derived from this Software may not be called "OpenEJB"
   *    nor may "OpenEJB" appear in their names without prior written
   *    permission of The OpenEJB Group. OpenEJB is a registered
   *    trademark of The OpenEJB Group.
   *
   * 5. Due credit should be given to the OpenEJB Project
   *    (http://openejb.sf.net/).
   *
   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
   * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * Copyright 2005 (C) The OpenEJB Group. All Rights Reserved.
   *
   * $Id: OpenEJBORB.java,v 1.1 2005/04/12 21:29:56 maguro Exp $
   */
  package org.openejb.corba.sunorb;
  
  import com.sun.corba.se.internal.Interceptors.PIORB;
  import com.sun.corba.se.internal.POA.POAImpl;
  import com.sun.corba.se.internal.POA.POAManagerImpl;
  import com.sun.corba.se.internal.POA.Policies;
  import com.sun.corba.se.internal.orbutil.ORBConstants;
  
  
  /**
   * This class is used to assist in the interception of IOR creation.
   *
   * @version $Revision: 1.1 $ $Date: 2005/04/12 21:29:56 $
   * @see OpenEJBPOA
   */
  public class OpenEJBORB extends PIORB {
  
      protected POAImpl makeRootPOA() {
  
          POAManagerImpl poaManager = new POAManagerImpl(this);
          POAImpl result = new OpenEJBPOA(ORBConstants.ROOT_POA_NAME, 
poaManager, Policies.rootPOAPolicies, null, null, this);
  
          return result;
      }
  
  }
  
  
  
  1.1                  
openejb/modules/core/src/java/org/openejb/corba/sunorb/OpenEJBPOA.java
  
  Index: OpenEJBPOA.java
  ===================================================================
  /**
   * Redistribution and use of this software and associated documentation
   * ("Software"), with or without modification, are permitted provided
   * that the following conditions are met:
   *
   * 1. Redistributions of source code must retain copyright
   *    statements and notices.  Redistributions must also contain a
   *    copy of this document.
   *
   * 2. Redistributions in binary form must reproduce the
   *    above copyright notice, this list of conditions and the
   *    following disclaimer in the documentation and/or other
   *    materials provided with the distribution.
   *
   * 3. The name "OpenEJB" must not be used to endorse or promote
   *    products derived from this Software without prior written
   *    permission of The OpenEJB Group.  For written permission,
   *    please contact [EMAIL PROTECTED]
   *
   * 4. Products derived from this Software may not be called "OpenEJB"
   *    nor may "OpenEJB" appear in their names without prior written
   *    permission of The OpenEJB Group. OpenEJB is a registered
   *    trademark of The OpenEJB Group.
   *
   * 5. Due credit should be given to the OpenEJB Project
   *    (http://openejb.sf.net/).
   *
   * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
   * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
   * OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * Copyright 2005 (C) The OpenEJB Group. All Rights Reserved.
   *
   * $Id: OpenEJBPOA.java,v 1.1 2005/04/12 21:29:56 maguro Exp $
   */
  package org.openejb.corba.sunorb;
  
  import com.sun.corba.se.internal.POA.POAImpl;
  import com.sun.corba.se.internal.POA.POAManagerImpl;
  import com.sun.corba.se.internal.POA.POAORB;
  import com.sun.corba.se.internal.POA.Policies;
  import com.sun.corba.se.internal.corba.CORBAObjectImpl;
  import com.sun.corba.se.internal.core.ClientSubcontract;
  import com.sun.corba.se.internal.core.IOR;
  import com.sun.corba.se.internal.core.StandardIIOPProfileTemplate;
  import com.sun.corba.se.internal.ior.IIOPAddressImpl;
  import com.sun.corba.se.internal.ior.IORTemplate;
  import com.sun.corba.se.internal.ior.ObjectId;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.omg.CORBA.portable.Delegate;
  import org.omg.CORBA.portable.ObjectImpl;
  import org.omg.PortableServer.AdapterActivator;
  
  import org.openejb.corba.security.ServerPolicy;
  import org.openejb.corba.security.ServerPolicyFactory;
  
  
  /**
   * This class basically intercepts the creation of IORs and checks to see if
   * CSIv2 transport security has been defined.  If it has, then the port of the
   * profile must be zero, indicating that only the transport defined in the
   * CSIv2 component should be used.
   *
   * @version $Revision: 1.1 $ $Date: 2005/04/12 21:29:56 $
   */
  public class OpenEJBPOA extends POAImpl {
  
      private final static Log log = LogFactory.getLog(OpenEJBPOA.class);
  
      public OpenEJBPOA(String name, POAManagerImpl manager, Policies policies, 
POAImpl parent, AdapterActivator activator, POAORB orb) {
          super(name, manager, policies, parent, activator, orb);
  
          if (log.isDebugEnabled()) log.debug("<init>");
      }
  
      public POAImpl makePOA(String name, POAManagerImpl manager, Policies 
policies, POAImpl parent, AdapterActivator activator, POAORB orb) {
          if (log.isDebugEnabled()) log.debug("makePOA()");
  
          return new OpenEJBPOA(name, manager, policies, parent, activator, 
orb);
      }
  
      protected org.omg.CORBA.Object makeObjectReference(String repId, byte[] 
id, IORTemplate iortemp, int scid) {
  
          if (log.isDebugEnabled()) log.debug("makeObjectReference()");
  
          IORTemplate template = null;
  
          ServerPolicy policy = (ServerPolicy) 
get_effective_policy(ServerPolicyFactory.POLICY_TYPE);
          if (policy != null
              && policy.getConfig() != null
              && policy.getConfig().getTransport_mech().getRequires() > 0)
          {
              if (log.isDebugEnabled()) log.debug("Found security policy");
  
              template = new IORTemplate();
  
              for (int i = 0; i < iortemp.size(); i++) {
                  Object obj = iortemp.get(i);
  
                  if (obj instanceof StandardIIOPProfileTemplate) {
                      StandardIIOPProfileTemplate stdTemp = 
(StandardIIOPProfileTemplate) obj;
                      IIOPAddressImpl primaryAddress = (IIOPAddressImpl) 
stdTemp.getPrimaryAddress();
  
                      StandardIIOPProfileTemplate newTemp = new 
StandardIIOPProfileTemplate(new IIOPAddressImpl(primaryAddress.getHost(), 0),
                                                                                
            stdTemp.getMajorVersion(), stdTemp.getMinorVersion(),
                                                                                
            stdTemp.getObjectKeyTemplate(),
                                                                                
            null,
                                                                                
            orb);
                      newTemp.clear();
                      newTemp.addAll(stdTemp);
  
                      if (stdTemp.isImmutable()) newTemp.makeImmutable();
  
                      obj = newTemp;
                  }
  
                  template.add(obj);
              }
          } else {
              template = iortemp;
          }
  
          IOR ior = new IOR(orb, repId, template, new ObjectId(id));
  
          ClientSubcontract csub = 
orb.getSubcontractRegistry().getClientSubcontract(scid);
          csub.setOrb(orb);
          csub.unmarshal(ior);
  
          ObjectImpl o = new CORBAObjectImpl();
          o._set_delegate((Delegate) csub);
  
          return o;
      }
  }
  
  
  

Reply via email to