001: /*
002: * Copyright 1999,2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.catalina.authenticator;
018:
019: import java.util.ArrayList;
020: import java.util.HashMap;
021: import java.util.Iterator;
022: import java.util.Locale;
023:
024: import javax.servlet.http.Cookie;
025:
026: /**
027: * Object that saves the critical information from a request so that
028: * form-based authentication can reproduce it once the user has been
029: * authenticated.
030: * <p>
031: * <b>IMPLEMENTATION NOTE</b> - It is assumed that this object is accessed
032: * only from the context of a single thread, so no synchronization around
033: * internal collection classes is performed.
034: * <p>
035: * <b>FIXME</b> - Currently, this object has no mechanism to save or
036: * restore the data content of the request, although it does save
037: * request parameters so that a POST transaction can be faithfully
038: * duplicated.
039: *
040: * @author Craig R. McClanahan
041: * @version $Revision: 1.3 $ $Date: 2004/02/27 14:58:41 $
042: */
043:
044: public final class SavedRequest {
045:
046: /**
047: * The set of Cookies associated with this Request.
048: */
049: private ArrayList cookies = new ArrayList();
050:
051: public void addCookie(Cookie cookie) {
052: cookies.add(cookie);
053: }
054:
055: public Iterator getCookies() {
056: return (cookies.iterator());
057: }
058:
059: /**
060: * The set of Headers associated with this Request. Each key is a header
061: * name, while the value is a ArrayList containing one or more actual
062: * values for this header. The values are returned as an Iterator when
063: * you ask for them.
064: */
065: private HashMap headers = new HashMap();
066:
067: public void addHeader(String name, String value) {
068: ArrayList values = (ArrayList) headers.get(name);
069: if (values == null) {
070: values = new ArrayList();
071: headers.put(name, values);
072: }
073: values.add(value);
074: }
075:
076: public Iterator getHeaderNames() {
077: return (headers.keySet().iterator());
078: }
079:
080: public Iterator getHeaderValues(String name) {
081: ArrayList values = (ArrayList) headers.get(name);
082: if (values == null)
083: return ((new ArrayList()).iterator());
084: else
085: return (values.iterator());
086: }
087:
088: /**
089: * The set of Locales associated with this Request.
090: */
091: private ArrayList locales = new ArrayList();
092:
093: public void addLocale(Locale locale) {
094: locales.add(locale);
095: }
096:
097: public Iterator getLocales() {
098: return (locales.iterator());
099: }
100:
101: /**
102: * The request method used on this Request.
103: */
104: private String method = null;
105:
106: public String getMethod() {
107: return (this .method);
108: }
109:
110: public void setMethod(String method) {
111: this .method = method;
112: }
113:
114: /**
115: * The set of request parameters associated with this Request. Each
116: * entry is keyed by the parameter name, pointing at a String array of
117: * the corresponding values.
118: */
119: private HashMap parameters = new HashMap();
120:
121: public void addParameter(String name, String values[]) {
122: parameters.put(name, values);
123: }
124:
125: public Iterator getParameterNames() {
126: return (parameters.keySet().iterator());
127: }
128:
129: public String[] getParameterValues(String name) {
130: return ((String[]) parameters.get(name));
131: }
132:
133: /**
134: * The query string associated with this Request.
135: */
136: private String queryString = null;
137:
138: public String getQueryString() {
139: return (this .queryString);
140: }
141:
142: public void setQueryString(String queryString) {
143: this .queryString = queryString;
144: }
145:
146: /**
147: * The request URI associated with this Request.
148: */
149: private String requestURI = null;
150:
151: public String getRequestURI() {
152: return (this .requestURI);
153: }
154:
155: public void setRequestURI(String requestURI) {
156: this.requestURI = requestURI;
157: }
158:
159: }
|