001: /*
002: * Tomcat: The deployer for the tomcat daemon
003: * Created on July 10, 2007, 6:52 AM
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: * CoadunationInterceptor.java
020: */
021:
022: // package paths
023: package com.rift.coad.daemon.tomcat.security;
024:
025: // log 4 j imports
026: import org.apache.log4j.Logger;
027:
028: // coadunation imports
029: import com.rift.coad.lib.interceptor.ServerInterceptor;
030: import com.rift.coad.lib.interceptor.InterceptorWrapper;
031: import com.rift.coad.lib.security.UserSession;
032: import com.rift.coad.lib.interceptor.credentials.Session;
033:
034: /**
035: * The coadunation interceptor.
036: *
037: * @author brett
038: */
039: public class CoadunationInterceptor extends InterceptorWrapper {
040:
041: // static member variables
042: protected static Logger log = Logger
043: .getLogger(CoadunationInterceptor.class.getName());
044: private static CoadunationInterceptor singleton = null;
045:
046: // private member variables
047: private ThreadLocal threadSession = new ThreadLocal();
048:
049: /**
050: * Creates a new instance of CoadunationInterceptor
051: */
052: public CoadunationInterceptor() {
053: }
054:
055: /**
056: * This method is called to sudo a user
057: */
058: public void pushUser(UserSession session) {
059: threadSession.set(session);
060: if (session == null) {
061: return;
062: }
063: try {
064: this .getServerInterceptor().createSession(
065: new Session(session.getName(), session
066: .getSessionId(), session.getPrincipals()));
067: } catch (Exception ex) {
068: log.error(
069: "Failed to create a session : " + ex.getMessage(),
070: ex);
071: }
072: }
073:
074: /**
075: * This method will be called to pop a user after the valve call has
076: * terminated.
077: */
078: public void popUser() {
079: if (threadSession.get() == null) {
080: return;
081: }
082: try {
083: this .getServerInterceptor().release();
084: threadSession.set(null);
085: } catch (Exception ex) {
086: log.error("Failed to release a session : "
087: + ex.getMessage(), ex);
088: }
089: }
090:
091: /**
092: * This method returns the singleton instance.
093: */
094: public synchronized static CoadunationInterceptor getInstance() {
095: if (singleton == null) {
096: singleton = new CoadunationInterceptor();
097: }
098: return singleton;
099: }
100: }
|