1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.shiro.spring.web.config;
20
21 import org.apache.shiro.mgt.SecurityManager;
22 import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
23 import org.apache.shiro.web.filter.mgt.DefaultFilter;
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.beans.factory.annotation.Value;
26
27 import javax.servlet.Filter;
28 import java.util.Collections;
29 import java.util.List;
30 import java.util.Map;
31
32
33
34
35 public class AbstractShiroWebFilterConfiguration {
36
37 @Autowired
38 protected SecurityManager securityManager;
39
40 @Autowired
41 protected ShiroFilterChainDefinition shiroFilterChainDefinition;
42
43 @Autowired(required = false)
44 protected Map<String, Filter> filterMap;
45
46 @Value("#{ @environment['shiro.loginUrl'] ?: '/login.jsp' }")
47 protected String loginUrl;
48
49 @Value("#{ @environment['shiro.successUrl'] ?: '/' }")
50 protected String successUrl;
51
52 @Value("#{ @environment['shiro.unauthorizedUrl'] ?: null }")
53 protected String unauthorizedUrl;
54
55 protected List<String> globalFilters() {
56 return Collections.singletonList(DefaultFilter.invalidRequest.name());
57 }
58
59 protected ShiroFilterFactoryBean shiroFilterFactoryBean() {
60 ShiroFilterFactoryBeann.html#ShiroFilterFactoryBean">ShiroFilterFactoryBean filterFactoryBean = new ShiroFilterFactoryBean();
61
62 filterFactoryBean.setLoginUrl(loginUrl);
63 filterFactoryBean.setSuccessUrl(successUrl);
64 filterFactoryBean.setUnauthorizedUrl(unauthorizedUrl);
65
66 filterFactoryBean.setSecurityManager(securityManager);
67 filterFactoryBean.setGlobalFilters(globalFilters());
68 filterFactoryBean.setFilterChainDefinitionMap(shiroFilterChainDefinition.getFilterChainMap());
69 filterFactoryBean.setFilters(filterMap);
70
71 return filterFactoryBean;
72 }
73 }