package org.jboss.iiop.csiv2;
import org.omg.CORBA.Any;
import org.omg.CORBA.ORB;
import org.omg.CORBA.LocalObject;
import org.omg.CORBA.BAD_PARAM;
import org.omg.CSIIOP.Integrity;
import org.omg.CSIIOP.DetectReplay;
import org.omg.CSIIOP.DetectMisordering;
import org.omg.PortableInterceptor.IORInfo;
import org.omg.PortableInterceptor.IORInterceptor;
import org.omg.IOP.Codec;
import org.omg.IOP.CodecPackage.InvalidTypeForEncoding;
import org.omg.IOP.TAG_INTERNET_IOP;
import org.omg.IOP.TaggedComponent;
import org.omg.SSLIOP.SSL;
import org.omg.SSLIOP.SSLHelper;
import org.omg.SSLIOP.TAG_SSL_SEC_TRANS;
import org.jboss.iiop.CorbaORBService;
import org.jboss.logging.Logger;
import org.jboss.metadata.IorSecurityConfigMetaData;
public class CSIv2IORInterceptor
extends LocalObject
implements IORInterceptor
{
static final long serialVersionUID = 7726088578382542812L;
private static final Logger log = Logger.getLogger(CSIv2IORInterceptor.class);
private static final int MIN_SSL_OPTIONS = Integrity.value |
DetectReplay.value |
DetectMisordering.value;
private TaggedComponent defaultSSLComponent;
private TaggedComponent defaultCSIComponent;
public CSIv2IORInterceptor(Codec codec)
{
int sslPort = CorbaORBService.getTheActualSSLPort();
try
{
SSL ssl = new SSL((short) MIN_SSL_OPTIONS,
(short) 0,
(short) sslPort);
ORB orb = ORB.init();
Any any = orb.create_any();
SSLHelper.insert(any, ssl);
byte[] componentData = codec.encode_value(any);
defaultSSLComponent = new TaggedComponent(TAG_SSL_SEC_TRANS.value,
componentData);
IorSecurityConfigMetaData metadata = new IorSecurityConfigMetaData();
defaultCSIComponent = CSIv2Util.createSecurityTaggedComponent(metadata,
codec, sslPort, orb);
}
catch (InvalidTypeForEncoding e)
{
log.warn("Caught unexcepted exception while encoding SSL component", e);
throw new RuntimeException(e);
}
}
public String name()
{
return CSIv2IORInterceptor.class.getName();
}
public void destroy()
{
}
public void establish_components(IORInfo info)
{
CSIv2Policy csiv2Policy = null;
try
{
csiv2Policy = (CSIv2Policy) info.get_effective_policy(CSIv2Policy.TYPE);
}
catch (BAD_PARAM e)
{
if (log.isDebugEnabled())
log.debug("No CSIv2Policy");
}
catch (Exception e)
{
if (log.isDebugEnabled())
log.debug("Error fetching CSIv2Policy", e);
}
if (csiv2Policy != null)
{
TaggedComponent sslComponent =
csiv2Policy.getSSLTaggedComponent();
if (sslComponent != null &&
CorbaORBService.getSSLComponentsEnabledFlag() == true)
{
info.add_ior_component_to_profile(sslComponent,
TAG_INTERNET_IOP.value);
}
TaggedComponent csiv2Component =
csiv2Policy.getSecurityTaggedComponent();
if (csiv2Component != null)
{
info.add_ior_component_to_profile(csiv2Component,
TAG_INTERNET_IOP.value);
}
}
else
{
if (defaultSSLComponent != null &&
CorbaORBService.getSSLComponentsEnabledFlag() == true)
{
info.add_ior_component_to_profile(defaultSSLComponent,
TAG_INTERNET_IOP.value);
}
if (defaultCSIComponent != null)
{
info.add_ior_component_to_profile(defaultCSIComponent,
TAG_INTERNET_IOP.value);
}
}
return;
}
}