1 21 package org.jacorb.orb.standardInterceptors; 22 23 import org.apache.avalon.framework.logger.Logger; 24 import org.apache.avalon.framework.configuration.ConfigurationException; 25 import org.ietf.jgss.Oid ; 26 27 import org.jacorb.orb.CDROutputStream; 28 import org.jacorb.orb.ORB; 29 import org.jacorb.orb.portableInterceptor.IORInfoImpl; 30 import org.jacorb.sasPolicy.ATLASPolicy; 31 import org.jacorb.sasPolicy.ATLASPolicyValues; 32 import org.jacorb.sasPolicy.ATLAS_POLICY_TYPE; 33 import org.jacorb.sasPolicy.SASPolicy; 34 import org.jacorb.sasPolicy.SASPolicyValues; 35 import org.jacorb.sasPolicy.SAS_POLICY_TYPE; 36 import org.jacorb.security.sas.ISASContext; 37 38 import org.omg.ATLAS.ATLASLocator; 39 import org.omg.ATLAS.ATLASProfile; 40 import org.omg.ATLAS.ATLASProfileHelper; 41 import org.omg.ATLAS.SCS_ATLAS; 42 import org.omg.CORBA.BAD_PARAM ; 43 import org.omg.CSIIOP.AS_ContextSec; 44 import org.omg.CSIIOP.CompoundSecMech; 45 import org.omg.CSIIOP.CompoundSecMechList; 46 import org.omg.CSIIOP.CompoundSecMechListHelper; 47 import org.omg.CSIIOP.SAS_ContextSec; 48 import org.omg.CSIIOP.ServiceConfiguration; 49 import org.omg.CSIIOP.TAG_CSI_SEC_MECH_LIST; 50 import org.omg.CSIIOP.TAG_NULL_TAG; 51 import org.omg.IOP.Codec ; 52 import org.omg.IOP.CodecFactory ; 53 import org.omg.IOP.ENCODING_CDR_ENCAPS ; 54 import org.omg.IOP.Encoding ; 55 import org.omg.IOP.TAG_INTERNET_IOP ; 56 import org.omg.IOP.TaggedComponent ; 57 import org.omg.PortableInterceptor.IORInfo ; 58 import org.omg.PortableInterceptor.IORInterceptor ; 59 import org.omg.PortableInterceptor.ORBInitInfo ; 60 61 67 68 public class SASComponentInterceptor 69 extends org.omg.CORBA.LocalObject 70 implements IORInterceptor 71 { 72 73 private org.jacorb.config.Configuration config = null; 74 75 76 private Logger logger = null; 77 78 private ORB orb = null; 79 private Codec codec = null; 80 private TaggedComponent tc = null; 81 private ISASContext sasContext = null; 82 83 public SASComponentInterceptor(ORBInitInfo info) 84 { 85 orb = ((org.jacorb.orb.portableInterceptor.ORBInitInfoImpl)info).getORB(); 86 config = orb.getConfiguration(); 87 logger = config.getNamedLogger("jacorb.SAS.IOR"); 88 89 try 90 { 91 Encoding encoding = 92 new Encoding (ENCODING_CDR_ENCAPS.value, (byte) 1, (byte) 0); 93 94 CodecFactory codec_factory = 95 (CodecFactory )orb.resolve_initial_references("CodecFactory"); 96 97 codec = codec_factory.create_codec(encoding); 98 } 99 catch (Exception e) 100 { 101 if (logger.isErrorEnabled()) 102 logger.error("Error initing SASComponentInterceptor: ",e); 103 } 104 105 String contextClass = null; 106 107 try 108 { 109 contextClass = config.getAttribute("jacorb.security.sas.contextClass"); 110 try 111 { 112 Class c = org.jacorb.util.ObjectUtil.classForName(contextClass); 113 sasContext = (ISASContext)c.newInstance(); 114 } 115 catch (Exception e) 116 { 117 if (logger.isErrorEnabled()) 118 logger.error("Could not instantiate SAS Context class " + 119 contextClass + ": " + e); 120 } 121 } 122 catch( ConfigurationException ce ) 123 { 124 } 126 127 if (sasContext == null) 128 { 129 if (logger.isErrorEnabled()) 130 logger.error("Could not load SAS context class: "+ contextClass); 131 } 132 } 133 134 136 public String name() 137 { 138 return "SASComponentCreator"; 139 } 140 141 public void destroy() 142 { 143 } 144 145 149 150 public void establish_components(IORInfo info) 151 { 152 if (sasContext == null) 154 return; 155 156 SASPolicyValues sasValues = null; 157 try 158 { 159 SASPolicy policy = 160 (SASPolicy)((IORInfoImpl)info).get_effective_policy(SAS_POLICY_TYPE.value); 161 if (policy != null) 162 sasValues = policy.value(); 163 } 164 catch (BAD_PARAM e) 165 { 166 if (logger.isDebugEnabled()) 167 logger.debug("No SAS Policy"); 168 } 169 catch (Exception e) 170 { 171 if (logger.isWarnEnabled()) 172 logger.warn("Error fetching SAS policy: "+e); 173 } 174 175 if (sasValues == null) 176 return; 177 178 if (sasValues.targetRequires == 0 && sasValues.targetSupports == 0) 179 return; 180 181 ATLASPolicyValues atlasValues = null; 182 try 183 { 184 ATLASPolicy policy = 185 (ATLASPolicy)info.get_effective_policy(ATLAS_POLICY_TYPE.value); 186 if (policy != null) 187 atlasValues = policy.value(); 188 } 189 catch (BAD_PARAM e) 190 { 191 if (logger.isDebugEnabled()) 192 logger.debug("No ATLAS Policy"); 193 } 194 catch (Exception e) 195 { 196 if (logger.isWarnEnabled()) 197 logger.warn("Error fetching ATLAS policy: "+e); 198 } 199 200 try 202 { 203 if( tc == null ) 204 { 205 TaggedComponent transportMech = 207 new TaggedComponent (TAG_NULL_TAG.value, new byte[0]); 208 209 byte[] targetName = sasContext.getClientPrincipal().getBytes(); 211 ServiceConfiguration[] serviceConfiguration = null; 212 if (atlasValues == null) 213 { 214 serviceConfiguration = new ServiceConfiguration[0]; 215 } 216 else 217 { 218 if (atlasValues.atlasCache == null) 219 atlasValues.atlasCache = ""; 220 ATLASLocator atlasLoc = new ATLASLocator(); 221 atlasLoc.the_url(atlasValues.atlasURL); 222 ATLASProfile profile = new ATLASProfile(); 223 profile.the_cache_id = atlasValues.atlasCache.getBytes(); 224 profile.the_locator = atlasLoc; 225 byte[] cdrProfile = new byte[0]; 226 org.omg.CORBA.Any any = orb.create_any(); 227 ATLASProfileHelper.insert( any, profile ); 228 cdrProfile = codec.encode(any); 229 serviceConfiguration = new ServiceConfiguration[1]; 230 serviceConfiguration[0] = 231 new ServiceConfiguration(SCS_ATLAS.value, cdrProfile); 232 } 233 SAS_ContextSec sasContextSec = 234 new SAS_ContextSec((short)0, 235 (short)0, 236 serviceConfiguration, 237 new byte[0][0], 238 0); 239 240 boolean useStateful = 242 config.getAttributeAsBoolean("jacorb.security.sas.stateful", true); 243 244 CompoundSecMech[] compoundSecMech = new CompoundSecMech[1]; 245 Oid oid = new Oid (sasContext.getMechOID()); 246 byte[] clientAuthenticationMech = oid.getDER(); 247 248 AS_ContextSec asContextSec = 249 new AS_ContextSec(sasValues.targetSupports, 250 sasValues.targetRequires, 251 clientAuthenticationMech, 252 targetName); 253 compoundSecMech[0] = 254 new CompoundSecMech(sasValues.targetRequires, 255 transportMech, 256 asContextSec, 257 sasContextSec); 258 259 CompoundSecMechList compoundSecMechList = 260 new CompoundSecMechList(useStateful, compoundSecMech); 261 262 CDROutputStream sasDataStream = new CDROutputStream( orb ); 264 sasDataStream.beginEncapsulatedArray(); 265 CompoundSecMechListHelper.write( sasDataStream , compoundSecMechList ); 266 tc = new TaggedComponent ( TAG_CSI_SEC_MECH_LIST.value, 267 sasDataStream.getBufferCopy() ); 268 269 sasDataStream.close (); 270 sasDataStream = null; 271 } 272 273 info.add_ior_component_to_profile (tc, TAG_INTERNET_IOP.value); 274 } 275 catch (Exception e) 276 { 277 if (logger.isErrorEnabled()) 278 logger.error("establish_components error: ", e); 279 } 280 } 281 } | Popular Tags |