You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by cr...@locus.apache.org on 2000/04/14 20:55:31 UTC
cvs commit: jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security HttpBasicAuth.java HttpSecurityValve.java
craigmcc 00/04/14 11:55:31
Modified: proposals/catalina/src/share/org/apache/tomcat Request.java
proposals/catalina/src/share/org/apache/tomcat/connector
RequestBase.java
proposals/catalina/src/share/org/apache/tomcat/connector/http
HttpConnector.java
proposals/catalina/src/share/org/apache/tomcat/security
HttpBasicAuth.java HttpSecurityValve.java
Added: proposals/catalina/src/share/org/apache/tomcat
HttpRequest.java
proposals/catalina/src/share/org/apache/tomcat/connector
HttpRequestBase.java
proposals/catalina/src/share/org/apache/tomcat/connector/http
HttpRequestImpl.java
Removed: proposals/catalina/src/share/org/apache/tomcat/connector/http
HttpRequest.java
Log:
Factor the "generic" and "HTTP-specific" portions of the Request interface
(and the corresponding implementation classes) into separate layers so
that a non-HTTP connector need not deal with the HTTP-related stuff.
Shortly the corresponding changes for the response side will be checked
in.
Revision Changes Path
1.4 +7 -75 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Request.java
Index: Request.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Request.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Request.java 2000/04/11 00:27:51 1.3
+++ Request.java 2000/04/14 18:55:26 1.4
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Request.java,v 1.3 2000/04/11 00:27:51 craigmcc Exp $
- * $Revision: 1.3 $
- * $Date: 2000/04/11 00:27:51 $
+ * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Request.java,v 1.4 2000/04/14 18:55:26 craigmcc Exp $
+ * $Revision: 1.4 $
+ * $Date: 2000/04/14 18:55:26 $
*
* ====================================================================
*
@@ -67,21 +67,18 @@
import java.io.InputStream;
import java.io.IOException;
-import java.security.Principal;
-import java.util.Locale;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletRequest;
-import javax.servlet.http.Cookie;
/**
- * A <b>Request</b> is the Tomcat-internal facade for an
- * <code>ServletRequest</code> or <code>HttpServletRequest</code>
- * that is to be processed, in order to produce a corresponding Response.
+ * A <b>Request</b> is the Tomcat-internal facade for a
+ * <code>ServletRequest</code> that is to be processed, in order to
+ * produce the corresponding <code>Response</code>.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.3 $ $Date: 2000/04/11 00:27:51 $
+ * @version $Revision: 1.4 $ $Date: 2000/04/14 18:55:26 $
*/
public interface Request {
@@ -168,32 +165,6 @@
/**
- * Add a Cookie to the set of Cookies associated with this Request.
- *
- * @param cookie The new cookie
- */
- public void addCookie(Cookie cookie);
-
-
- /**
- * Add a Header to the set of Headers associated with this Request.
- *
- * @param name The new header name
- * @param value The new header value
- */
- public void addHeader(String name, String value);
-
-
- /**
- * Add a Locale to the set of preferred Locales for this Request. The
- * first added Locale will be the first one returned by getLocales().
- *
- * @param locale The new preferred Locale
- */
- public void addLocale(Locale locale);
-
-
- /**
* Create and return a ServletInputStream to read the content
* associated with this Request.
*
@@ -210,16 +181,6 @@
/**
- * Set the authentication type used for this request, if any; otherwise
- * set the type to <code>null</code>. Typical values are "BASIC",
- * "DIGEST", or "SSL".
- *
- * @param type The authentication type used
- */
- public void setAuthType(String type);
-
-
- /**
* Set the content length associated with this Request.
*
* @param length The new content length
@@ -238,14 +199,6 @@
/**
- * Set the HTTP request method used for this Request.
- *
- * @param method The request method
- */
- public void setMethod(String method);
-
-
- /**
* Set the protocol name and version associated with this Request.
*
* @param protocol Protocol name and version
@@ -264,16 +217,6 @@
/**
- * Set the unparsed request URI for this Request. This value cannot be
- * parsed until <code>setContext()</code> has been called. <b>FIXME</b>:
- * how and when is parsing initiated?
- *
- * @param uri The request URI
- */
- public void setRequestURI(String uri);
-
-
- /**
* Set the name of the scheme associated with this request. Typical values
* are <code>http</code>, <code>https</code>, and <code>ftp</code>.
*
@@ -307,15 +250,4 @@
public void setServerPort(int port);
- /**
- * Set the Principal who has been authenticated for this Request. This
- * value is also used to calculate the value to be returned by the
- * <code>getRemoteUser()</code> method.
- *
- * @param principal The user Principal
- */
- public void setUserPrincipal(Principal principal);
-
-
}
-
1.1 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/HttpRequest.java
Index: HttpRequest.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/HttpRequest.java,v 1.1 2000/04/14 18:55:26 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/04/14 18:55:26 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.tomcat;
import java.security.Principal;
import java.util.Locale;
import javax.servlet.http.Cookie;
/**
* An <b>HttpRequest</b> is the Tomcat internal facade for an
* <code>HttpServletRequest</code> that is to be processed, in order to
* produce the corresponding <code>HttpResponse</code>.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/04/14 18:55:26 $
*/
public interface HttpRequest extends Request {
// --------------------------------------------------------- Public Methods
/**
* Add a Cookie to the set of Cookies associated with this Request.
*
* @param cookie The new cookie
*/
public void addCookie(Cookie cookie);
/**
* Add a Header to the set of Headers associated with this Request.
*
* @param name The new header name
* @param value The new header value
*/
public void addHeader(String name, String value);
/**
* Add a Locale to the set of preferred Locales for this Request. The
* first added Locale will be the first one returned by getLocales().
*
* @param locale The new preferred Locale
*/
public void addLocale(Locale locale);
/**
* Set the authentication type used for this request, if any; otherwise
* set the type to <code>null</code>. Typical values are "BASIC",
* "DIGEST", or "SSL".
*
* @param type The authentication type used
*/
public void setAuthType(String type);
/**
* Set the HTTP request method used for this Request.
*
* @param method The request method
*/
public void setMethod(String method);
/**
* Set the unparsed request URI for this Request. This value cannot be
* parsed until <code>setContext()</code> has been called. <b>FIXME</b>:
* how and when is parsing initiated?
*
* @param uri The request URI
*/
public void setRequestURI(String uri);
/**
* Set the Principal who has been authenticated for this Request. This
* value is also used to calculate the value to be returned by the
* <code>getRemoteUser()</code> method.
*
* @param principal The user Principal
*/
public void setUserPrincipal(Principal principal);
}
1.3 +5 -423 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/RequestBase.java
Index: RequestBase.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/RequestBase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RequestBase.java 2000/04/11 00:27:52 1.2
+++ RequestBase.java 2000/04/14 18:55:27 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/RequestBase.java,v 1.2 2000/04/11 00:27:52 craigmcc Exp $
- * $Revision: 1.2 $
- * $Date: 2000/04/11 00:27:52 $
+ * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/RequestBase.java,v 1.3 2000/04/14 18:55:27 craigmcc Exp $
+ * $Revision: 1.3 $
+ * $Date: 2000/04/14 18:55:27 $
*
* ====================================================================
*
@@ -77,9 +77,6 @@
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletRequest;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
import org.apache.tomcat.Connector;
import org.apache.tomcat.Context;
import org.apache.tomcat.Request;
@@ -92,11 +89,11 @@
* the connector-specific methods need to be implemented.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.2 $ $Date: 2000/04/11 00:27:52 $
+ * @version $Revision: 1.3 $ $Date: 2000/04/14 18:55:27 $
*/
public class RequestBase
- implements HttpServletRequest, Request {
+ implements ServletRequest, Request {
// ----------------------------------------------------- Instance Variables
@@ -109,12 +106,6 @@
/**
- * The authentication type used for this request.
- */
- protected String authType = null;
-
-
- /**
* The Connector through which this Request was received.
*/
protected Connector connector = null;
@@ -139,18 +130,6 @@
/**
- * The set of cookies associated with this Request.
- */
- protected Vector cookies = new Vector();
-
-
- /**
- * The HTTP headers associated with this Request, keyed by name.
- */
- protected Hashtable headers = new Hashtable();
-
-
- /**
* Descriptive information about this Request implementation.
*/
protected static final String info =
@@ -164,12 +143,6 @@
/**
- * The request method associated with this Request.
- */
- protected String method = null;
-
-
- /**
* The protocol name and version associated with this Request.
*/
protected String protocol = null;
@@ -182,12 +155,6 @@
/**
- * The request URI associated with this request.
- */
- protected String requestUri = null;
-
-
- /**
* The response with which this request is associated.
*/
protected Response response = null;
@@ -223,12 +190,6 @@
protected InputStream stream = null;
- /**
- * The Principal who has been authenticated for this Request.
- */
- protected Principal userPrincipal;
-
-
// ------------------------------------------------------------- Properties
@@ -350,31 +311,6 @@
/**
- * Add a Cookie to the set of Cookies associated with this Request.
- *
- * @param cookie The new cookie
- */
- public void addCookie(Cookie cookie) {
-
- cookies.addElement(cookie);
-
- }
-
-
- /**
- * Add a Header to the set of Headers associated with this Request.
- *
- * @param name The new header name
- * @param value The new header value
- */
- public void addHeader(String name, String value) {
-
- headers.put(name.toLowerCase(), value);
-
- }
-
-
- /**
* Add a Locale to the set of preferred Locales for this Request. The
* first added Locale will be the first one returned by getLocales().
*
@@ -407,15 +343,11 @@
public void recycle() {
attributes.clear();
- authType = null;
// connector is NOT reset when recycling
contentLength = -1;
contentType = null;
context = null;
- cookies.removeAllElements();
- headers.clear();
locales.removeAllElements();
- method = null;
protocol = null;
response = null;
scheme = null;
@@ -427,20 +359,6 @@
/**
- * Set the authentication type used for this request, if any; otherwise
- * set the type to <code>null</code>. Typical values are "BASIC",
- * "DIGEST", or "SSL".
- *
- * @param type The authentication type used
- */
- public void setAuthType(String type) {
-
- this.authType = authType;
-
- }
-
-
- /**
* Set the content length associated with this Request.
*
* @param length The new content length
@@ -467,18 +385,6 @@
/**
- * Set the HTTP request method used for this Request.
- *
- * @param method The request method
- */
- public void setMethod(String method) {
-
- this.method = method;
-
- }
-
-
- /**
* Set the protocol name and version associated with this Request.
*
* @param protocol Protocol name and version
@@ -505,20 +411,6 @@
/**
- * Set the unparsed request URI for this Request. This value cannot be
- * parsed until <code>setContext()</code> has been called. <b>FIXME</b>:
- * how and when is parsing initiated?
- *
- * @param uri The request URI
- */
- public void setRequestURI(String uri) {
-
- this.requestUri = uri;
-
- }
-
-
- /**
* Set the name of the scheme associated with this request. Typical values
* are <code>http</code>, <code>https</code>, and <code>ftp</code>.
*
@@ -568,20 +460,6 @@
}
- /**
- * Set the Principal who has been authenticated for this Request. This
- * value is also used to calculate the value to be returned by the
- * <code>getRemoteUser()</code> method.
- *
- * @param principal The user Principal
- */
- public void setUserPrincipal(Principal principal) {
-
- this.userPrincipal = principal;
-
- }
-
-
// ------------------------------------------------- ServletRequest Methods
@@ -856,302 +734,6 @@
public void setAttribute(String name, Object value) {
attributes.put(name, value);
-
- }
-
-
- // --------------------------------------------- HttpServletRequest Methods
-
-
- /**
- * Return the authentication type used for this Request.
- */
- public String getAuthType() {
-
- return (this.authType);
-
- }
-
-
- /**
- * Return the portion of the request URI used to select the Context
- * of the Request.
- */
- public String getContextPath() {
-
- return (null); // FIXME: getContextPath()
-
- }
-
-
- /**
- * Return the set of Cookies received with this Request.
- */
- public Cookie[] getCookies() {
-
- synchronized (cookies) {
- Cookie results[] = new Cookie[cookies.size()];
- for (int i = 0; i < results.length; i++)
- results[i] = (Cookie) cookies.elementAt(i);
- return (results);
- }
-
- }
-
-
- /**
- * Return the value of the specified date header, if any; otherwise
- * return -1.
- *
- * @param name Name of the requested date header
- *
- * @exception IllegalArgumentException if the specified header value
- * cannot be converted to a date
- */
- public long getDateHeader(String name) {
-
- return (-1); // FIXME: getDateHeader()
-
- }
-
-
- /**
- * Return the first value of the specified header, if any; otherwise,
- * return <code>null</code>
- *
- * @param name Name of the requested header
- */
- public String getHeader(String name) {
-
- Vector values = (Vector) headers.get(name.toLowerCase());
- if (values == null)
- return (null);
- else
- return ((String) values.elementAt(0));
-
- }
-
-
- /**
- * Return all of the values of the specified header, if any; otherwise,
- * return <code>null</code>.
- *
- * @param name Name of the requested header
- */
- public Enumeration getHeaders(String name) {
-
- Vector values = (Vector) headers.get(name.toLowerCase());
- if (values != null)
- return (values.elements());
- else
- return (null);
-
- }
-
-
- /**
- * Return the names of all headers received with this request.
- */
- public Enumeration getHeaderNames() {
-
- return (headers.keys());
-
- }
-
-
- /**
- * Return the value of the specified header as an integer, or -1 if there
- * is no such header for this request.
- *
- * @param name Name of the requested header
- *
- * @exception IllegalArgumentException if the specified header value
- * cannot be converted to an integer
- */
- public int getIntHeader(String name) {
-
- return (-1); // FIXME: getIntHeader()
-
- }
-
-
- /**
- * Return the HTTP request method used in this Request.
- */
- public String getMethod() {
-
- return (this.method);
-
- }
-
-
- /**
- * Return the path information associated with this Request.
- */
- public String getPathInfo() {
-
- return (null); // FIXME: getPathInfo()
-
- }
-
-
- /**
- * Return the extra path information for this request, translated
- * to a real path.
- */
- public String getPathTranslated() {
-
- return (null); // FIXME: getPathTranslated()
-
- }
-
-
- /**
- * Return the query string associated with this request.
- */
- public String getQueryString() {
-
- return (null); // FIXME: getQueryString()
-
- }
-
-
- /**
- * Return the name of the remote user that has been authenticated
- * for this Request.
- */
- public String getRemoteUser() {
-
- if (userPrincipal != null)
- return (userPrincipal.getName());
- else
- return (null);
-
- }
-
-
- /**
- * Return the session identifier included in this request, if any.
- */
- public String getRequestedSessionId() {
-
- return (null); // FIXME: getRequestedSessionId()
-
- }
-
-
- /**
- * Return the request URI for this request.
- */
- public String getRequestURI() {
-
- return (this.requestUri);
-
- }
-
-
- /**
- * Return the portion of the request URI used to select the servlet
- * that will process this request.
- */
- public String getServletPath() {
-
- return (null); // FIXME: getServletPath()
-
- }
-
-
- /**
- * Return the session associated with this Request, creating one
- * if necessary.
- */
- public HttpSession getSession() {
-
- return (null); // FIXME: getSession()
-
- }
-
-
- /**
- * Return the session associated with this Request, creating one
- * if necessary and requested.
- *
- * @param create Create a new session if one does not exist
- */
- public HttpSession getSession(boolean create) {
-
- return (null); // FIXME: getSession(create)
-
- }
-
-
- /**
- * Return <code>true</code> if the session identifier included in this
- * request came from a cookie.
- */
- public boolean isRequestedSessionIdFromCookie() {
-
- return (false); // FIXME: isRequestedSessionIdFromCookie()
-
- }
-
-
- /**
- * Return <code>true</code> if the session identifier included in this
- * request came from the request URI.
- */
- public boolean isRequestedSessionIdFromURL() {
-
- return (false); // FIXME: isRequestedSessionIdFromURL()
-
- }
-
-
- /**
- * Return <code>true</code> if the session identifier included in this
- * request came from the request URI.
- *
- * @deprecated As of Version 2.1 of the Java Servlet API, use
- * <code>isRequestedSessionIdFromURL()</code> instead.
- */
- public boolean isRequestedSessionIdFromUrl() {
-
- return (isRequestedSessionIdFromURL());
-
- }
-
-
- /**
- * Return <code>true</code> if the session identifier included in this
- * request identifies a valid session.
- */
- public boolean isRequestedSessionIdValid() {
-
- return (false); // FIXME: isRequestedSessionIdValid()
-
- }
-
-
- /**
- * Return <code>true</code> if the authenticated user principal
- * possesses the specified role name. FIXME - Respect translations
- * in the web application deployment descriptor!
- *
- * @param role Role name to be validated
- */
- public boolean isUserInRole(String role) {
-
- return (false); // FIXME: isUserInRole()
-
- }
-
-
- /**
- * Return the principal that has been authenticated for this Request.
- */
- public Principal getUserPrincipal() {
-
- return (userPrincipal);
}
1.1 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/HttpRequestBase.java
Index: HttpRequestBase.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/HttpRequestBase.java,v 1.1 2000/04/14 18:55:27 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/04/14 18:55:27 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.tomcat.connector;
import java.security.Principal;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.tomcat.HttpRequest;
/**
* Convenience base implementation of the <b>HttpRequest</b> interface, which
* can be used for the Request implementation required by most Connectors that
* implement the HTTP protocol. Only the connector-specific methods need to
* be implemented.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/04/14 18:55:27 $
*/
public class HttpRequestBase
extends RequestBase
implements HttpRequest, HttpServletRequest {
// ----------------------------------------------------- Instance Variables
/**
* The authentication type used for this request.
*/
protected String authType = null;
/**
* The set of cookies associated with this Request.
*/
protected Vector cookies = new Vector();
/**
* The HTTP headers associated with this Request, keyed by name.
*/
protected Hashtable headers = new Hashtable();
/**
* Descriptive information about this HttpRequest implementation.
*/
protected static final String info =
"org.apache.tomcat.connector.HttpRequestBase/1.0";
/**
* The request method associated with this Request.
*/
protected String method = null;
/**
* The request URI associated with this request.
*/
protected String requestUri = null;
/**
* The Principal who has been authenticated for this Request.
*/
protected Principal userPrincipal;
// ------------------------------------------------------------- Properties
/**
* Return descriptive information about this Request implementation and
* the corresponding version number, in the format
* <code><description>/<version></code>.
*/
public String getInfo() {
return (info);
}
// --------------------------------------------------------- Public Methods
/**
* Add a Cookie to the set of Cookies associated with this Request.
*
* @param cookie The new cookie
*/
public void addCookie(Cookie cookie) {
cookies.addElement(cookie);
}
/**
* Add a Header to the set of Headers associated with this Request.
*
* @param name The new header name
* @param value The new header value
*/
public void addHeader(String name, String value) {
headers.put(name.toLowerCase(), value);
}
/**
* Release all object references, and initialize instance variables, in
* preparation for reuse of this object.
*/
public void recycle() {
super.recycle();
authType = null;
cookies.removeAllElements();
headers.clear();
method = null;
}
/**
* Set the authentication type used for this request, if any; otherwise
* set the type to <code>null</code>. Typical values are "BASIC",
* "DIGEST", or "SSL".
*
* @param type The authentication type used
*/
public void setAuthType(String type) {
this.authType = authType;
}
/**
* Set the HTTP request method used for this Request.
*
* @param method The request method
*/
public void setMethod(String method) {
this.method = method;
}
/**
* Set the unparsed request URI for this Request. This value cannot be
* parsed until <code>setContext()</code> has been called. <b>FIXME</b>:
* how and when is parsing initiated?
*
* @param uri The request URI
*/
public void setRequestURI(String uri) {
this.requestUri = uri;
}
/**
* Set the Principal who has been authenticated for this Request. This
* value is also used to calculate the value to be returned by the
* <code>getRemoteUser()</code> method.
*
* @param principal The user Principal
*/
public void setUserPrincipal(Principal principal) {
this.userPrincipal = principal;
}
// ------------------------------------------------- ServletRequest Methods
/**
* Return the value of the specified request parameter, if any; otherwise,
* return <code>null</code>. If there is more than one value defined,
* return only the first one.
*
* @param name Name of the desired request parameter
*/
public String getParameter(String name) {
return (null); // FIXME: getParameter()
}
/**
* Return the names of all defined request parameters for this request.
*/
public Enumeration getParameterNames() {
return (null); // FIXME: getParameterNames()
}
/**
* Return the defined values for the specified request parameter, if any;
* otherwise, return <code>null</code>.
*
* @param name Name of the desired request parameter
*/
public String[] getParameterValues(String name) {
return (null); // FIXME: getParameterValues()
}
// --------------------------------------------- HttpServletRequest Methods
/**
* Return the authentication type used for this Request.
*/
public String getAuthType() {
return (this.authType);
}
/**
* Return the portion of the request URI used to select the Context
* of the Request.
*/
public String getContextPath() {
return (null); // FIXME: getContextPath()
}
/**
* Return the set of Cookies received with this Request.
*/
public Cookie[] getCookies() {
synchronized (cookies) {
Cookie results[] = new Cookie[cookies.size()];
for (int i = 0; i < results.length; i++)
results[i] = (Cookie) cookies.elementAt(i);
return (results);
}
}
/**
* Return the value of the specified date header, if any; otherwise
* return -1.
*
* @param name Name of the requested date header
*
* @exception IllegalArgumentException if the specified header value
* cannot be converted to a date
*/
public long getDateHeader(String name) {
return (-1); // FIXME: getDateHeader()
}
/**
* Return the first value of the specified header, if any; otherwise,
* return <code>null</code>
*
* @param name Name of the requested header
*/
public String getHeader(String name) {
Vector values = (Vector) headers.get(name.toLowerCase());
if (values == null)
return (null);
else
return ((String) values.elementAt(0));
}
/**
* Return all of the values of the specified header, if any; otherwise,
* return <code>null</code>.
*
* @param name Name of the requested header
*/
public Enumeration getHeaders(String name) {
Vector values = (Vector) headers.get(name.toLowerCase());
if (values != null)
return (values.elements());
else
return (null);
}
/**
* Return the names of all headers received with this request.
*/
public Enumeration getHeaderNames() {
return (headers.keys());
}
/**
* Return the value of the specified header as an integer, or -1 if there
* is no such header for this request.
*
* @param name Name of the requested header
*
* @exception IllegalArgumentException if the specified header value
* cannot be converted to an integer
*/
public int getIntHeader(String name) {
return (-1); // FIXME: getIntHeader()
}
/**
* Return the HTTP request method used in this Request.
*/
public String getMethod() {
return (this.method);
}
/**
* Return the path information associated with this Request.
*/
public String getPathInfo() {
return (null); // FIXME: getPathInfo()
}
/**
* Return the extra path information for this request, translated
* to a real path.
*/
public String getPathTranslated() {
return (null); // FIXME: getPathTranslated()
}
/**
* Return the query string associated with this request.
*/
public String getQueryString() {
return (null); // FIXME: getQueryString()
}
/**
* Return the name of the remote user that has been authenticated
* for this Request.
*/
public String getRemoteUser() {
if (userPrincipal != null)
return (userPrincipal.getName());
else
return (null);
}
/**
* Return the session identifier included in this request, if any.
*/
public String getRequestedSessionId() {
return (null); // FIXME: getRequestedSessionId()
}
/**
* Return the request URI for this request.
*/
public String getRequestURI() {
return (this.requestUri);
}
/**
* Return the portion of the request URI used to select the servlet
* that will process this request.
*/
public String getServletPath() {
return (null); // FIXME: getServletPath()
}
/**
* Return the session associated with this Request, creating one
* if necessary.
*/
public HttpSession getSession() {
return (null); // FIXME: getSession()
}
/**
* Return the session associated with this Request, creating one
* if necessary and requested.
*
* @param create Create a new session if one does not exist
*/
public HttpSession getSession(boolean create) {
return (null); // FIXME: getSession(create)
}
/**
* Return <code>true</code> if the session identifier included in this
* request came from a cookie.
*/
public boolean isRequestedSessionIdFromCookie() {
return (false); // FIXME: isRequestedSessionIdFromCookie()
}
/**
* Return <code>true</code> if the session identifier included in this
* request came from the request URI.
*/
public boolean isRequestedSessionIdFromURL() {
return (false); // FIXME: isRequestedSessionIdFromURL()
}
/**
* Return <code>true</code> if the session identifier included in this
* request came from the request URI.
*
* @deprecated As of Version 2.1 of the Java Servlet API, use
* <code>isRequestedSessionIdFromURL()</code> instead.
*/
public boolean isRequestedSessionIdFromUrl() {
return (isRequestedSessionIdFromURL());
}
/**
* Return <code>true</code> if the session identifier included in this
* request identifies a valid session.
*/
public boolean isRequestedSessionIdValid() {
return (false); // FIXME: isRequestedSessionIdValid()
}
/**
* Return <code>true</code> if the authenticated user principal
* possesses the specified role name. FIXME - Respect translations
* in the web application deployment descriptor!
*
* @param role Role name to be validated
*/
public boolean isUserInRole(String role) {
return (false); // FIXME: isUserInRole()
}
/**
* Return the principal that has been authenticated for this Request.
*/
public Principal getUserPrincipal() {
return (userPrincipal);
}
}
1.3 +7 -6 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/http/HttpConnector.java
Index: HttpConnector.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/http/HttpConnector.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- HttpConnector.java 2000/04/10 20:01:36 1.2
+++ HttpConnector.java 2000/04/14 18:55:28 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/http/HttpConnector.java,v 1.2 2000/04/10 20:01:36 craigmcc Exp $
- * $Revision: 1.2 $
- * $Date: 2000/04/10 20:01:36 $
+ * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/http/HttpConnector.java,v 1.3 2000/04/14 18:55:28 craigmcc Exp $
+ * $Revision: 1.3 $
+ * $Date: 2000/04/14 18:55:28 $
*
* ====================================================================
*
@@ -71,6 +71,7 @@
import java.util.Stack;
import org.apache.tomcat.Connector;
import org.apache.tomcat.Container;
+import org.apache.tomcat.HttpRequest;
import org.apache.tomcat.Lifecycle;
import org.apache.tomcat.LifecycleEvent;
import org.apache.tomcat.LifecycleException;
@@ -309,7 +310,7 @@
*/
public Request newRequest() {
- HttpRequest request = new HttpRequest();
+ HttpRequestImpl request = new HttpRequestImpl();
request.setConnector(this);
return (request);
@@ -338,7 +339,7 @@
*
* @param request The request to be recycled
*/
- void recycle(Request request) {
+ void recycle(HttpRequest request) {
requests.push(request);
@@ -350,7 +351,7 @@
*
* @param response The response to be recycled
*/
- void recycle(Response response) {
+ void recycle(HttpResponse response) {
responses.push(response);
1.1 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/http/HttpRequestImpl.java
Index: HttpRequestImpl.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/connector/http/HttpRequestImpl.java,v 1.1 2000/04/14 18:55:28 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2000/04/14 18:55:28 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.tomcat.connector.http;
import org.apache.tomcat.connector.HttpRequestBase;
/**
* Implementation of <b>HttpRequest</b> specific to the HTTP connector.
*
* @author Craig R. McClanahan
* @version $Revision: 1.1 $ $Date: 2000/04/14 18:55:28 $
*/
final class HttpRequestImpl
extends HttpRequestBase {
// ----------------------------------------------------- Instance Variables
/**
* Descriptive information about this Request implementation.
*/
protected static final String info =
"org.apache.tomcat.connector.http.HttpRequestImpl/1.0";
// ------------------------------------------------------------- Properties
/**
* Return descriptive information about this Request implementation and
* the corresponding version number, in the format
* <code><description>/<version></code>.
*/
public String getInfo() {
return (info);
}
// --------------------------------------------------------- Public Methods
/**
* Release all object references, and initialize instance variables, in
* preparation for reuse of this object.
*/
public void recycle() {
super.recycle();
((HttpConnector) connector).recycle(this);
}
}
1.4 +6 -6 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/HttpBasicAuth.java
Index: HttpBasicAuth.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/HttpBasicAuth.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- HttpBasicAuth.java 2000/04/11 00:27:53 1.3
+++ HttpBasicAuth.java 2000/04/14 18:55:29 1.4
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/HttpBasicAuth.java,v 1.3 2000/04/11 00:27:53 craigmcc Exp $
- * $Revision: 1.3 $
- * $Date: 2000/04/11 00:27:53 $
+ * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/HttpBasicAuth.java,v 1.4 2000/04/14 18:55:29 craigmcc Exp $
+ * $Revision: 1.4 $
+ * $Date: 2000/04/14 18:55:29 $
*
* ====================================================================
*
@@ -69,8 +69,8 @@
import java.security.Principal;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.tomcat.HttpRequest;
import org.apache.tomcat.Realm;
-import org.apache.tomcat.Request;
import org.apache.tomcat.Response;
import org.apache.tomcat.deploy.LoginConfig;
@@ -84,7 +84,7 @@
* if this is not the case.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.3 $ $Date: 2000/04/11 00:27:53 $
+ * @version $Revision: 1.4 $ $Date: 2000/04/14 18:55:29 $
*/
final class HttpBasicAuth {
@@ -107,7 +107,7 @@
*
* @exception IOException if an input/output error occurs
*/
- public static boolean authenticate(Request request, Response response,
+ public static boolean authenticate(HttpRequest request, Response response,
LoginConfig config, Realm realm)
throws IOException {
1.2 +18 -8 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/HttpSecurityValve.java
Index: HttpSecurityValve.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/HttpSecurityValve.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HttpSecurityValve.java 2000/04/11 00:28:53 1.1
+++ HttpSecurityValve.java 2000/04/14 18:55:29 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/HttpSecurityValve.java,v 1.1 2000/04/11 00:28:53 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2000/04/11 00:28:53 $
+ * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/HttpSecurityValve.java,v 1.2 2000/04/14 18:55:29 craigmcc Exp $
+ * $Revision: 1.2 $
+ * $Date: 2000/04/14 18:55:29 $
*
* ====================================================================
*
@@ -74,6 +74,7 @@
import javax.servlet.http.HttpServletResponse;
import org.apache.tomcat.Container;
import org.apache.tomcat.Context;
+import org.apache.tomcat.HttpRequest;
import org.apache.tomcat.Lifecycle;
import org.apache.tomcat.LifecycleEvent;
import org.apache.tomcat.LifecycleException;
@@ -114,7 +115,7 @@
* </ul>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2000/04/11 00:28:53 $
+ * @version $Revision: 1.2 $ $Date: 2000/04/14 18:55:29 $
*/
@@ -214,6 +215,11 @@
throws IOException, ServletException {
// If this is not an HTTP request, do nothing
+ if (!(request instanceof HttpRequest) /* ||
+ !(response instanceof HttpResponse) */ ) {
+ invokeNext(request, response);
+ return;
+ }
if (!(request.getRequest() instanceof HttpServletRequest) ||
!(response.getResponse() instanceof HttpServletResponse)) {
invokeNext(request, response);
@@ -351,17 +357,21 @@
// Apply the requested login mechanism
if (method.equals(Constants.BASIC_METHOD))
- return (HttpBasicAuth.authenticate(request, response,
+ return (HttpBasicAuth.authenticate((HttpRequest) request,
+ response,
config, context.getRealm()));
/*
else if (method.equals(Constants.CERT_METHOD))
- return (ClientCertAuth.authenticate(request, response,
+ return (ClientCertAuth.authenticate((HttpRequest) request,
+ response,
config, context.getRealm()));
else if (method.equals(Constants.DIGEST_METHOD))
- return (HttpDigestAuth.authenticate(request, response,
+ return (HttpDigestAuth.authenticate((HttpRequest) request,
+ response,
config, context.getRealm()));
else if (method.equals(Constants.FORM_METHOD))
- return (LoginFormAuth.authenticate(request, response,
+ return (LoginFormAuth.authenticate(request,
+ response,
config, context.getRealm()));
*/
else {