KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > iiop > csiv2 > SASInitializer


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.iiop.csiv2;
23
24 /***************************************
25  * *
26  * JBoss: The OpenSource J2EE WebOS *
27  * *
28  * Distributable under LGPL license. *
29  * See terms of license at gnu.org. *
30  * *
31  ***************************************/

32
33 import org.omg.CORBA.LocalObject JavaDoc;
34 import org.omg.IOP.Codec JavaDoc;
35 import org.omg.IOP.ENCODING_CDR_ENCAPS JavaDoc;
36 import org.omg.IOP.Encoding JavaDoc;
37 import org.omg.PortableInterceptor.ORBInitInfo JavaDoc;
38 import org.omg.PortableInterceptor.ORBInitInfoPackage.InvalidName JavaDoc;
39 import org.omg.PortableInterceptor.ORBInitializer JavaDoc;
40
41 import org.jboss.ejb.plugins.SecurityInterceptor;
42 import org.jboss.system.Registry;
43
44 /**
45  * This is an <code>org.omg.PortableInterceptor.ORBInitializer</code> that
46  * initializes the Security Attibute Service (SAS).
47  *
48  * @author <a HREF="mailto:reverbel@ime.usp.br">Francisco Reverbel</a>
49  * @version $Revision: 37459 $
50  */

51 public class SASInitializer
52    extends LocalObject JavaDoc
53    implements ORBInitializer JavaDoc
54 {
55
56    public SASInitializer()
57    {
58       // do nothing
59
}
60     
61    // org.omg.PortableInterceptor.ORBInitializer operations ---------
62

63    public void pre_init(ORBInitInfo JavaDoc info)
64    {
65       try
66       {
67          // Create and register the SASCurrent
68
SASCurrent sasCurrent = new SASCurrentImpl();
69          info.register_initial_reference("SASCurrent", sasCurrent);
70       }
71       catch(InvalidName JavaDoc e)
72       {
73          throw new RuntimeException JavaDoc("Could not register initial " +
74             "reference for SASCurrent: " + e);
75       }
76    }
77
78    public void post_init(ORBInitInfo JavaDoc info)
79    {
80       try
81       {
82          // Use CDR encapsulations with GIOP 1.0 encoding
83
Encoding JavaDoc encoding = new Encoding JavaDoc(ENCODING_CDR_ENCAPS.value,
84             (byte) 1, /* GIOP version */
85             (byte) 0 /* GIOP revision*/);
86          Codec JavaDoc codec = info.codec_factory().create_codec(encoding);
87             
88          // Create and register client interceptor
89
SASClientIdentityInterceptor clientInterceptor =
90             new SASClientIdentityInterceptor(codec);
91          info.add_client_request_interceptor(clientInterceptor);
92
93          // Create and register server interceptor
94
SASTargetInterceptor serverInterceptor =
95             new SASTargetInterceptor(codec);
96          info.add_server_request_interceptor(serverInterceptor);
97  
98          // Initialize the SASCurrent implementation
99
org.omg.CORBA.Object JavaDoc obj =
100             info.resolve_initial_references("SASCurrent");
101          final SASCurrentImpl sasCurrentImpl = (SASCurrentImpl) obj;
102          sasCurrentImpl.init(serverInterceptor);
103
104          // Create and register an AuthenticationObserver to be called
105
// by the SecurityInterceptor
106
Registry.bind(SecurityInterceptor.AuthenticationObserver.KEY,
107                        new SecurityInterceptor.AuthenticationObserver() {
108                           public void authenticationFailed()
109                           {
110                              sasCurrentImpl.reject_incoming_context();
111                           }
112                        });
113       }
114       catch(Exception JavaDoc e)
115       {
116          throw new RuntimeException JavaDoc("Unexpected " + e);
117       }
118    }
119
120 }
121
Popular Tags