You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ServletRequestWrapper.java 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. /*
  2. * Copyright 2011 gitblit.com.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.gitblit;
  17. import java.io.BufferedReader;
  18. import java.io.IOException;
  19. import java.io.UnsupportedEncodingException;
  20. import java.security.Principal;
  21. import java.util.Collection;
  22. import java.util.Enumeration;
  23. import java.util.Locale;
  24. import java.util.Map;
  25. import javax.servlet.AsyncContext;
  26. import javax.servlet.DispatcherType;
  27. import javax.servlet.RequestDispatcher;
  28. import javax.servlet.ServletContext;
  29. import javax.servlet.ServletException;
  30. import javax.servlet.ServletInputStream;
  31. import javax.servlet.ServletRequest;
  32. import javax.servlet.ServletResponse;
  33. import javax.servlet.http.Cookie;
  34. import javax.servlet.http.HttpServletRequest;
  35. import javax.servlet.http.HttpServletResponse;
  36. import javax.servlet.http.HttpSession;
  37. import javax.servlet.http.Part;
  38. /**
  39. * ServletRequestWrapper is a pass-through/delegate wrapper class for a servlet
  40. * request. This class is used in conjunction with ServletFilters, such as the
  41. * AccessRestrictionFilter.
  42. *
  43. * The original request is wrapped by instances of this class and this class is
  44. * set as the servlet request in the filter. This allows for specialized
  45. * implementations of request methods, like getUserPrincipal() with delegation
  46. * to the original request for any method not overridden.
  47. *
  48. * This class, by itself, is not altogether interesting. Subclasses of this
  49. * class, however, are of interest.
  50. *
  51. * @author James Moger
  52. *
  53. */
  54. public abstract class ServletRequestWrapper implements HttpServletRequest {
  55. protected final HttpServletRequest req;
  56. public ServletRequestWrapper(HttpServletRequest req) {
  57. this.req = req;
  58. }
  59. @Override
  60. public Object getAttribute(String name) {
  61. return req.getAttribute(name);
  62. }
  63. @Override
  64. public Enumeration getAttributeNames() {
  65. return req.getAttributeNames();
  66. }
  67. @Override
  68. public String getCharacterEncoding() {
  69. return req.getCharacterEncoding();
  70. }
  71. @Override
  72. public void setCharacterEncoding(String env) throws UnsupportedEncodingException {
  73. req.setCharacterEncoding(env);
  74. }
  75. @Override
  76. public int getContentLength() {
  77. return req.getContentLength();
  78. }
  79. @Override
  80. public String getContentType() {
  81. return req.getContentType();
  82. }
  83. @Override
  84. public ServletInputStream getInputStream() throws IOException {
  85. return req.getInputStream();
  86. }
  87. @Override
  88. public String getParameter(String name) {
  89. return req.getParameter(name);
  90. }
  91. @Override
  92. public Enumeration getParameterNames() {
  93. return req.getParameterNames();
  94. }
  95. @Override
  96. public String[] getParameterValues(String name) {
  97. return req.getParameterValues(name);
  98. }
  99. @Override
  100. public Map getParameterMap() {
  101. return req.getParameterMap();
  102. }
  103. @Override
  104. public String getProtocol() {
  105. return req.getProtocol();
  106. }
  107. @Override
  108. public String getScheme() {
  109. return req.getScheme();
  110. }
  111. @Override
  112. public String getServerName() {
  113. return req.getServerName();
  114. }
  115. @Override
  116. public int getServerPort() {
  117. return req.getServerPort();
  118. }
  119. @Override
  120. public BufferedReader getReader() throws IOException {
  121. return req.getReader();
  122. }
  123. @Override
  124. public String getRemoteAddr() {
  125. return req.getRemoteAddr();
  126. }
  127. @Override
  128. public String getRemoteHost() {
  129. return req.getRemoteHost();
  130. }
  131. @Override
  132. public void setAttribute(String name, Object o) {
  133. req.setAttribute(name, o);
  134. }
  135. @Override
  136. public void removeAttribute(String name) {
  137. req.removeAttribute(name);
  138. }
  139. @Override
  140. public Locale getLocale() {
  141. return req.getLocale();
  142. }
  143. @Override
  144. public Enumeration getLocales() {
  145. return req.getLocales();
  146. }
  147. @Override
  148. public boolean isSecure() {
  149. return req.isSecure();
  150. }
  151. @Override
  152. public RequestDispatcher getRequestDispatcher(String path) {
  153. return req.getRequestDispatcher(path);
  154. }
  155. @Override
  156. @Deprecated
  157. public String getRealPath(String path) {
  158. return req.getRealPath(path);
  159. }
  160. @Override
  161. public int getRemotePort() {
  162. return req.getRemotePort();
  163. }
  164. @Override
  165. public String getLocalName() {
  166. return req.getLocalName();
  167. }
  168. @Override
  169. public String getLocalAddr() {
  170. return req.getLocalAddr();
  171. }
  172. @Override
  173. public int getLocalPort() {
  174. return req.getLocalPort();
  175. }
  176. @Override
  177. public String getAuthType() {
  178. return req.getAuthType();
  179. }
  180. @Override
  181. public Cookie[] getCookies() {
  182. return req.getCookies();
  183. }
  184. @Override
  185. public long getDateHeader(String name) {
  186. return req.getDateHeader(name);
  187. }
  188. @Override
  189. public String getHeader(String name) {
  190. return req.getHeader(name);
  191. }
  192. @Override
  193. public Enumeration getHeaders(String name) {
  194. return req.getHeaders(name);
  195. }
  196. @Override
  197. public Enumeration getHeaderNames() {
  198. return req.getHeaderNames();
  199. }
  200. @Override
  201. public int getIntHeader(String name) {
  202. return req.getIntHeader(name);
  203. }
  204. @Override
  205. public String getMethod() {
  206. return req.getMethod();
  207. }
  208. @Override
  209. public String getPathInfo() {
  210. return req.getPathInfo();
  211. }
  212. @Override
  213. public String getPathTranslated() {
  214. return req.getPathTranslated();
  215. }
  216. @Override
  217. public String getContextPath() {
  218. return req.getContextPath();
  219. }
  220. @Override
  221. public String getQueryString() {
  222. return req.getQueryString();
  223. }
  224. @Override
  225. public String getRemoteUser() {
  226. return req.getRemoteUser();
  227. }
  228. @Override
  229. public boolean isUserInRole(String role) {
  230. return req.isUserInRole(role);
  231. }
  232. @Override
  233. public Principal getUserPrincipal() {
  234. return req.getUserPrincipal();
  235. }
  236. @Override
  237. public String getRequestedSessionId() {
  238. return req.getRequestedSessionId();
  239. }
  240. @Override
  241. public String getRequestURI() {
  242. return req.getRequestURI();
  243. }
  244. @Override
  245. public StringBuffer getRequestURL() {
  246. return req.getRequestURL();
  247. }
  248. @Override
  249. public String getServletPath() {
  250. return req.getServletPath();
  251. }
  252. @Override
  253. public HttpSession getSession(boolean create) {
  254. return req.getSession(create);
  255. }
  256. @Override
  257. public HttpSession getSession() {
  258. return req.getSession();
  259. }
  260. @Override
  261. public boolean isRequestedSessionIdValid() {
  262. return req.isRequestedSessionIdValid();
  263. }
  264. @Override
  265. public boolean isRequestedSessionIdFromCookie() {
  266. return req.isRequestedSessionIdFromCookie();
  267. }
  268. @Override
  269. public boolean isRequestedSessionIdFromURL() {
  270. return req.isRequestedSessionIdFromURL();
  271. }
  272. @Override
  273. @Deprecated
  274. public boolean isRequestedSessionIdFromUrl() {
  275. return req.isRequestedSessionIdFromUrl();
  276. }
  277. /*
  278. * Servlet 3.0 Methods
  279. */
  280. @Override
  281. public boolean authenticate(HttpServletResponse response) throws IOException, ServletException {
  282. return false;
  283. }
  284. @Override
  285. public void login(String username, String password) throws ServletException {
  286. }
  287. @Override
  288. public void logout() throws ServletException {
  289. }
  290. @Override
  291. public Part getPart(String arg0) throws IOException, ServletException {
  292. return req.getPart(arg0);
  293. }
  294. @Override
  295. public Collection<Part> getParts() throws IOException, ServletException {
  296. return req.getParts();
  297. }
  298. @Override
  299. public AsyncContext getAsyncContext() {
  300. return req.getAsyncContext();
  301. }
  302. @Override
  303. public DispatcherType getDispatcherType() {
  304. return req.getDispatcherType();
  305. }
  306. @Override
  307. public ServletContext getServletContext() {
  308. return req.getServletContext();
  309. }
  310. @Override
  311. public boolean isAsyncStarted() {
  312. return req.isAsyncStarted();
  313. }
  314. @Override
  315. public boolean isAsyncSupported() {
  316. return req.isAsyncStarted();
  317. }
  318. @Override
  319. public AsyncContext startAsync() throws IllegalStateException {
  320. return req.startAsync();
  321. }
  322. @Override
  323. public AsyncContext startAsync(ServletRequest arg0, ServletResponse arg1)
  324. throws IllegalStateException {
  325. return req.startAsync(arg0, arg1);
  326. }
  327. }