View Javadoc
1   /*
2    * Copyright 2008 Les Hazlewood
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.shiro.web.session.mgt;
17  
18  import org.apache.shiro.session.mgt.DefaultSessionKey;
19  import org.apache.shiro.web.util.RequestPairSource;
20  
21  import javax.servlet.ServletRequest;
22  import javax.servlet.ServletResponse;
23  import java.io.Serializable;
24  
25  /**
26   * A {@link org.apache.shiro.session.mgt.SessionKey SessionKey} implementation that also retains the
27   * {@code ServletRequest} and {@code ServletResponse} associated with the web request that is performing the
28   * session lookup.
29   *
30   * @since 1.0
31   */
32  public class WebSessionKey extends DefaultSessionKey implements RequestPairSource {
33  
34      private final ServletRequest servletRequest;
35      private final ServletResponse servletResponse;
36  
37      public WebSessionKey(ServletRequest request, ServletResponse response) {
38          if (request == null) {
39              throw new NullPointerException("request argument cannot be null.");
40          }
41          if (response == null) {
42              throw new NullPointerException("response argument cannot be null.");
43          }
44          this.servletRequest = request;
45          this.servletResponse = response;
46      }
47  
48      public WebSessionKey(Serializable sessionId, ServletRequest request, ServletResponse response) {
49          this(request, response);
50          setSessionId(sessionId);
51      }
52  
53      public ServletRequest getServletRequest() {
54          return servletRequest;
55      }
56  
57      public ServletResponse getServletResponse() {
58          return servletResponse;
59      }
60  }