KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > interceptor > iiop > SecurityServerInterceptor


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * SecurityServerInterceptor.java
20  *
21  * The security server interceptor is responsible for intercepting the call on
22  * the server and setting up the security context appropriatly.
23  */

24
25 // package path
26
package com.rift.coad.lib.interceptor.iiop;
27
28 // java imports
29
import java.util.MissingResourceException JavaDoc;
30 import org.omg.CORBA.TIMEOUT JavaDoc;
31 import org.omg.IOP.ServiceContext JavaDoc;
32 import org.omg.PortableInterceptor.ServerRequestInterceptor JavaDoc;
33 import org.omg.PortableInterceptor.ServerRequestInfo JavaDoc;
34 import org.omg.PortableInterceptor.ForwardRequest JavaDoc;
35 import org.omg.PortableInterceptor.ORBInitInfo JavaDoc;
36
37 // logging import
38
import org.apache.log4j.Logger;
39
40 // coadunation imports
41
import com.rift.coad.lib.common.ObjectSerializer;
42 import com.rift.coad.lib.interceptor.credentials.Credential;
43 import com.rift.coad.lib.interceptor.InterceptorWrapper;
44 import com.rift.coad.lib.interceptor.ServerInterceptor;
45
46
47
48 /**
49  * The security server interceptor is responsible for intercepting the call on
50  * the server and setting up the security context appropriatly.
51  *
52  * @author Brett Chaldecott
53  */

54 public class SecurityServerInterceptor extends InterceptorWrapper implements
55         ServerRequestInterceptor JavaDoc {
56     // the class log variable
57
protected static Logger log =
58             Logger.getLogger(SecurityServerInterceptor.class.getName());
59     
60     
61     /**
62      * Creates a new instance of SecurityServerInterceptor
63      */

64     public SecurityServerInterceptor(ORBInitInfo JavaDoc info) {
65     }
66     
67     
68     /**
69      * This method returns the name of this interceptor.
70      *
71      * @return A string containing the name of this interceptor.
72      */

73     public String JavaDoc name() {
74         return "SecurityServerInterceptor";
75     }
76     
77     
78     /**
79      * This method is called to distory this object.
80      */

81     public void destroy() {
82         // do nothing for time being
83
}
84     
85     
86     /**
87      * Allows the interceptor to process service context information.
88      *
89      * @param ri The reference to the request information
90      */

91     public void receive_request_service_contexts(ServerRequestInfo JavaDoc ri) {
92         
93     }
94           
95     
96     /**
97      * Allows an Interceptor to query request information after all the
98      * information, including operation parameters, are available.
99      */

100     public void receive_request(ServerRequestInfo JavaDoc ri) {
101         try {
102             // this logic assums that the context will not get set internally
103
// and stuff this logic up
104
log.debug("Receive a request on the server side");
105             ServiceContext JavaDoc serviceContext = ri.get_request_service_context(
106                     Constants.STANDARD_SECURITY_CONTEXT_ID);
107             if (serviceContext != null) {
108                 Credential credential = (Credential)ObjectSerializer.
109                         deserialize(serviceContext.context_data);
110                 this.getServerInterceptor().createSession(credential);
111             }
112         } catch (org.omg.CORBA.BAD_PARAM JavaDoc ex) {
113             // ignore the bad param exception
114
} catch (Exception JavaDoc ex) {
115             log.debug("Failed to setup the security because : "
116                     + ex.getMessage(),ex);
117         }
118     }
119     
120     
121     /**
122      * Allows an Interceptor to query the exception information and modify the
123      * reply service context before the exception is thrown to the client.
124      */

125     public void send_exception(ServerRequestInfo JavaDoc ri) {
126         try {
127             // this logic assums that the context will not get set internally
128
// and stuff this logic up
129
log.debug("Reply to a request on the server side.");
130             ServiceContext JavaDoc serviceContext = ri.get_request_service_context(
131                     Constants.STANDARD_SECURITY_CONTEXT_ID);
132             if (serviceContext != null) {
133                 this.getServerInterceptor().release();
134             }
135         } catch (org.omg.CORBA.BAD_PARAM JavaDoc ex) {
136             // ignore the bad param exception
137
} catch (Exception JavaDoc ex) {
138             log.debug("Failed to release security because : " +
139                     ex.getMessage(),ex);
140         }
141     }
142     
143     
144     /**
145      * Allows an Interceptor to query the information available when a request
146      * results in something other than a normal reply or an exception.
147      */

148     public void send_other(ServerRequestInfo JavaDoc ri) {
149         
150     }
151     
152     
153     /**
154      * Allows an Interceptor to query reply information and modify the reply
155      * service context after the target operation has been invoked and before
156      * the reply is returned to the client.
157      */

158     public void send_reply(ServerRequestInfo JavaDoc ri) {
159         try {
160             // this logic assums that the context will not get set internally
161
// and stuff this logic up
162
log.debug("Reply to a request on the server side.");
163             ServiceContext JavaDoc serviceContext = ri.get_request_service_context(
164                     Constants.STANDARD_SECURITY_CONTEXT_ID);
165             if (serviceContext != null) {
166                 this.getServerInterceptor().release();
167             }
168         } catch (org.omg.CORBA.BAD_PARAM JavaDoc ex) {
169             // ignore the bad param exception
170
} catch (Exception JavaDoc ex) {
171             log.debug("Failed to release security because : " +
172                     ex.getMessage(),ex);
173         }
174     }
175           
176 }
177
Popular Tags