KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > orb > standardInterceptors > SSLComponentInterceptor


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2004 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

21 package org.jacorb.orb.standardInterceptors;
22
23 import org.apache.avalon.framework.configuration.*;
24
25 import org.omg.PortableInterceptor.*;
26 import org.omg.IOP.*;
27 import org.omg.SSLIOP.*;
28
29 import org.jacorb.orb.*;
30
31 /**
32  * This interceptor creates an ssl TaggedComponent
33  *
34  * @author Nicolas Noffke
35  * @version $Id: SSLComponentInterceptor.java,v 1.19 2004/05/06 12:40:00 nicolas Exp $
36  */

37
38 public class SSLComponentInterceptor
39     extends org.omg.CORBA.LocalObject JavaDoc
40     implements IORInterceptor, Configurable
41 {
42     private ORB orb = null;
43     private TaggedComponent tc = null;
44     private short supported = 0;
45     private short required = 0;
46
47     public SSLComponentInterceptor( ORB orb )
48         throws ConfigurationException
49    {
50         this.orb = orb;
51         configure( orb.getConfiguration());
52     }
53
54     public void configure(Configuration configuration)
55         throws ConfigurationException
56     {
57         supported =
58             Short.parseShort(
59                 configuration.getAttribute("jacorb.security.ssl.server.supported_options","20"),
60                 16); // 16 is the base as we take the string value as hex!
61

62         required =
63             Short.parseShort(
64                 configuration.getAttribute("jacorb.security.ssl.server.required_options","0"),
65                 16);
66
67     }
68
69     // implementation of org.omg.PortableInterceptor.IORInterceptorOperations interface
70
public String JavaDoc name()
71     {
72         return "SSLComponentCreator";
73     }
74
75     public void destroy()
76     {
77     }
78
79     /**
80      * Builds an ssl TaggedComponent.
81      * Was formerly: ORB.makeSSLComponent()
82      */

83
84     /*
85         typedef unsigned short AssociationOptions;
86
87         const AssociationOptions NoProtection = 1; 0x001
88         const AssociationOptions Integrity = 2; 0x002
89         const AssociationOptions Confidentiality = 4; 0x004
90         const AssociationOptions DetectReplay = 8; 0x008
91         const AssociationOptions DetectMisordering = 16;0x010
92         const AssociationOptions EstablishTrustInTarget = 32; 0x020
93         const AssociationOptions EstablishTrustInClient = 64; 0x040
94         const AssociationOptions NoDelegation = 128; 0x080
95         const AssociationOptions SimpleDelegation = 256; 0x100
96         const AssociationOptions CompositeDelegation = 512; 0x200
97      */

98
99     public void establish_components(IORInfo info)
100     {
101         try
102         {
103             if( tc == null )
104             {
105                 SSL ssl =
106                     new SSL ( supported,
107                               required,
108                               (short) orb.getBasicAdapter().getSSLPort());
109
110                 //we don't support delegation 0x80 -> NoDelegation we don't
111
//care if the other side delegates, so no required options are
112
//set.
113
ssl.target_supports |= 0x80;
114
115                 //this is SSLs default behaviour, included for completeness
116
ssl.target_supports |= 0x20; //establish trust in target
117

118                 CDROutputStream sslDataStream =
119                     new CDROutputStream( orb );
120
121                 sslDataStream.beginEncapsulatedArray();
122
123                 SSLHelper.write( sslDataStream , ssl );
124
125                 tc = new TaggedComponent( TAG_SSL_SEC_TRANS.value,
126                                           sslDataStream.getBufferCopy() );
127
128                 sslDataStream.close ();
129                 sslDataStream = null;
130             }
131
132             info.add_ior_component_to_profile (tc, TAG_INTERNET_IOP.value);
133         }
134         catch (Exception JavaDoc e)
135         {
136             // should not happen
137
e.printStackTrace();
138         }
139     }
140 } // SSLComponentInterceptor
141
Popular Tags