001: /*
002: * CoadunationLib: The coaduntion implementation library.
003: * Copyright (C) 2006 Rift IT Contracting
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
018: *
019: * SecurityServerInterceptor.java
020: *
021: * The security server interceptor is responsible for intercepting the call on
022: * the server and setting up the security context appropriatly.
023: */
024:
025: // package path
026: package com.rift.coad.lib.interceptor.iiop;
027:
028: // java imports
029: import java.util.MissingResourceException;
030: import org.omg.CORBA.TIMEOUT;
031: import org.omg.IOP.ServiceContext;
032: import org.omg.PortableInterceptor.ServerRequestInterceptor;
033: import org.omg.PortableInterceptor.ServerRequestInfo;
034: import org.omg.PortableInterceptor.ForwardRequest;
035: import org.omg.PortableInterceptor.ORBInitInfo;
036:
037: // logging import
038: import org.apache.log4j.Logger;
039:
040: // coadunation imports
041: import com.rift.coad.lib.common.ObjectSerializer;
042: import com.rift.coad.lib.interceptor.credentials.Credential;
043: import com.rift.coad.lib.interceptor.InterceptorWrapper;
044: import com.rift.coad.lib.interceptor.ServerInterceptor;
045:
046: /**
047: * The security server interceptor is responsible for intercepting the call on
048: * the server and setting up the security context appropriatly.
049: *
050: * @author Brett Chaldecott
051: */
052: public class SecurityServerInterceptor extends InterceptorWrapper
053: implements ServerRequestInterceptor {
054: // the class log variable
055: protected static Logger log = Logger
056: .getLogger(SecurityServerInterceptor.class.getName());
057:
058: /**
059: * Creates a new instance of SecurityServerInterceptor
060: */
061: public SecurityServerInterceptor(ORBInitInfo info) {
062: }
063:
064: /**
065: * This method returns the name of this interceptor.
066: *
067: * @return A string containing the name of this interceptor.
068: */
069: public String name() {
070: return "SecurityServerInterceptor";
071: }
072:
073: /**
074: * This method is called to distory this object.
075: */
076: public void destroy() {
077: // do nothing for time being
078: }
079:
080: /**
081: * Allows the interceptor to process service context information.
082: *
083: * @param ri The reference to the request information
084: */
085: public void receive_request_service_contexts(ServerRequestInfo ri) {
086:
087: }
088:
089: /**
090: * Allows an Interceptor to query request information after all the
091: * information, including operation parameters, are available.
092: */
093: public void receive_request(ServerRequestInfo ri) {
094: try {
095: // this logic assums that the context will not get set internally
096: // and stuff this logic up
097: log.debug("Receive a request on the server side");
098: ServiceContext serviceContext = ri
099: .get_request_service_context(Constants.STANDARD_SECURITY_CONTEXT_ID);
100: if (serviceContext != null) {
101: Credential credential = (Credential) ObjectSerializer
102: .deserialize(serviceContext.context_data);
103: this .getServerInterceptor().createSession(credential);
104: }
105: } catch (org.omg.CORBA.BAD_PARAM ex) {
106: // ignore the bad param exception
107: } catch (Exception ex) {
108: log.debug("Failed to setup the security because : "
109: + ex.getMessage(), ex);
110: }
111: }
112:
113: /**
114: * Allows an Interceptor to query the exception information and modify the
115: * reply service context before the exception is thrown to the client.
116: */
117: public void send_exception(ServerRequestInfo ri) {
118: try {
119: // this logic assums that the context will not get set internally
120: // and stuff this logic up
121: log.debug("Reply to a request on the server side.");
122: ServiceContext serviceContext = ri
123: .get_request_service_context(Constants.STANDARD_SECURITY_CONTEXT_ID);
124: if (serviceContext != null) {
125: this .getServerInterceptor().release();
126: }
127: } catch (org.omg.CORBA.BAD_PARAM ex) {
128: // ignore the bad param exception
129: } catch (Exception ex) {
130: log.debug("Failed to release security because : "
131: + ex.getMessage(), ex);
132: }
133: }
134:
135: /**
136: * Allows an Interceptor to query the information available when a request
137: * results in something other than a normal reply or an exception.
138: */
139: public void send_other(ServerRequestInfo ri) {
140:
141: }
142:
143: /**
144: * Allows an Interceptor to query reply information and modify the reply
145: * service context after the target operation has been invoked and before
146: * the reply is returned to the client.
147: */
148: public void send_reply(ServerRequestInfo ri) {
149: try {
150: // this logic assums that the context will not get set internally
151: // and stuff this logic up
152: log.debug("Reply to a request on the server side.");
153: ServiceContext serviceContext = ri
154: .get_request_service_context(Constants.STANDARD_SECURITY_CONTEXT_ID);
155: if (serviceContext != null) {
156: this .getServerInterceptor().release();
157: }
158: } catch (org.omg.CORBA.BAD_PARAM ex) {
159: // ignore the bad param exception
160: } catch (Exception ex) {
161: log.debug("Failed to release security because : "
162: + ex.getMessage(), ex);
163: }
164: }
165:
166: }
|