1 /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 package org.acegisecurity.intercept.web;
17
18 import org.acegisecurity.util.UrlUtils;
19
20 import javax.servlet.FilterChain;
21 import javax.servlet.ServletRequest;
22 import javax.servlet.ServletResponse;
23 import javax.servlet.http.HttpServletRequest;
24 import javax.servlet.http.HttpServletResponse;
25
26
27 /**
28 * Holds objects associated with a HTTP filter.<P>Guarantees the request and response are instances of
29 * <code>HttpServletRequest</code> and <code>HttpServletResponse</code>, and that there are no <code>null</code>
30 * objects.</p>
31 * <P>Required so that security system classes can obtain access to the filter environment, as well as the request
32 * and response.</p>
33 *
34 * @author Ben Alex
35 * @author colin sampaleanu
36 * @version $Id: FilterInvocation.java 1496 2006-05-23 13:38:33Z benalex $
37 */
38 public class FilterInvocation {
39 //~ Instance fields ================================================================================================
40
41 private FilterChain chain;
42 private ServletRequest request;
43 private ServletResponse response;
44
45 //~ Constructors ===================================================================================================
46
47 public FilterInvocation(ServletRequest request, ServletResponse response, FilterChain chain) {
48 if ((request == null) || (response == null) || (chain == null)) {
49 throw new IllegalArgumentException("Cannot pass null values to constructor");
50 }
51
52 if (!(request instanceof HttpServletRequest)) {
53 throw new IllegalArgumentException("Can only process HttpServletRequest");
54 }
55
56 if (!(response instanceof HttpServletResponse)) {
57 throw new IllegalArgumentException("Can only process HttpServletResponse");
58 }
59
60 this.request = request;
61 this.response = response;
62 this.chain = chain;
63 }
64
65 //~ Methods ========================================================================================================
66
67 public FilterChain getChain() {
68 return chain;
69 }
70
71 /**
72 * Indicates the URL that the user agent used for this request.<P>The returned URL does <b>not</b> reflect
73 * the port number determined from a {@link org.acegisecurity.util.PortResolver}.</p>
74 *
75 * @return the full URL of this request
76 */
77 public String getFullRequestUrl() {
78 return UrlUtils.getFullRequestUrl(this);
79 }
80
81 public HttpServletRequest getHttpRequest() {
82 return (HttpServletRequest) request;
83 }
84
85 public HttpServletResponse getHttpResponse() {
86 return (HttpServletResponse) response;
87 }
88
89 public ServletRequest getRequest() {
90 return request;
91 }
92
93 /**
94 * Obtains the web application-specific fragment of the URL.
95 *
96 * @return the URL, excluding any server name, context path or servlet path
97 */
98 public String getRequestUrl() {
99 return UrlUtils.getRequestUrl(this);
100 }
101
102 public ServletResponse getResponse() {
103 return response;
104 }
105
106 public String toString() {
107 return "FilterInvocation: URL: " + getRequestUrl();
108 }
109 }