KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > iiop > TxSecIORInterceptor


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.iiop;
25
26 import java.util.logging.*;
27 import java.util.Properties JavaDoc;
28 import java.io.IOException JavaDoc;
29
30 import org.omg.CORBA.Any JavaDoc;
31 import org.omg.CORBA.ORB JavaDoc;
32 import org.omg.CORBA.INV_POLICY JavaDoc;
33 import org.omg.CORBA.INTERNAL JavaDoc;
34 import org.omg.IOP.Codec JavaDoc;
35 import org.omg.IOP.Encoding JavaDoc;
36 import org.omg.IOP.TaggedComponent JavaDoc;
37 import org.omg.PortableInterceptor.IORInfo JavaDoc;
38
39 import org.omg.CosTransactions.*;
40 import org.omg.CosTSInteroperation.TAG_OTS_POLICY;
41 import org.omg.CosTSInteroperation.TAG_INV_POLICY;
42
43 import com.sun.logging.*;
44 import com.sun.enterprise.deployment.EjbDescriptor;
45 import com.sun.enterprise.util.ORBManager;
46 import com.sun.enterprise.util.Utility;
47 import com.sun.enterprise.iiop.ASORBUtilities;
48
49
50 public class TxSecIORInterceptor extends org.omg.CORBA.LocalObject JavaDoc
51                     implements org.omg.PortableInterceptor.IORInterceptor JavaDoc {
52     
53
54     private static Logger _logger=null;
55
56     static {
57     _logger=LogDomains.getLogger(LogDomains.CORBA_LOGGER);
58     }
59
60     private Codec JavaDoc codec;
61     
62     
63     public TxSecIORInterceptor(Codec JavaDoc c) {
64         codec = c;
65     }
66     
67     public void destroy() {
68     }
69     
70     public String JavaDoc name() {
71         return "TxSecIORInterceptor";
72     }
73     
74     // Note: this is called for all remote refs created from this ORB,
75
// including EJBs and COSNaming objects.
76
public void establish_components(IORInfo JavaDoc iorInfo) {
77         try {
78         _logger.log(Level.FINE,
79             "TxSecIORInterceptor.establish_components->:");
80
81         // Add OTS tagged components. These are always the same for all EJBs
82
OTSPolicy otsPolicy = null;
83         try {
84         otsPolicy = (OTSPolicy)iorInfo.get_effective_policy(
85                    POARemoteReferenceFactory.OTS_POLICY_TYPE);
86         } catch ( INV_POLICY JavaDoc ex ) {
87         _logger.log(Level.FINE,
88                 "TxSecIORInterceptor.establish_components: OTSPolicy not present");
89         }
90         if ( otsPolicy != null ) {
91         addOTSComponents(iorInfo);
92         }
93
94         // Find the CSIv2 policy in effect for this IOR kind
95
CSIv2Policy csiv2Policy = null;
96         try {
97         csiv2Policy = (CSIv2Policy)iorInfo.get_effective_policy(
98                    POARemoteReferenceFactory.CSIv2_POLICY_TYPE);
99         // REVISIT - this did not log an exception when missing.
100
} catch ( INV_POLICY JavaDoc ex ) {
101         _logger.log(Level.FINE,
102                 "TxSecIORInterceptor.establish_components: CSIv2Policy not present");
103         }
104
105         // Add CSIv2 tagged component for this EJB type.
106
if(_logger.isLoggable(Level.FINE)) {
107         _logger.log(Level.FINE,
108                 "TxSecIORInterceptor.establish_components: CSIv2Policy: " + csiv2Policy);
109         }
110         addCSIv2Components(iorInfo, csiv2Policy);
111
112         } catch (Exception JavaDoc e) {
113             _logger.log(Level.WARNING,"Exception in establish_components", e);
114         } finally {
115         _logger.log(Level.FINE,
116             "TxSecIORInterceptor.establish_components<-:");
117     }
118     }
119
120     private void addOTSComponents(IORInfo JavaDoc iorInfo)
121     {
122         short invPolicyValue = SHARED.value;
123         short otsPolicyValue = ADAPTS.value;
124         
125         Any JavaDoc otsAny = ORB.init().create_any();
126         Any JavaDoc invAny = ORB.init().create_any();
127         
128         otsAny.insert_short(otsPolicyValue);
129         invAny.insert_short(invPolicyValue);
130         
131         byte[] otsCompValue = null;
132         byte[] invCompValue = null;
133         try {
134             otsCompValue = codec.encode_value(otsAny);
135             invCompValue = codec.encode_value(invAny);
136         } catch (org.omg.IOP.CodecPackage.InvalidTypeForEncoding JavaDoc e) {
137             throw new INTERNAL JavaDoc("InvalidTypeForEncoding "+e.getMessage());
138         }
139     
140         TaggedComponent JavaDoc otsComp = new TaggedComponent JavaDoc(TAG_OTS_POLICY.value,
141                                                       otsCompValue);
142     iorInfo.add_ior_component(otsComp);
143
144         TaggedComponent JavaDoc invComp = new TaggedComponent JavaDoc(TAG_INV_POLICY.value,
145                                                       invCompValue);
146     iorInfo.add_ior_component(invComp);
147     }
148
149     private void addCSIv2Components(IORInfo JavaDoc iorInfo, CSIv2Policy csiv2Policy)
150     {
151       try {
152     if(_logger.isLoggable(Level.FINE)) {
153         _logger.log(Level.FINE,
154             ".addCSIv2Components->: "
155             + " " + iorInfo + " " + csiv2Policy);
156     }
157         if (ASORBUtilities.isGMSAvailableAndClusterHeartbeatEnabled()) {
158             return;
159         }
160
161     EjbDescriptor ejbDesc = null;
162
163     if ( csiv2Policy != null ) {
164         ejbDesc = csiv2Policy.getEjbDescriptor();
165     }
166
167     if(_logger.isLoggable(Level.FINE)) {
168         _logger.log(Level.FINE,
169             ".addCSIv2Components: ejbDesc: " + ejbDesc);
170     }
171
172     ORB JavaDoc orb = ORBManager.getORB();
173
174     int sslMutualAuthPort = -1;
175     try {
176         sslMutualAuthPort = ((com.sun.corba.ee.spi.legacy.interceptor.IORInfoExt)iorInfo).
177                                 getServerPort("SSL_MUTUALAUTH");
178     } catch (com.sun.corba.ee.spi.legacy.interceptor.UnknownType ute) {
179             _logger.log(Level.FINE,"UnknownType exception", ute);
180     }
181
182     if(_logger.isLoggable(Level.FINE)) {
183         _logger.log(Level.FINE,
184             ".addCSIv2Components: sslMutualAuthPort: "
185             + sslMutualAuthPort);
186     }
187
188     CSIV2TaggedComponentInfo ctc = new CSIV2TaggedComponentInfo(orb);
189     ctc.setSSLMutualAuthPort(sslMutualAuthPort);
190
191     // Create CSIv2 tagged component
192
int sslport = -1;
193     try {
194         sslport = ((com.sun.corba.ee.spi.legacy.interceptor.IORInfoExt)iorInfo).
195                                 getServerPort("SSL");
196     } catch (com.sun.corba.ee.spi.legacy.interceptor.UnknownType ute) {
197             _logger.log(Level.FINE,"UnknownType exception", ute);
198     }
199
200     if(_logger.isLoggable(Level.FINE)) {
201         _logger.log(Level.FINE,
202             ".addCSIv2Components: sslport: "
203             + sslport);
204     }
205
206     TaggedComponent JavaDoc csiv2Comp = null;
207     if ( ejbDesc != null ) {
208         csiv2Comp = ctc.createSecurityTaggedComponent(sslport, ejbDesc);
209     }
210     else {
211         // this is not an EJB object, must be a non-EJB CORBA object
212
csiv2Comp = ctc.createSecurityTaggedComponent(sslport);
213     }
214
215     iorInfo.add_ior_component(csiv2Comp);
216
217       } finally {
218       if(_logger.isLoggable(Level.FINE)) {
219           _logger.log(Level.FINE,
220               ".addCSIv2Components<-: "
221               + " " + iorInfo + " " + csiv2Policy);
222       }
223       }
224     }
225 }
226
227 // End of file.
228
Popular Tags