package com.fdkankan.web.config; import com.fdkankan.common.constant.LoginType; import com.fdkankan.web.realm.AppJwtRealm; import com.fdkankan.web.realm.ManagerJwtRealm; import com.fdkankan.web.realm.UserJwtRealm; import com.fdkankan.web.constant.FilterConstant; import com.fdkankan.web.jwt.JwtFilter; import com.fdkankan.web.realm.AgentJwtRealm; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import javax.servlet.Filter; import org.apache.shiro.authc.pam.AtLeastOneSuccessfulStrategy; import org.apache.shiro.authc.pam.ModularRealmAuthenticator; import org.apache.shiro.mgt.DefaultSessionStorageEvaluator; import org.apache.shiro.mgt.DefaultSubjectDAO; import org.apache.shiro.mgt.SecurityManager; import org.apache.shiro.realm.Realm; import org.apache.shiro.spring.web.ShiroFilterFactoryBean; import org.apache.shiro.web.mgt.DefaultWebSecurityManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class ShiroConfig { @Autowired ModularRealmAuthenticator modularRealmAuthenticator; @Autowired private UserJwtRealm userJwtRealm; @Autowired private AgentJwtRealm agentJwtRealm; @Autowired private ManagerJwtRealm managerJwtRealm; @Autowired private AppJwtRealm appJwtRealm; @Bean("shiroFilter") public ShiroFilterFactoryBean shiroFilter(SecurityManager securityManager) { ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean(); shiroFilterFactoryBean.setSecurityManager(securityManager); //拦截器 Map filterChainDefinitionMap = new LinkedHashMap(); // 配置不会被拦截的链接 顺序判断 // filterChainDefinitionMap.put("/**", "anon"); // 添加自己的过滤器并且取名为jwt Map filterMap = new HashMap(1); filterMap.put("user_jwt", new JwtFilter(LoginType.USER.code())); filterMap.put("manager_jwt", new JwtFilter(LoginType.MANAGER.code())); filterMap.put("agent_jwt", new JwtFilter(LoginType.AGENT.code())); filterMap.put("app_jwt", new JwtFilter(LoginType.APP.code())); shiroFilterFactoryBean.setFilters(filterMap); //