1 25 26 package org.objectweb.jonas.security.iiop; 27 28 import org.omg.CORBA.Any ; 29 import org.omg.CORBA.BAD_PARAM ; 30 import org.omg.CORBA.NO_PERMISSION ; 31 import org.omg.CSI.CompleteEstablishContext; 32 import org.omg.CSI.EstablishContext; 33 import org.omg.CSI.GSS_NT_ExportedNameHelper; 34 import org.omg.CSI.ITTPrincipalName; 35 import org.omg.CSI.IdentityToken; 36 import org.omg.CSI.MTEstablishContext; 37 import org.omg.CSI.MTMessageInContext; 38 import org.omg.CSI.SASContextBody; 39 import org.omg.CSI.SASContextBodyHelper; 40 import org.omg.GSSUP.InitialContextToken; 41 import org.omg.GSSUP.InitialContextTokenHelper; 42 import org.omg.IOP.Codec ; 43 import org.omg.IOP.SecurityAttributeService; 44 import org.omg.IOP.ServiceContext ; 45 import org.omg.IOP.CodecPackage.FormatMismatch ; 46 import org.omg.IOP.CodecPackage.InvalidTypeForEncoding ; 47 import org.omg.IOP.CodecPackage.TypeMismatch ; 48 import org.omg.PortableInterceptor.ForwardRequest ; 49 import org.omg.PortableInterceptor.ServerRequestInfo ; 50 import org.omg.PortableInterceptor.ServerRequestInterceptor ; 51 52 import org.objectweb.carol.util.csiv2.gss.GSSHelper; 53 54 import org.objectweb.util.monolog.api.BasicLevel; 55 import org.objectweb.util.monolog.api.Logger; 56 57 63 public class Csiv2ServerInterceptor extends org.omg.CORBA.LocalObject implements ServerRequestInterceptor { 64 65 68 private static final String NAME = "Csiv2ServerInterceptor"; 69 70 73 private Codec codec = null; 74 75 78 private Logger logger = null; 79 80 83 private Logger loggerDetails = null; 84 85 91 public Csiv2ServerInterceptor(Codec codec, Logger logger, Logger loggerDetails) { 92 this.codec = codec; 93 this.logger = logger; 94 this.loggerDetails = loggerDetails; 95 } 96 97 107 public void receive_request(ServerRequestInfo ri) throws ForwardRequest { 108 109 ServiceContext receiveServiceContext = null; 111 try { 112 receiveServiceContext = ri.get_request_service_context(SecurityAttributeService.value); 114 if (logger.isLoggable(BasicLevel.DEBUG)) { 115 logger.log(BasicLevel.DEBUG, "Got security service context = " + receiveServiceContext); 116 } 117 } catch (BAD_PARAM e) { 118 if (loggerDetails.isLoggable(BasicLevel.DEBUG)) { 119 loggerDetails.log(BasicLevel.DEBUG, "No security service context found"); 120 } 121 } 122 123 if (receiveServiceContext == null) { 125 return; 126 } 127 128 SASContextBody receivedSASContextBody = null; 130 Any receiveAny = null; 131 try { 132 receiveAny = codec.decode_value(receiveServiceContext.context_data, SASContextBodyHelper.type()); 133 } catch (FormatMismatch fm) { 134 logger.log(BasicLevel.ERROR, "Format mismatch while decoding value :" + fm.getMessage()); 135 return; 136 } catch (TypeMismatch tm) { 137 logger.log(BasicLevel.ERROR, "Type mismatch while decoding value :" + tm.getMessage()); 138 return; 139 } 140 receivedSASContextBody = SASContextBodyHelper.extract(receiveAny); 141 if (receivedSASContextBody == null) { 142 logger.log(BasicLevel.ERROR, "Received Sascontext body is null"); 143 return; 144 } 145 short discriminator = receivedSASContextBody.discriminator(); 146 147 if (discriminator == MTEstablishContext.value) { 148 EstablishContext receivedEstablishContext = receivedSASContextBody.establish_msg(); 150 151 byte[] clientAuthenticationToken = receivedEstablishContext.client_authentication_token; 153 IdentityToken identityToken = receivedEstablishContext.identity_token; 155 156 if (clientAuthenticationToken != null && clientAuthenticationToken.length != 0) { 158 Any pAny = null; 159 try { 160 pAny = codec.decode_value(GSSHelper.decodeToken(receivedEstablishContext.client_authentication_token), InitialContextTokenHelper.type()); 161 } catch (FormatMismatch fm) { 162 logger.log(BasicLevel.ERROR, "Format mismatch while decoding value :" + fm.getMessage()); 163 return; 164 } catch (TypeMismatch tm) { 165 logger.log(BasicLevel.ERROR, "Type mismatch while decoding value :" + tm.getMessage()); 166 return; 167 } 168 InitialContextToken initialContextToken = InitialContextTokenHelper.extract(pAny); 169 String userName = new String (initialContextToken.username); 170 String password = new String (initialContextToken.password); 171 if (logger.isLoggable(BasicLevel.DEBUG)) { 172 logger.log(BasicLevel.DEBUG, "Received InitialContextToken, login = '" + userName + "' and password = '" + password + "'."); 173 } 174 SecurityContextHelper.getInstance().loginAuthenticationToken(userName, password); 175 176 } else if (identityToken != null) { try { 178 if (identityToken.discriminator() == ITTPrincipalName.value) { 180 Any a = codec.decode_value(receivedEstablishContext.identity_token.principal_name(), GSS_NT_ExportedNameHelper.type()); 181 byte[] encodedName = GSS_NT_ExportedNameHelper.extract(a); 182 183 String principalName = GSSHelper.decodeExported(encodedName); 185 if (logger.isLoggable(BasicLevel.DEBUG)) { 186 logger.log(BasicLevel.DEBUG, "Received identityToken, principalName = " + principalName); 187 } 188 SecurityContextHelper.getInstance().loginIdentiyToken(principalName); 189 } 190 } catch (Exception e) { 191 logger.log(BasicLevel.ERROR, "Error = " + e.getMessage()); 192 return; 193 } 194 } 195 196 } else if (discriminator == MTMessageInContext.value) { throw new NO_PERMISSION (); 198 } 199 200 231 CompleteEstablishContext completeEstablishContext = new CompleteEstablishContext(Csiv2Const.STATELESS_CONTEXT_ID, Csiv2Const.STATEFUL_MODE, Csiv2Const.EMPTY_BYTES); 232 233 234 247 Any pAny = null; 248 try { 249 pAny = ORBHelper.getOrb().create_any(); 250 } catch (Csiv2InterceptorException csie) { 251 logger.log(BasicLevel.ERROR, "Cannot get orb for any = " + csie.getMessage()); 252 return; 253 } 254 255 SASContextBody sasContextBody = new SASContextBody(); 257 sasContextBody.complete_msg(completeEstablishContext); 258 SASContextBodyHelper.insert(pAny, sasContextBody); 259 byte[] contextData = null; 260 261 try { 262 contextData = codec.encode_value(pAny); 263 } catch (InvalidTypeForEncoding itfe) { 264 logger.log(BasicLevel.ERROR, "Cannot encode a given any corba object : " + itfe.getMessage()); 265 return; 266 } 267 268 ServiceContext serviceContext = new ServiceContext (SecurityAttributeService.value, contextData); 270 ri.add_reply_service_context(serviceContext, Csiv2Const.REPLACE_SECURITY_ATTRIBUTE_SERVICE); 271 272 273 } 274 275 282 public void receive_request_service_contexts(ServerRequestInfo ri) throws ForwardRequest { 283 285 } 286 287 298 public void send_exception(ServerRequestInfo ri) throws ForwardRequest { 299 301 } 302 303 312 public void send_other(ServerRequestInfo ri) throws ForwardRequest { 313 315 } 316 317 324 public void send_reply(ServerRequestInfo ri) { 325 326 } 327 328 331 public void destroy() { 332 333 } 334 335 339 public String name() { 340 return NAME; 341 } 342 } 343 | Popular Tags |