1 25 package org.objectweb.jonas.security.iiop; 26 27 import java.rmi.Remote ; 28 29 import javax.rmi.CORBA.Tie ; 30 31 import org.jacorb.orb.iiop.IIOPProfile; 32 import org.jacorb.poa.RequestProcessor; 33 import org.omg.CORBA.Any ; 34 import org.omg.CORBA.INV_POLICY ; 35 import org.omg.CSIIOP.AS_ContextSec; 36 import org.omg.CSIIOP.CompoundSecMech; 37 import org.omg.CSIIOP.CompoundSecMechList; 38 import org.omg.CSIIOP.CompoundSecMechListHelper; 39 import org.omg.CSIIOP.DetectMisordering; 40 import org.omg.CSIIOP.DetectReplay; 41 import org.omg.CSIIOP.Integrity; 42 import org.omg.CSIIOP.SAS_ContextSec; 43 import org.omg.CSIIOP.ServiceConfiguration; 44 import org.omg.CSIIOP.TAG_CSI_SEC_MECH_LIST; 45 import org.omg.CSIIOP.TAG_NULL_TAG; 46 import org.omg.CSIIOP.TAG_TLS_SEC_TRANS; 47 import org.omg.CSIIOP.TLS_SEC_TRANS; 48 import org.omg.CSIIOP.TLS_SEC_TRANSHelper; 49 import org.omg.IOP.Codec ; 50 import org.omg.IOP.TAG_INTERNET_IOP ; 51 import org.omg.IOP.TaggedComponent ; 52 import org.omg.IOP.CodecPackage.InvalidTypeForEncoding ; 53 import org.omg.PortableInterceptor.IORInfo ; 54 import org.omg.PortableServer.Servant ; 55 import org.omg.SSLIOP.SSL; 56 import org.omg.SSLIOP.SSLHelper; 57 import org.omg.SSLIOP.TAG_SSL_SEC_TRANS; 58 59 import org.objectweb.carol.util.configuration.CarolDefaultValues; 60 import org.objectweb.carol.util.csiv2.SasComponent; 61 import org.objectweb.carol.util.csiv2.SasPolicy; 62 import org.objectweb.carol.util.csiv2.struct.AsStruct; 63 import org.objectweb.carol.util.csiv2.struct.SasStruct; 64 import org.objectweb.carol.util.csiv2.struct.TransportStruct; 65 66 import org.objectweb.jonas_ejb.container.JHome; 67 import org.objectweb.jonas_ejb.container.JRemote; 68 import org.objectweb.jonas_ejb.deployment.api.BeanDesc; 69 70 import org.objectweb.util.monolog.api.BasicLevel; 71 import org.objectweb.util.monolog.api.Logger; 72 73 79 public class Csiv2IorInterceptor extends org.omg.CORBA.LocalObject implements 80 org.omg.PortableInterceptor.IORInterceptor { 81 82 85 private static final String NAME = "Csiv2IorInterceptor"; 86 87 90 private Codec codec = null; 91 92 95 private Logger logger = null; 96 97 100 private Logger loggerDetails = null; 101 102 108 public Csiv2IorInterceptor(Codec codec, Logger logger, Logger loggerDetails) { 109 this.codec = codec; 110 this.logger = logger; 111 this.loggerDetails = loggerDetails; 112 } 113 114 120 public void establish_components(IORInfo info) { 121 SasPolicy sasPolicy = null; 122 SasComponent sasComponent = null; 123 124 try { 125 sasPolicy = (SasPolicy) info.get_effective_policy(SasPolicy.POLICY_TYPE); 126 127 TaggedComponent taggedComponent = null; 130 131 if (sasPolicy != null) { 132 sasComponent = sasPolicy.getSasComponent(); 133 } else { 134 Thread currentThread = Thread.currentThread(); 136 if (!(currentThread instanceof RequestProcessor)) { 137 return; 138 } 139 RequestProcessor rp = (RequestProcessor) currentThread; 140 Servant servant = rp.getServant(); 141 if (servant == null) { 142 return; 143 } 144 Tie tie = null; 145 if (!(servant instanceof Tie )) { 146 return; 147 } 148 tie = (Tie ) servant; 149 Remote target = tie.getTarget(); 150 if (target == null) { 151 return; 152 } 153 154 if (!(target instanceof JHome) && !(target instanceof JRemote)) { 155 return; 156 } 157 BeanDesc bd = null; 158 if (target instanceof JHome) { 159 bd = ((JHome) target).getDd(); 160 } else if (target instanceof JRemote) { 161 bd = ((JRemote) target).getBf().getDeploymentDescriptor(); 162 } 163 sasComponent = bd.getSasComponent(); 164 } 165 166 if (sasComponent == null) { 167 if (loggerDetails.isLoggable(BasicLevel.DEBUG)) { 168 loggerDetails.log(BasicLevel.DEBUG, "No Sas component was found, will not write any infos into IOR."); 169 } 170 return; 171 } 172 173 try { 174 175 taggedComponent = buildCSIv2Component(sasComponent); 176 177 info.add_ior_component_to_profile(taggedComponent, TAG_INTERNET_IOP.value); 179 180 } catch (Csiv2InterceptorException cie) { 181 logger.log(BasicLevel.ERROR, "Cannot build Csiv2 component, cannot add it. Component = " 182 + taggedComponent); 183 } 184 185 } catch (INV_POLICY e) { 186 if (logger.isLoggable(BasicLevel.DEBUG)) { 187 logger.log(BasicLevel.DEBUG, "No policy found"); 188 } 189 190 } finally { 191 192 if (sasComponent != null) { 194 TransportStruct transportStruct = sasComponent.getTransport(); 196 if (transportStruct.getTargetRequires() > 0) { 197 org.omg.ETF.Profile profile = ((org.jacorb.orb.portableInterceptor.IORInfoImpl) info).get_profile(0); 198 if (profile instanceof IIOPProfile) { 199 if (logger.isLoggable(BasicLevel.DEBUG)) { 200 logger.log(BasicLevel.DEBUG, "Set port to 0"); 201 } 202 ((IIOPProfile) profile).patchPrimaryAddress(null, 0); 203 } 204 } 205 } 206 207 try { 208 info.add_ior_component_to_profile(buildSslTaggedComponent(sasComponent), TAG_INTERNET_IOP.value); 209 } catch (Csiv2InterceptorException cie) { 210 logger.log(BasicLevel.ERROR, "Cannot add SSL tagged component" + cie.getMessage(), cie); 211 } 212 213 214 } 215 216 217 } 218 219 222 public void destroy() { 223 } 224 225 229 public String name() { 230 return NAME; 231 } 232 233 259 private TaggedComponent buildCSIv2Component(SasComponent sasComponent) throws Csiv2InterceptorException { 260 if (logger.isLoggable(BasicLevel.DEBUG)) { 261 logger.log(BasicLevel.DEBUG, ""); 262 } 263 264 CompoundSecMech[] mechanismList = buildCompoundSecMechs(sasComponent); 267 CompoundSecMechList compoundSecMechList = new CompoundSecMechList(Csiv2Const.STATEFUL_MODE, mechanismList); 268 269 270 Any pAny = ORBHelper.getOrb().create_any(); 272 CompoundSecMechListHelper.insert(pAny, compoundSecMechList); 273 byte[] componentData = null; 274 try { 275 componentData = codec.encode_value(pAny); 276 } catch (InvalidTypeForEncoding itfe) { 277 throw new Csiv2InterceptorException("Cannot encode a given any corba object", itfe); 278 } 279 280 TaggedComponent taggedComponent = new TaggedComponent (TAG_CSI_SEC_MECH_LIST.value, componentData); 282 283 return taggedComponent; 284 } 285 286 299 private CompoundSecMech[] buildCompoundSecMechs(SasComponent sasComponent) throws Csiv2InterceptorException { 300 if (logger.isLoggable(BasicLevel.DEBUG)) { 301 logger.log(BasicLevel.DEBUG, ""); 302 } 303 304 TaggedComponent transportMech = buildTransportMech(sasComponent); 306 307 AS_ContextSec asContextMech = buildAsContextMech(sasComponent); 309 310 SAS_ContextSec sasContextMech = buildSasContextMech(sasComponent); 312 313 short targetRequires = (short) (sasComponent.getTransport().getTargetRequires() | asContextMech.target_requires | sasContextMech.target_requires); 320 321 CompoundSecMech[] compoundSecMechs = new CompoundSecMech[1]; 323 compoundSecMechs[0] = new CompoundSecMech(targetRequires, transportMech, asContextMech, sasContextMech); 324 325 return compoundSecMechs; 327 } 328 329 335 private TaggedComponent buildTransportMech(SasComponent sasComponent) throws Csiv2InterceptorException { 336 337 TaggedComponent taggedComponent = null; 338 339 TransportStruct transportStruct = sasComponent.getTransport(); 340 341 if (transportStruct.getTargetSupports() == 0 && transportStruct.getTargetRequires() == 0) { 342 347 return new TaggedComponent (TAG_NULL_TAG.value, Csiv2Const.EMPTY_BYTES); 348 } 349 350 354 TLS_SEC_TRANS tlsSecTrans = new TLS_SEC_TRANS(transportStruct.getTargetSupports(), transportStruct.getTargetRequires(), transportStruct.getTransportAddress()); 355 356 Any pAny = ORBHelper.getOrb().create_any(); 358 TLS_SEC_TRANSHelper.insert(pAny, tlsSecTrans); 359 byte[] componentData = null; 360 try { 361 componentData = codec.encode_value(pAny); 362 } catch (InvalidTypeForEncoding itfe) { 363 throw new Csiv2InterceptorException("Cannot encode a given any corba object", itfe); 364 } 365 366 taggedComponent = new TaggedComponent (TAG_TLS_SEC_TRANS.value, componentData); 368 369 return taggedComponent; 370 } 371 372 378 private TaggedComponent buildSslTaggedComponent(SasComponent sasComponent) throws Csiv2InterceptorException { 379 380 SSL ssl = null; 381 int minSSlOptions = Integrity.value | DetectReplay.value | DetectMisordering.value; 382 if (sasComponent != null) { 383 TransportStruct transportStruct = sasComponent.getTransport(); 384 385 ssl = new SSL(transportStruct.getTargetSupports(), transportStruct.getTargetRequires(), (short) TransportStruct.getSslPort()); 386 } else { 387 ssl = new SSL((short) minSSlOptions, (short) 0, (short) TransportStruct.getSslPort()); 388 } 389 390 Any pAny = ORBHelper.getOrb().create_any(); 392 SSLHelper.insert(pAny, ssl); 393 byte[] componentData = null; 394 try { 395 componentData = codec.encode_value(pAny); 396 } catch (InvalidTypeForEncoding itfe) { 397 throw new Csiv2InterceptorException("Cannot encode a given any corba object", itfe); 398 } 399 return new TaggedComponent (TAG_SSL_SEC_TRANS.value, componentData); 400 401 } 402 403 404 405 406 411 private AS_ContextSec buildAsContextMech(SasComponent sasComponent) { 412 413 AsStruct asStruct = sasComponent.getAs(); 414 415 AS_ContextSec asContextMech = new AS_ContextSec(asStruct.getTargetSupports(), asStruct 417 .getTargetRequires(), asStruct.getClientAuthenticationMech(), asStruct.getTargetName()); 418 419 return asContextMech; 420 421 } 422 423 428 private SAS_ContextSec buildSasContextMech(SasComponent sasComponent) { 429 430 SasStruct sasStruct = sasComponent.getSas(); 431 432 439 ServiceConfiguration[] privilegeAuthorities = new ServiceConfiguration[0]; 440 441 byte[][] supportedNamingMechanisms = sasStruct.getSupportedNamingMechanisms(); 442 if (logger.isLoggable(BasicLevel.DEBUG)) { 443 logger.log(BasicLevel.DEBUG, "supported mechanisms = " + supportedNamingMechanisms + " and identity = " 444 + sasStruct.getSupportedIdentityTypes()); 445 logger.log(BasicLevel.DEBUG, "supported mechanisms size= " + supportedNamingMechanisms.length); 446 logger.log(BasicLevel.DEBUG, "target supports= " + sasStruct.getTargetSupports()); 447 } 448 458 int supportedIdentityTypes = sasStruct.getSupportedIdentityTypes(); 460 461 SAS_ContextSec sasContextMech = new SAS_ContextSec(sasStruct.getTargetSupports(), 463 sasStruct.getTargetRequires(), privilegeAuthorities, supportedNamingMechanisms, supportedIdentityTypes); 464 465 return sasContextMech; 466 } 467 468 469 470 } | Popular Tags |