001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 Networks Associates Technology, Inc
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: *
026: * Created on September 12, 2001, 10:55 AM
027: */
028:
029: package org.cougaar.lib.web.tomcat;
030:
031: import java.io.IOException;
032:
033: import javax.servlet.Servlet;
034: import javax.servlet.ServletConfig;
035: import javax.servlet.ServletException;
036: import javax.servlet.ServletRequest;
037: import javax.servlet.ServletResponse;
038:
039: /**
040: * This class is designed to load
041: * org.cougaar.core.security.acl.auth.SecureHookServlet if it
042: * exists and the System property
043: * <code>org.cougaar.lib.web.tomcat.enableAuth</code>
044: * is "true".
045: * <p>
046: * The <code>web.xml</code> should have within the <web-app> element:
047: * <pre>
048: * <servlet>
049: * <servlet-name>cougaar</servlet-name>
050: * <servlet-class>org.cougaar.lib.web.tomcat.HookServletFront</servlet-class>
051: * </servlet>
052: * </pre>
053: * <p>
054: * a privileged action under the principal of the user
055: * who has logged in.
056: *
057: * @property org.cougaar.lib.web.tomcat.auth.class
058: * classname for hook servlet override class.
059: * @property org.cougaar.lib.web.tomcat.enableAuth
060: * enable default hook class if the classname property
061: * is not specified.
062: */
063: public class HookServletFront implements Servlet {
064:
065: private static final String PROP_ENABLE = "org.cougaar.lib.web.tomcat.enableAuth";
066: private static final String PROP_CLASS = "org.cougaar.lib.web.tomcat.hookservlet.class";
067: private static final String DEFAULT_SECURE = "org.cougaar.core.security.acl.auth.SecureHookServlet";
068:
069: private Servlet _hookServlet = null;
070:
071: /**
072: * default constructor
073: */
074: public HookServletFront() {
075: String servletClass = System.getProperty(PROP_CLASS);
076: if (servletClass == null && Boolean.getBoolean(PROP_ENABLE)) {
077: servletClass = DEFAULT_SECURE;
078: }
079:
080: if (servletClass != null) {
081: try {
082: Class c = Class.forName(servletClass);
083: _hookServlet = (Servlet) c.newInstance();
084: } catch (ClassNotFoundException e) {
085: System.err.println("Error: could not find class "
086: + servletClass);
087: } catch (ClassCastException e) {
088: System.err.println("Error: the class " + servletClass
089: + " is not a Servlet");
090: } catch (Exception e) {
091: System.err.println("Error: Could not load the class "
092: + servletClass);
093: }
094: }
095:
096: if (_hookServlet == null) {
097: _hookServlet = new HookServlet();
098: }
099: }
100:
101: /**
102: * Call the hook servlet service
103: */
104: public void service(ServletRequest req, ServletResponse res)
105: throws ServletException, IOException {
106: _hookServlet.service(req, res);
107: }
108:
109: /**
110: * Prepare the hook servlet to be destroyed.
111: */
112: public void destroy() {
113: _hookServlet.destroy();
114: }
115:
116: /**
117: * Calls the Hook Servlet init()
118: */
119: public void init(ServletConfig config) throws ServletException {
120: _hookServlet.init(config);
121: }
122:
123: /**
124: * Return the ServletConfig we got in init()
125: */
126: public ServletConfig getServletConfig() {
127: return _hookServlet.getServletConfig();
128: }
129:
130: /**
131: * Returns the hook servlet's info, if available
132: */
133: public String getServletInfo() {
134: return _hookServlet.getServletInfo();
135: }
136: }
|