001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements.  See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership.  The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance
008     * with the License.  You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing,
013     * software distributed under the License is distributed on an
014     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     * KIND, either express or implied.  See the License for the
016     * specific language governing permissions and limitations
017     * under the License.
018     */
019    package org.apache.shiro.web.session.mgt;
020    
021    import org.apache.shiro.session.mgt.DefaultSessionContext;
022    
023    import javax.servlet.ServletRequest;
024    import javax.servlet.ServletResponse;
025    import java.util.Map;
026    
027    /**
028     * Default implementation of the {@link WebSessionContext} interface which provides getters and setters that
029     * wrap interaction with the underlying backing context map.
030     *
031     * @since 1.0
032     */
033    public class DefaultWebSessionContext extends DefaultSessionContext implements WebSessionContext {
034    
035        private static final long serialVersionUID = -3974604687792523072L;
036    
037        private static final String SERVLET_REQUEST = DefaultWebSessionContext.class.getName() + ".SERVLET_REQUEST";
038        private static final String SERVLET_RESPONSE = DefaultWebSessionContext.class.getName() + ".SERVLET_RESPONSE";
039    
040        public DefaultWebSessionContext() {
041            super();
042        }
043    
044        public DefaultWebSessionContext(Map<String, Object> map) {
045            super(map);
046        }
047    
048        public void setServletRequest(ServletRequest request) {
049            if (request != null) {
050                put(SERVLET_REQUEST, request);
051            }
052        }
053    
054        public ServletRequest getServletRequest() {
055            return getTypedValue(SERVLET_REQUEST, ServletRequest.class);
056        }
057    
058        public void setServletResponse(ServletResponse response) {
059            if (response != null) {
060                put(SERVLET_RESPONSE, response);
061            }
062        }
063    
064        public ServletResponse getServletResponse() {
065            return getTypedValue(SERVLET_RESPONSE, ServletResponse.class);
066        }
067    }