001: /*
002: * (C) Copyright 2000 - 2003 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019:
020: package com.nabhinc.portal.container;
021:
022: import java.io.BufferedReader;
023: import java.io.IOException;
024: import java.io.UnsupportedEncodingException;
025: import java.security.Principal;
026: import java.util.Enumeration;
027: import java.util.Locale;
028: import java.util.Map;
029:
030: import javax.servlet.ServletInputStream;
031: import javax.servlet.http.HttpServletRequest;
032: import javax.servlet.http.HttpServletRequestWrapper;
033:
034: import com.nabhinc.spi.LocalUserInfo;
035: import com.nabhinc.spi.UserPrincipal;
036:
037: /**
038: *
039: *
040: * @author Padmanabh dabke
041: * (c) 2003 Nabh Information Systems, Inc. All Rights Reserved.
042: */
043: public class HttpServletRequestStringbeansWrapper extends
044: HttpServletRequestWrapper implements HttpServletRequest {
045:
046: HttpServletRequest hsriOriginalRequest = null;
047:
048: PortletRequestImpl hsriRenderRequest = null;
049:
050: LocalUserInfo hsriUserInfo = null;
051:
052: public HttpServletRequestStringbeansWrapper(HttpServletRequest req,
053: LocalUserInfo userInfo) {
054: super (req);
055: hsriOriginalRequest = req;
056: hsriUserInfo = userInfo;
057: }
058:
059: protected void setRenderRequest(RenderRequestImpl req) {
060: hsriRenderRequest = req;
061: }
062:
063: public LocalUserInfo getLocalUserInfo() {
064: return this .hsriUserInfo;
065: }
066:
067: public void setLocalUserInfo(LocalUserInfo uInfo) {
068: this .hsriUserInfo = uInfo;
069: }
070:
071: /* (non-Javadoc)
072: * @see javax.servlet.http.HttpServletRequest#getContextPath()
073: */
074: public String getContextPath() {
075: if (hsriRenderRequest == null) {
076: return super .getContextPath();
077: } else {
078: return hsriRenderRequest.getContextPath();
079: }
080: }
081:
082: /* (non-Javadoc)
083: * @see javax.servlet.http.HttpServletRequest#getRemoteUser()
084: */
085: public String getRemoteUser() {
086: if (hsriUserInfo == null)
087: return super .getRemoteUser();
088: return hsriUserInfo.userName;
089: }
090:
091: /* (non-Javadoc)
092: * @see javax.servlet.http.HttpServletRequest#getUserPrincipal()
093: */
094: public Principal getUserPrincipal() {
095: if (hsriUserInfo == null)
096: return super .getUserPrincipal();
097: if (hsriUserInfo.principal == null) {
098: hsriUserInfo.principal = new UserPrincipal(
099: hsriUserInfo.userName);
100: }
101: return hsriUserInfo.principal;
102: }
103:
104: /* (non-Javadoc)
105: * @see javax.servlet.http.HttpServletRequest#isUserInRole(java.lang.String)
106: */
107: public boolean isUserInRole(String arg0) {
108: String servletRole = arg0;
109: if (hsriRenderRequest != null) {
110: servletRole = hsriRenderRequest.getServletRole(arg0);
111: if (servletRole == null)
112: servletRole = arg0;
113: }
114:
115: if (hsriUserInfo == null) {
116: return super .isUserInRole(arg0);
117: } else {
118: for (int i = 0; i < hsriUserInfo.roles.length; i++) {
119: if (hsriUserInfo.roles[i].equals(arg0))
120: return true;
121: }
122: return false;
123: }
124: }
125:
126: /* (non-Javadoc)
127: * @see javax.servlet.http.HttpServletRequest#getRequestURL()
128: */
129: public StringBuffer getRequestURL() {
130: if (hsriRenderRequest == null)
131: return super .getRequestURL();
132: return null;
133: }
134:
135: /* (non-Javadoc)
136: * @see javax.servlet.ServletRequest#getCharacterEncoding()
137: */
138: public String getCharacterEncoding() {
139: if (hsriRenderRequest == null)
140: return super .getCharacterEncoding();
141: return null;
142: }
143:
144: /* (non-Javadoc)
145: * @see javax.servlet.ServletRequest#setCharacterEncoding(java.lang.String)
146: */
147: public void setCharacterEncoding(String arg0)
148: throws UnsupportedEncodingException {
149: if (hsriRenderRequest == null)
150: super .setCharacterEncoding(arg0);
151:
152: }
153:
154: /* (non-Javadoc)
155: * @see javax.servlet.ServletRequest#getContentLength()
156: */
157: public int getContentLength() {
158: if (hsriRenderRequest == null)
159: return super .getContentLength();
160: return 0;
161: }
162:
163: /* (non-Javadoc)
164: * @see javax.servlet.ServletRequest#getContentType()
165: */
166: public String getContentType() {
167: if (hsriRenderRequest == null)
168: return super .getContentType();
169: return null;
170: }
171:
172: /* (non-Javadoc)
173: * @see javax.servlet.ServletRequest#getInputStream()
174: */
175: public ServletInputStream getInputStream() throws IOException {
176: if (hsriRenderRequest == null)
177: return super .getInputStream();
178: return null;
179: }
180:
181: /* (non-Javadoc)
182: * @see javax.servlet.ServletRequest#getParameter(java.lang.String)
183: */
184: public String getParameter(String arg0) {
185: if (hsriRenderRequest == null)
186: return super .getParameter(arg0);
187: return hsriRenderRequest.getParameter(arg0);
188: }
189:
190: /* (non-Javadoc)
191: * @see javax.servlet.ServletRequest#getParameterNames()
192: */
193: public Enumeration getParameterNames() {
194: if (hsriRenderRequest == null)
195: return super .getParameterNames();
196: return hsriRenderRequest.getParameterNames();
197: }
198:
199: /* (non-Javadoc)
200: * @see javax.servlet.ServletRequest#getParameterValues(java.lang.String)
201: */
202: public String[] getParameterValues(String arg0) {
203: if (hsriRenderRequest == null)
204: return super .getParameterValues(arg0);
205: return hsriRenderRequest.getParameterValues(arg0);
206: }
207:
208: /* (non-Javadoc)
209: * @see javax.servlet.ServletRequest#getParameterMap()
210: */
211: public Map getParameterMap() {
212: if (hsriRenderRequest == null)
213: return super .getParameterMap();
214: return hsriRenderRequest.getParameterMap();
215: }
216:
217: /* (non-Javadoc)
218: * @see javax.servlet.ServletRequest#getProtocol()
219: */
220: public String getProtocol() {
221: if (hsriRenderRequest == null)
222: return super .getProtocol();
223: return null;
224: }
225:
226: /* (non-Javadoc)
227: * @see javax.servlet.ServletRequest#getReader()
228: */
229: public BufferedReader getReader() throws IOException {
230: if (hsriRenderRequest == null)
231: return super .getReader();
232: return null;
233: }
234:
235: /* (non-Javadoc)
236: * @see javax.servlet.ServletRequest#getRemoteAddr()
237: */
238: public String getRemoteAddr() {
239: if (hsriRenderRequest == null)
240: return super .getRemoteAddr();
241: return null;
242: }
243:
244: /* (non-Javadoc)
245: * @see javax.servlet.ServletRequest#getRemoteHost()
246: */
247: public String getRemoteHost() {
248: if (hsriRenderRequest == null)
249: return super .getRemoteHost();
250: return null;
251: }
252:
253: /* (non-Javadoc)
254: * @see javax.servlet.ServletRequest#getLocale()
255: */
256: public Locale getLocale() {
257: if (hsriRenderRequest == null)
258: return super .getLocale();
259: return hsriRenderRequest.getLocale();
260: }
261:
262: /* (non-Javadoc)
263: * @see javax.servlet.ServletRequest#getLocales()
264: */
265: public Enumeration getLocales() {
266: if (hsriRenderRequest == null)
267: return super .getLocales();
268: return hsriRenderRequest.getLocales();
269: }
270:
271: /* (non-Javadoc)
272: * @see javax.servlet.ServletRequest#getRealPath(java.lang.String)
273: */
274: public String getRealPath(String arg0) {
275: if (hsriRenderRequest == null)
276: return super .getRealPath(arg0);
277: return null;
278: }
279:
280: /* (non-Javadoc)
281: * @see javax.servlet.ServletRequest#getLocalAddr()
282: */
283: public String getLocalAddr() {
284: // Added to comply to Servlet 2.4 Specification
285: return null;
286: }
287:
288: /* (non-Javadoc)
289: * @see javax.servlet.ServletRequest#getLocalName()
290: */
291: public String getLocalName() {
292: // Added to comply to Servlet 2.4 Specification
293: if (hsriRenderRequest != null)
294: return hsriRenderRequest.getServerName();
295: else
296: return hsriOriginalRequest.getServerName();
297: }
298:
299: /* (non-Javadoc)
300: * @see javax.servlet.ServletRequest#getLocalPort()
301: */
302: public int getLocalPort() {
303: // Added to comply to Servlet 2.4 Specification
304: if (hsriRenderRequest != null)
305: return hsriRenderRequest.getServerPort();
306: else
307: return hsriOriginalRequest.getServerPort();
308: }
309:
310: /* (non-Javadoc)
311: * @see javax.servlet.ServletRequest#getRemotePort()
312: */
313: public int getRemotePort() {
314: // Added to comply to Servlet 2.4 Specification
315: return 0;
316: }
317:
318: }
|