001 /* 002 * Copyright 2007 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.codehaus.groovy.grails.plugins.springsecurity; 017 018 import javax.servlet.http.HttpServletRequest; 019 020 /** 021 * Uses a <code>ThreadLocal</code> to store the current request. 022 * 023 * @author <a href='mailto:beckwithb@studentsonly.com'>Burt Beckwith</a> 024 */ 025 public final class SecurityRequestHolder { 026 027 private static final ThreadLocal<HttpServletRequest> HOLDER = new ThreadLocal<HttpServletRequest>(); 028 029 private SecurityRequestHolder() { 030 // static only 031 } 032 033 /** 034 * Clear the saved request. 035 */ 036 public static void reset() { 037 HOLDER.set(null); 038 } 039 040 /** 041 * Set the current request. 042 * @param request the request 043 */ 044 public static void setRequest(final HttpServletRequest request) { 045 HOLDER.set(request); 046 } 047 048 /** 049 * Get the current request. 050 * @return the request 051 */ 052 public static HttpServletRequest getRequest() { 053 return HOLDER.get(); 054 } 055 }