KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > iiop > csiv2 > CSIv2IORInterceptor


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.iiop.csiv2;
23
24 import org.omg.CORBA.Any JavaDoc;
25 import org.omg.CORBA.ORB JavaDoc;
26 import org.omg.CORBA.LocalObject JavaDoc;
27 import org.omg.CORBA.BAD_PARAM JavaDoc;
28 import org.omg.CSIIOP.Integrity;
29 import org.omg.CSIIOP.DetectReplay;
30 import org.omg.CSIIOP.DetectMisordering;
31 import org.omg.PortableInterceptor.IORInfo JavaDoc;
32 import org.omg.PortableInterceptor.IORInterceptor JavaDoc;
33
34 import org.omg.IOP.Codec JavaDoc;
35 import org.omg.IOP.CodecPackage.InvalidTypeForEncoding JavaDoc;
36 import org.omg.IOP.TAG_INTERNET_IOP JavaDoc;
37 import org.omg.IOP.TaggedComponent JavaDoc;
38
39 import org.omg.SSLIOP.SSL;
40 import org.omg.SSLIOP.SSLHelper;
41 import org.omg.SSLIOP.TAG_SSL_SEC_TRANS;
42
43 import org.jboss.iiop.CorbaORBService;
44 import org.jboss.logging.Logger;
45 import org.jboss.metadata.IorSecurityConfigMetaData;
46
47 /**
48  * Implements an <code>org.omg.PortableInterceptor.IORInterceptor</code>
49  * that CSIv2 info to an IOR.
50  *
51  * @author Dimitris.Andreadis@jboss.org
52  * @version $Revision: 37459 $
53  */

54 public class CSIv2IORInterceptor
55    extends LocalObject JavaDoc
56    implements IORInterceptor JavaDoc
57 {
58    private static final Logger log = Logger.getLogger(CSIv2IORInterceptor.class);
59    /**
60     * The minimum set of security options supported by the SSL mechanism
61     * (These options cannot be turned off, so they are always supported.)
62     */

63    private static final int MIN_SSL_OPTIONS = Integrity.value |
64       DetectReplay.value |
65       DetectMisordering.value;
66
67    private TaggedComponent JavaDoc defaultSSLComponent;
68    private TaggedComponent JavaDoc defaultCSIComponent;
69
70    public CSIv2IORInterceptor(Codec JavaDoc codec)
71    {
72       int sslPort = CorbaORBService.getTheActualSSLPort();
73       try
74       {
75          // Build default SSL component with minimum SSL options
76
SSL ssl = new SSL((short) MIN_SSL_OPTIONS, /* supported options */
77             (short) 0, /* required options */
78             (short) sslPort);
79          ORB JavaDoc orb = ORB.init();
80          Any JavaDoc any = orb.create_any();
81          SSLHelper.insert(any, ssl);
82          byte[] componentData = codec.encode_value(any);
83          defaultSSLComponent = new TaggedComponent JavaDoc(TAG_SSL_SEC_TRANS.value,
84             componentData);
85
86          IorSecurityConfigMetaData metadata = new IorSecurityConfigMetaData();
87          defaultCSIComponent = CSIv2Util.createSecurityTaggedComponent(metadata,
88             codec, sslPort, orb);
89       }
90       catch (InvalidTypeForEncoding JavaDoc e)
91       {
92          log.warn("Caught unexcepted exception while encoding SSL component", e);
93          throw new RuntimeException JavaDoc(e);
94       }
95    }
96
97    // org.omg.PortableInterceptor.IORInterceptor operations -------------------
98

99    public String JavaDoc name()
100    {
101       return CSIv2IORInterceptor.class.getName();
102    }
103
104    public void destroy()
105    {
106    }
107
108    // called for all IORs created from this ORB
109
public void establish_components(IORInfo JavaDoc info)
110    {
111       // check if CSIv2 policy is in effect for this IOR
112
CSIv2Policy csiv2Policy = null;
113
114       try
115       {
116          csiv2Policy = (CSIv2Policy) info.get_effective_policy(CSIv2Policy.TYPE);
117       }
118       catch (BAD_PARAM JavaDoc e)
119       {
120          log.debug("No CSIv2Policy");
121       }
122       catch (Exception JavaDoc e)
123       {
124          log.debug("Error fetching CSIv2Policy", e);
125       }
126
127       if (csiv2Policy != null)
128       {
129          // if csiv2Policy effective, stuff a copy of the TaggedComponents
130
// already created by the CSIv2Policy into the IOR's IIOP profile
131
TaggedComponent JavaDoc sslComponent =
132             csiv2Policy.getSSLTaggedComponent();
133          if (sslComponent != null &&
134              CorbaORBService.getSSLComponentsEnabledFlag() == true)
135          {
136             info.add_ior_component_to_profile(sslComponent,
137                                               TAG_INTERNET_IOP.value);
138          }
139          TaggedComponent JavaDoc csiv2Component =
140             csiv2Policy.getSecurityTaggedComponent();
141          if (csiv2Component != null)
142          {
143             info.add_ior_component_to_profile(csiv2Component,
144                TAG_INTERNET_IOP.value);
145          }
146       }
147       else
148       {
149          if (defaultSSLComponent != null &&
150              CorbaORBService.getSSLComponentsEnabledFlag() == true)
151          {
152             // otherwise stuff the default SSL component (with the minimum
153
// set of SSL options) into the IOR's IIOP profile
154
info.add_ior_component_to_profile(defaultSSLComponent,
155                                               TAG_INTERNET_IOP.value);
156          }
157          if (defaultCSIComponent != null)
158          {
159             // and stuff the default CSI component (with the minimum
160
// set of CSI options) into the IOR's IIOP profile
161
info.add_ior_component_to_profile(defaultCSIComponent,
162                                               TAG_INTERNET_IOP.value);
163          }
164       }
165
166       return;
167    }
168 }
169
Popular Tags