1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity.intercept.web;
17
18 import javax.servlet.FilterChain;
19 import javax.servlet.ServletRequest;
20 import javax.servlet.ServletResponse;
21 import javax.servlet.http.HttpServletRequest;
22 import javax.servlet.http.HttpServletResponse;
23
24
25 /***
26 * Holds objects associated with a HTTP filter.
27 *
28 * <P>
29 * Guarantees the request and response are instances of
30 * <code>HttpServletRequest</code> and <code>HttpServletResponse</code>, and
31 * that there are no <code>null</code> objects.
32 * </p>
33 *
34 * <P>
35 * Required so that security system classes can obtain access to the filter
36 * environment, as well as the request and response.
37 * </p>
38 *
39 * @author Ben Alex
40 * @author colin sampaleanu
41 * @version $Id: FilterInvocation.java,v 1.6 2005/11/17 00:55:50 benalex Exp $
42 */
43 public class FilterInvocation {
44
45
46 private FilterChain chain;
47 private ServletRequest request;
48 private ServletResponse response;
49
50
51
52 public FilterInvocation(ServletRequest request, ServletResponse response,
53 FilterChain chain) {
54 if ((request == null) || (response == null) || (chain == null)) {
55 throw new IllegalArgumentException(
56 "Cannot pass null values to constructor");
57 }
58
59 if (!(request instanceof HttpServletRequest)) {
60 throw new IllegalArgumentException(
61 "Can only process HttpServletRequest");
62 }
63
64 if (!(response instanceof HttpServletResponse)) {
65 throw new IllegalArgumentException(
66 "Can only process HttpServletResponse");
67 }
68
69 this.request = request;
70 this.response = response;
71 this.chain = chain;
72 }
73
74 protected FilterInvocation() {
75 throw new IllegalArgumentException("Cannot use default constructor");
76 }
77
78
79
80 public FilterChain getChain() {
81 return chain;
82 }
83
84 /***
85 * Indicates the URL that the user agent used for this request.
86 *
87 * <P>
88 * The returned URL does <b>not</b> reflect the port number determined from
89 * a {@link org.acegisecurity.util.PortResolver}.
90 * </p>
91 *
92 * @return the full URL of this request
93 */
94 public String getFullRequestUrl() {
95 return getHttpRequest().getScheme() + "://"
96 + getHttpRequest().getServerName() + ":"
97 + getHttpRequest().getServerPort() + getHttpRequest().getContextPath()
98 + getRequestUrl();
99 }
100
101 public HttpServletRequest getHttpRequest() {
102 return (HttpServletRequest) request;
103 }
104
105 public HttpServletResponse getHttpResponse() {
106 return (HttpServletResponse) response;
107 }
108
109 public ServletRequest getRequest() {
110 return request;
111 }
112
113 public String getRequestUrl() {
114 String pathInfo = getHttpRequest().getPathInfo();
115 String queryString = getHttpRequest().getQueryString();
116
117 String uri = getHttpRequest().getServletPath();
118
119 if (uri == null) {
120 uri = getHttpRequest().getRequestURI();
121 uri = uri.substring(getHttpRequest().getContextPath().length());
122 }
123
124 return uri + ((pathInfo == null) ? "" : pathInfo)
125 + ((queryString == null) ? "" : ("?" + queryString));
126 }
127
128 public ServletResponse getResponse() {
129 return response;
130 }
131
132 public String toString() {
133 return "FilterInvocation: URL: " + getRequestUrl();
134 }
135 }