[58] | 1 | /* Copyright 2006-2009 the original author or authors. |
---|
| 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 | package org.codehaus.groovy.grails.plugins.springsecurity; |
---|
| 16 | |
---|
| 17 | import javax.servlet.http.HttpServletRequest; |
---|
| 18 | import javax.servlet.http.HttpServletResponse; |
---|
| 19 | |
---|
| 20 | /** |
---|
| 21 | * Uses a {@link ThreadLocal} to store the current request and response. |
---|
| 22 | * |
---|
| 23 | * @author <a href='mailto:beckwithb@studentsonly.com'>Burt Beckwith</a> |
---|
| 24 | */ |
---|
| 25 | public final class SecurityRequestHolder { |
---|
| 26 | |
---|
| 27 | private static final ThreadLocal<HttpServletRequest> REQUEST_HOLDER = new ThreadLocal<HttpServletRequest>(); |
---|
| 28 | private static final ThreadLocal<HttpServletResponse> RESPONSE_HOLDER = new ThreadLocal<HttpServletResponse>(); |
---|
| 29 | |
---|
| 30 | private SecurityRequestHolder() { |
---|
| 31 | // static only |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | /** |
---|
| 35 | * Clear the saved request. |
---|
| 36 | */ |
---|
| 37 | public static void reset() { |
---|
| 38 | REQUEST_HOLDER.set(null); |
---|
| 39 | RESPONSE_HOLDER.set(null); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | /** |
---|
| 43 | * Set the current request and response. |
---|
| 44 | * @param request the request |
---|
| 45 | * @param response the response |
---|
| 46 | */ |
---|
| 47 | public static void set(final HttpServletRequest request, final HttpServletResponse response) { |
---|
| 48 | REQUEST_HOLDER.set(request); |
---|
| 49 | RESPONSE_HOLDER.set(response); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | /** |
---|
| 53 | * Get the current request. |
---|
| 54 | * @return the request |
---|
| 55 | */ |
---|
| 56 | public static HttpServletRequest getRequest() { |
---|
| 57 | return REQUEST_HOLDER.get(); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | /** |
---|
| 61 | * Get the current response. |
---|
| 62 | * @return the response |
---|
| 63 | */ |
---|
| 64 | public static HttpServletResponse getResponse() { |
---|
| 65 | return RESPONSE_HOLDER.get(); |
---|
| 66 | } |
---|
| 67 | } |
---|