001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.yoko;
017:
018: import java.net.Socket;
019: import javax.net.ssl.SSLSession;
020: import javax.net.ssl.SSLSocket;
021:
022: import org.apache.yoko.orb.PortableInterceptor.ServerRequestInfoExt;
023: import org.apache.yoko.orb.OCI.IIOP.TransportInfo_impl;
024: import org.apache.commons.logging.Log;
025: import org.apache.commons.logging.LogFactory;
026: import org.omg.CORBA.LocalObject;
027: import org.omg.PortableInterceptor.ServerRequestInfo;
028: import org.omg.PortableInterceptor.ServerRequestInterceptor;
029:
030: import org.apache.geronimo.corba.security.SSLSessionManager;
031:
032: /**
033: * A service context interceptor to help manage
034: * SSL security information for incoming connections.
035: * @version $Revision: 452600 $ $Date: 2006-10-03 12:29:42 -0700 (Tue, 03 Oct 2006) $
036: */
037: final class ServiceContextInterceptor extends LocalObject implements
038: ServerRequestInterceptor {
039:
040: private final Log log = LogFactory
041: .getLog(ServiceContextInterceptor.class);
042:
043: public ServiceContextInterceptor() {
044: if (log.isDebugEnabled())
045: log.debug("<init>");
046: }
047:
048: public void receive_request(ServerRequestInfo ri) {
049: }
050:
051: public void receive_request_service_contexts(ServerRequestInfo ri) {
052:
053: if (log.isDebugEnabled())
054: log.debug("Looking for SSL Session");
055:
056: // for an incoming request, we need to see if the request is coming in on
057: // an SSLSocket. If this is using a secure connection, then we register the
058: // request and SSLSession with the session manager.
059: ServerRequestInfoExt riExt = (ServerRequestInfoExt) ri;
060: TransportInfo_impl connection = (TransportInfo_impl) riExt
061: .getTransportInfo();
062: if (connection != null) {
063: Socket socket = connection.socket();
064: if (socket != null && socket instanceof SSLSocket) {
065: if (log.isDebugEnabled())
066: log.debug("Found SSL Session");
067: SSLSocket sslSocket = (SSLSocket) socket;
068:
069: SSLSessionManager.setSSLSession(ri.request_id(),
070: sslSocket.getSession());
071: }
072: }
073: }
074:
075: public void send_exception(ServerRequestInfo ri) {
076: // clean any SSL session information if we registered.
077: SSLSession old = SSLSessionManager.clearSSLSession(ri
078: .request_id());
079: if (log.isDebugEnabled() && old != null)
080: log.debug("Removing SSL Session for send_exception");
081: }
082:
083: public void send_other(ServerRequestInfo ri) {
084: // clean any SSL session information if we registered.
085: SSLSession old = SSLSessionManager.clearSSLSession(ri
086: .request_id());
087: if (log.isDebugEnabled() && old != null)
088: log.debug("Removing SSL Session for send_reply");
089: }
090:
091: public void send_reply(ServerRequestInfo ri) {
092: // clean any SSL session information if we registered.
093: SSLSession old = SSLSessionManager.clearSSLSession(ri
094: .request_id());
095: if (log.isDebugEnabled() && old != null)
096: log.debug("Removing SSL Session for send_reply");
097: }
098:
099: public void destroy() {
100: if (log.isDebugEnabled())
101: log.debug("Destroy");
102: }
103:
104: public String name() {
105: return "org.apache.geronimo.yoko.ServiceContextInterceptor";
106: }
107: }
|