001/*002 * Copyright 2002-2017 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 at007 *008 * https://www.apache.org/licenses/LICENSE-2.0009 *010 * Unless required by applicable law or agreed to in writing, software011 * 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 and014 * limitations under the License.015 */016017package org.springframework.web.context.support;018019import java.util.HashSet;020import java.util.Set;021022import javax.servlet.http.HttpServletRequest;023import javax.servlet.http.HttpServletRequestWrapper;024025import org.springframework.lang.Nullable;026import org.springframework.util.Assert;027import org.springframework.web.context.WebApplicationContext;028029/**030 * HttpServletRequest decorator that makes all Spring beans in a031 * given WebApplicationContext accessible as request attributes,032 * through lazy checking once an attribute gets accessed.033 *034 * @author Juergen Hoeller035 * @since 2.5036 */037public class ContextExposingHttpServletRequest extends HttpServletRequestWrapper {038039 private final WebApplicationContext webApplicationContext;040041 @Nullable042 private final Set<String> exposedContextBeanNames;043044 @Nullable045 private Set<String> explicitAttributes;046047048 /**049 * Create a new ContextExposingHttpServletRequest for the given request.050 * @param originalRequest the original HttpServletRequest051 * @param context the WebApplicationContext that this request runs in052 */053 public ContextExposingHttpServletRequest(HttpServletRequest originalRequest, WebApplicationContext context) {054 this(originalRequest, context, null);055 }056057 /**058 * Create a new ContextExposingHttpServletRequest for the given request.059 * @param originalRequest the original HttpServletRequest060 * @param context the WebApplicationContext that this request runs in061 * @param exposedContextBeanNames the names of beans in the context which062 * are supposed to be exposed (if this is non-null, only the beans in this063 * Set are eligible for exposure as attributes)064 */065 public ContextExposingHttpServletRequest(HttpServletRequest originalRequest, WebApplicationContext context,066 @Nullable Set<String> exposedContextBeanNames) {067068 super(originalRequest);069 Assert.notNull(context, "WebApplicationContext must not be null");070 this.webApplicationContext = context;071 this.exposedContextBeanNames = exposedContextBeanNames;072 }073074075 /**