1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.shiro.web.subject.support;
20
21 import org.apache.shiro.mgt.SecurityManager;
22 import org.apache.shiro.session.Session;
23 import org.apache.shiro.session.mgt.SessionContext;
24 import org.apache.shiro.subject.PrincipalCollection;
25 import org.apache.shiro.subject.support.DelegatingSubject;
26 import org.apache.shiro.lang.util.StringUtils;
27 import org.apache.shiro.web.session.mgt.DefaultWebSessionContext;
28 import org.apache.shiro.web.session.mgt.WebSessionContext;
29 import org.apache.shiro.web.subject.WebSubject;
30 import org.apache.shiro.web.util.WebUtils;
31
32 import javax.servlet.ServletRequest;
33 import javax.servlet.ServletResponse;
34
35
36
37
38
39
40
41 public class WebDelegatingSubject extends DelegatingSubject implements WebSubject {
42
43 private static final long serialVersionUID = -1655724323350159250L;
44
45 private final ServletRequest servletRequest;
46 private final ServletResponse servletResponse;
47
48 public WebDelegatingSubject(PrincipalCollection principals, boolean authenticated,
49 String host, Session session,
50 ServletRequest request, ServletResponse response,
51 SecurityManager securityManager) {
52 this(principals, authenticated, host, session, true, request, response, securityManager);
53 }
54
55
56 public WebDelegatingSubject(PrincipalCollection principals, boolean authenticated,
57 String host, Session session, boolean sessionEnabled,
58 ServletRequest request, ServletResponse response,
59 SecurityManager securityManager) {
60 super(principals, authenticated, host, session, sessionEnabled, securityManager);
61 this.servletRequest = request;
62 this.servletResponse = response;
63 }
64
65 public ServletRequest getServletRequest() {
66 return servletRequest;
67 }
68
69 public ServletResponse getServletResponse() {
70 return servletResponse;
71 }
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86 @Override
87 protected boolean isSessionCreationEnabled() {
88 boolean enabled = super.isSessionCreationEnabled();
89 return enabled && WebUtils.isSessionCreationEnabled(this);
90 }
91
92 @Override
93 protected SessionContext createSessionContext() {
94 WebSessionContext wsc = new DefaultWebSessionContext();
95 String host = getHost();
96 if (StringUtils.hasText(host)) {
97 wsc.setHost(host);
98 }
99 wsc.setServletRequest(this.servletRequest);
100 wsc.setServletResponse(this.servletResponse);
101 return wsc;
102 }
103 }