1 25 package org.objectweb.jonas.security.iiop; 26 27 import java.io.IOException ; 28 import java.io.UnsupportedEncodingException ; 29 30 import org.omg.CORBA.Any ; 31 import org.omg.CORBA.BAD_PARAM ; 32 import org.omg.CSI.AuthorizationElement; 33 import org.omg.CSI.EstablishContext; 34 import org.omg.CSI.GSS_NT_ExportedNameHelper; 35 import org.omg.CSI.IdentityToken; 36 import org.omg.CSI.SASContextBody; 37 import org.omg.CSI.SASContextBodyHelper; 38 import org.omg.CSIIOP.CompoundSecMech; 39 import org.omg.CSIIOP.CompoundSecMechList; 40 import org.omg.CSIIOP.CompoundSecMechListHelper; 41 import org.omg.CSIIOP.EstablishTrustInClient; 42 import org.omg.CSIIOP.IdentityAssertion; 43 import org.omg.CSIIOP.TAG_CSI_SEC_MECH_LIST; 44 import org.omg.GSSUP.InitialContextToken; 45 import org.omg.GSSUP.InitialContextTokenHelper; 46 import org.omg.IOP.Codec ; 47 import org.omg.IOP.SecurityAttributeService; 48 import org.omg.IOP.ServiceContext ; 49 import org.omg.IOP.TaggedComponent ; 50 import org.omg.IOP.CodecPackage.FormatMismatch ; 51 import org.omg.IOP.CodecPackage.InvalidTypeForEncoding ; 52 import org.omg.IOP.CodecPackage.TypeMismatch ; 53 import org.omg.PortableInterceptor.ClientRequestInfo ; 54 import org.omg.PortableInterceptor.ClientRequestInterceptor ; 55 import org.omg.PortableInterceptor.ForwardRequest ; 56 57 import org.objectweb.carol.util.csiv2.gss.GSSHelper; 58 59 import org.objectweb.util.monolog.api.BasicLevel; 60 import org.objectweb.util.monolog.api.Logger; 61 62 71 public class Csiv2ClientInterceptor extends org.omg.CORBA.LocalObject implements ClientRequestInterceptor { 72 73 76 private static final String NAME = "Csiv2ClientInterceptor"; 77 78 81 private Codec codec = null; 82 83 86 private Logger logger = null; 87 88 91 private Logger loggerDetails = null; 92 93 99 public Csiv2ClientInterceptor(Codec codec, Logger logger, Logger loggerDetails) { 100 this.codec = codec; 101 this.logger = logger; 102 this.loggerDetails = loggerDetails; 103 } 104 105 114 public void receive_exception(ClientRequestInfo ri) throws ForwardRequest { 115 116 } 117 118 127 public void receive_other(ClientRequestInfo ri) throws ForwardRequest { 128 129 } 130 131 138 public void receive_reply(ClientRequestInfo ri) { 139 140 } 141 142 147 public void send_poll(ClientRequestInfo ri) { 148 149 } 150 151 156 public void send_request(ClientRequestInfo ri) throws ForwardRequest { 157 158 TaggedComponent taggedComponent = null; 160 try { 161 taggedComponent = ri.get_effective_component(TAG_CSI_SEC_MECH_LIST.value); 162 if (logger.isLoggable(BasicLevel.DEBUG)) { 163 logger.log(BasicLevel.DEBUG, "There is a TAG_CSI_SEC_MECH_LIST tagged component"); 164 } 165 166 } catch (BAD_PARAM e) { 167 if (loggerDetails.isLoggable(BasicLevel.DEBUG)) { 168 loggerDetails.log(BasicLevel.DEBUG, "No tagged component with id " + TAG_CSI_SEC_MECH_LIST.value); 169 } 170 return; 171 172 } 173 174 if (taggedComponent == null) { 176 return; 177 } 178 179 180 Any pAny = null; 182 try { 183 pAny = codec.decode_value(taggedComponent.component_data, CompoundSecMechListHelper.type()); 184 } catch (FormatMismatch fm) { 185 logger.log(BasicLevel.ERROR, "Format mismatch while decoding value :" + fm.getMessage()); 186 return; 187 } catch (TypeMismatch tm) { 188 logger.log(BasicLevel.ERROR, "Type mismatch while decoding value :" + tm.getMessage()); 189 return; 190 } 191 192 CompoundSecMechList compoundSecMechList = CompoundSecMechListHelper.extract(pAny); 195 CompoundSecMech compoundSecMech = null; 196 if (compoundSecMechList.mechanism_list.length > 0) { 197 compoundSecMech = compoundSecMechList.mechanism_list[0]; 198 } else { 199 if (logger.isLoggable(BasicLevel.DEBUG)) { 201 logger.log(BasicLevel.DEBUG, "No coumpound sec mech in the list."); 202 } 203 return; 204 } 205 206 207 258 259 long clientContextId = Csiv2Const.STATELESS_CONTEXT_ID; 260 AuthorizationElement[] withoutAuthorizationToken = new AuthorizationElement[0]; 261 262 IdentityToken identityToken = null; 263 264 IdentityToken anonymousIdentityToken = new IdentityToken(); 266 anonymousIdentityToken.anonymous(true); 267 268 IdentityToken absentIdentityToken = new IdentityToken(); 270 absentIdentityToken.absent(true); 271 272 273 byte[] clientAuthenticationToken = Csiv2Const.EMPTY_BYTES; 274 275 276 279 if ((compoundSecMech.as_context_mech.target_requires & EstablishTrustInClient.value) == EstablishTrustInClient.value) { 281 pAny = null; 282 try { 283 pAny = ORBHelper.getOrb().create_any(); 284 } catch (Csiv2InterceptorException csie) { 285 logger.log(BasicLevel.ERROR, "Cannot get orb for any = " + csie.getMessage()); 286 return; 287 } 288 InitialContextToken initialContextToken = null; 289 try { 290 initialContextToken = SecurityContextHelper.getInstance().getInitialContextToken(); 291 } catch (UnsupportedEncodingException uee) { 292 logger.log(BasicLevel.ERROR, "Unsupported encoding for UTF8" + uee.getMessage()); 293 return; 294 } 295 InitialContextTokenHelper.insert(pAny, initialContextToken); 296 byte[] contextData = null; 297 298 try { 299 contextData = codec.encode_value(pAny); 300 } catch (InvalidTypeForEncoding itfe) { 301 logger.log(BasicLevel.ERROR, "Cannot encode a given any corba object : " + itfe.getMessage()); 302 return; 303 } 304 305 try { 306 clientAuthenticationToken = GSSHelper.encodeToken(contextData); 307 } catch (IOException ioe) { 308 logger.log(BasicLevel.ERROR, "Cannot encode client authentication token : " + ioe.getMessage()); 309 return; 310 } 311 } 312 313 314 if ((compoundSecMech.sas_context_mech.target_supports & IdentityAssertion.value) == IdentityAssertion.value) { 316 pAny = null; 317 try { 318 pAny = ORBHelper.getOrb().create_any(); 319 } catch (Csiv2InterceptorException csie) { 320 logger.log(BasicLevel.ERROR, "Cannot get orb for any = " + csie.getMessage()); 321 return; 322 } 323 324 325 String identity = SecurityContextHelper.getInstance().getIdentityToken(); 327 byte[] name = GSSHelper.encodeExported(identity); 328 byte[] principalName = null; 329 GSS_NT_ExportedNameHelper.insert(pAny, name); 330 try { 331 principalName = codec.encode_value(pAny); 332 } catch (InvalidTypeForEncoding itfe) { 333 logger.log(BasicLevel.ERROR, "Cannot encode a given any corba object : " + itfe.getMessage()); 334 return; 335 } 336 337 338 identityToken = new IdentityToken(); 340 identityToken.principal_name(principalName); 341 342 } 343 344 if (identityToken == null) { 346 identityToken = absentIdentityToken; 347 } 348 349 if (identityToken == absentIdentityToken && clientAuthenticationToken == Csiv2Const.EMPTY_BYTES) { 351 return; 352 } 353 354 355 EstablishContext establishContext = new EstablishContext(clientContextId, withoutAuthorizationToken, 356 identityToken, clientAuthenticationToken); 357 358 359 360 361 362 375 try { 376 pAny = ORBHelper.getOrb().create_any(); 377 } catch (Csiv2InterceptorException csie) { 378 logger.log(BasicLevel.ERROR, "Cannot get orb for any = " + csie.getMessage()); 379 return; 380 } 381 382 SASContextBody sasContextBody = new SASContextBody(); 384 sasContextBody.establish_msg(establishContext); 385 SASContextBodyHelper.insert(pAny, sasContextBody); 386 byte[] contextData = null; 387 388 try { 389 contextData = codec.encode_value(pAny); 390 } catch (InvalidTypeForEncoding itfe) { 391 logger.log(BasicLevel.ERROR, "Cannot encode a given any corba object : " + itfe.getMessage()); 392 return; 393 } 394 395 ServiceContext serviceContext = new ServiceContext (SecurityAttributeService.value, contextData); 397 ri.add_request_service_context(serviceContext, Csiv2Const.REPLACE_SECURITY_ATTRIBUTE_SERVICE); 398 399 } 400 401 404 public void destroy() { 405 407 } 408 409 413 public String name() { 414 return NAME; 415 } 416 417 } | Popular Tags |