1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.shiro.web.env; |
20 | |
|
21 | |
import org.apache.shiro.env.DefaultEnvironment; |
22 | |
import org.apache.shiro.mgt.SecurityManager; |
23 | |
import org.apache.shiro.web.filter.mgt.FilterChainResolver; |
24 | |
import org.apache.shiro.web.mgt.WebSecurityManager; |
25 | |
|
26 | |
import javax.servlet.ServletContext; |
27 | |
import java.util.Map; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
public class DefaultWebEnvironment extends DefaultEnvironment implements MutableWebEnvironment { |
35 | |
|
36 | |
private static final String DEFAULT_FILTER_CHAIN_RESOLVER_NAME = "filterChainResolver"; |
37 | |
|
38 | |
private ServletContext servletContext; |
39 | |
|
40 | |
public DefaultWebEnvironment() { |
41 | 1 | super(); |
42 | 1 | } |
43 | |
|
44 | |
public FilterChainResolver getFilterChainResolver() { |
45 | 0 | return getObject(DEFAULT_FILTER_CHAIN_RESOLVER_NAME, FilterChainResolver.class); |
46 | |
} |
47 | |
|
48 | |
public void setFilterChainResolver(FilterChainResolver filterChainResolver) { |
49 | 0 | setObject(DEFAULT_FILTER_CHAIN_RESOLVER_NAME, filterChainResolver); |
50 | 0 | } |
51 | |
|
52 | |
@Override |
53 | |
public SecurityManager getSecurityManager() throws IllegalStateException { |
54 | 0 | return getWebSecurityManager(); |
55 | |
} |
56 | |
|
57 | |
@Override |
58 | |
public void setSecurityManager(SecurityManager securityManager) { |
59 | 0 | assertWebSecurityManager(securityManager); |
60 | 0 | super.setSecurityManager(securityManager); |
61 | 0 | } |
62 | |
|
63 | |
public WebSecurityManager getWebSecurityManager() { |
64 | 0 | SecurityManager sm = super.getSecurityManager(); |
65 | 0 | assertWebSecurityManager(sm); |
66 | 0 | return (WebSecurityManager)sm; |
67 | |
} |
68 | |
|
69 | |
public void setWebSecurityManager(WebSecurityManager wsm) { |
70 | 1 | super.setSecurityManager(wsm); |
71 | 1 | } |
72 | |
|
73 | |
private void assertWebSecurityManager(SecurityManager sm) { |
74 | 0 | if (!(sm instanceof WebSecurityManager)) { |
75 | 0 | String msg = "SecurityManager instance must be a " + WebSecurityManager.class.getName() + " instance."; |
76 | 0 | throw new IllegalStateException(msg); |
77 | |
} |
78 | 0 | } |
79 | |
|
80 | |
public ServletContext getServletContext() { |
81 | 0 | return this.servletContext; |
82 | |
} |
83 | |
|
84 | |
public void setServletContext(ServletContext servletContext) { |
85 | 0 | this.servletContext = servletContext; |
86 | 0 | } |
87 | |
} |