|
|
|
|
@ -3,18 +3,19 @@ package net.mingsoft.config; |
|
|
|
|
import java.util.LinkedHashMap; |
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
import org.apache.shiro.mgt.SecurityManager; |
|
|
|
|
import org.apache.shiro.spring.web.ShiroFilterFactoryBean; |
|
|
|
|
import org.apache.shiro.web.mgt.DefaultWebSecurityManager; |
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
|
import org.springframework.context.annotation.PropertySource; |
|
|
|
|
|
|
|
|
|
import net.mingsoft.basic.security.BaseAuthRealm; |
|
|
|
|
|
|
|
|
|
import org.apache.shiro.mgt.SecurityManager; |
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
|
public class ShiroConfiguration { |
|
|
|
|
public class ShiroConfig { |
|
|
|
|
|
|
|
|
|
@Value("${ms.manager.path}") |
|
|
|
|
private String managerPath; |
|
|
|
|
|
|
|
|
|
@ -24,9 +25,9 @@ public class ShiroConfiguration { |
|
|
|
|
// 必须设置 SecurityManager
|
|
|
|
|
shiroFilterFactoryBean.setSecurityManager(securityManager); |
|
|
|
|
// setLoginUrl 如果不设置值,默认会自动寻找Web工程根目录下的"/login.jsp"页面 或 "/login" 映射
|
|
|
|
|
shiroFilterFactoryBean.setLoginUrl(managerPath+"/login.do"); |
|
|
|
|
shiroFilterFactoryBean.setLoginUrl(managerPath + "/login.do"); |
|
|
|
|
// 设置无权限时跳转的 url;
|
|
|
|
|
shiroFilterFactoryBean.setUnauthorizedUrl(managerPath+"/404.do"); |
|
|
|
|
shiroFilterFactoryBean.setUnauthorizedUrl(managerPath + "/404.do"); |
|
|
|
|
|
|
|
|
|
// 设置拦截器
|
|
|
|
|
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<>(); |
|
|
|
|
@ -34,11 +35,11 @@ public class ShiroConfiguration { |
|
|
|
|
filterChainDefinitionMap.put("/static/**", "anon"); |
|
|
|
|
filterChainDefinitionMap.put("/html/**", "anon"); |
|
|
|
|
// 开放登陆接口
|
|
|
|
|
filterChainDefinitionMap.put(managerPath+"/login.do", "anon"); |
|
|
|
|
filterChainDefinitionMap.put(managerPath+"/checkLogin.do", "anon"); |
|
|
|
|
filterChainDefinitionMap.put(managerPath + "/login.do", "anon"); |
|
|
|
|
filterChainDefinitionMap.put(managerPath + "/checkLogin.do", "anon"); |
|
|
|
|
// 其余接口一律拦截
|
|
|
|
|
// 主要这行代码必须放在所有权限设置的最后,不然会导致所有 url 都被拦截
|
|
|
|
|
filterChainDefinitionMap.put(managerPath+"/**", "authc"); |
|
|
|
|
filterChainDefinitionMap.put(managerPath + "/**", "authc"); |
|
|
|
|
|
|
|
|
|
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); |
|
|
|
|
return shiroFilterFactoryBean; |