001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.shiro.spring.web.config; 020 021import org.apache.shiro.mgt.SecurityManager; 022import org.apache.shiro.spring.web.ShiroFilterFactoryBean; 023import org.apache.shiro.web.filter.mgt.DefaultFilter; 024import org.springframework.beans.factory.annotation.Autowired; 025import org.springframework.beans.factory.annotation.Value; 026 027import javax.servlet.Filter; 028import java.util.Collections; 029import java.util.List; 030import java.util.Map; 031 032/** 033 * @since 1.4.0 034 */ 035public class AbstractShiroWebFilterConfiguration { 036 037 @Autowired 038 protected SecurityManager securityManager; 039 040 @Autowired 041 protected ShiroFilterChainDefinition shiroFilterChainDefinition; 042 043 @Autowired(required = false) 044 protected Map<String, Filter> filterMap; 045 046 @Value("#{ @environment['shiro.loginUrl'] ?: '/login.jsp' }") 047 protected String loginUrl; 048 049 @Value("#{ @environment['shiro.successUrl'] ?: '/' }") 050 protected String successUrl; 051 052 @Value("#{ @environment['shiro.unauthorizedUrl'] ?: null }") 053 protected String unauthorizedUrl; 054 055 protected List<String> globalFilters() { 056 return Collections.singletonList(DefaultFilter.invalidRequest.name()); 057 } 058 059 protected ShiroFilterFactoryBean shiroFilterFactoryBean() { 060 ShiroFilterFactoryBean filterFactoryBean = new ShiroFilterFactoryBean(); 061 062 filterFactoryBean.setLoginUrl(loginUrl); 063 filterFactoryBean.setSuccessUrl(successUrl); 064 filterFactoryBean.setUnauthorizedUrl(unauthorizedUrl); 065 066 filterFactoryBean.setSecurityManager(securityManager); 067 filterFactoryBean.setGlobalFilters(globalFilters()); 068 filterFactoryBean.setFilterChainDefinitionMap(shiroFilterChainDefinition.getFilterChainMap()); 069 filterFactoryBean.setFilters(filterMap); 070 071 return filterFactoryBean; 072 } 073}