View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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   * @since 1.4.0
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  }