**
Spring Boot 整合Shiro 安全框架
**
关于Spring Boot整合Shiro安全框架的步骤,以后项目中用到 可以按照 步骤配置应用起来
1.pom文件添加依赖
1.pom文件添加依赖
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>1.5.3</version>
</dependency>
2.新建一个包 config 创建两个配置类
package com.hengyang.config;
import at.pollux.thymeleaf.shiro.dialect.ShiroDialect;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.LinkedHashMap;
import java.util.Map;
@Configuration
public class ShiroConfig {
@Bean
public ShiroFilterFactoryBean getShiroFilterFactoryBean(@Qualifier("securityManager") DefaultWebSecurityManager defaultWebSecurityManager){
ShiroFilterFactoryBean bean = new ShiroFilterFactoryBean();
//设置安全管理器
bean.setSecurityManager(defaultWebSecurityManager);
//设置shiro的内置过滤器
/**
* anno:无需认证所有人都可以访问
* authc: 必须认证了才能访问
* user: 必须拥有记住我才能访问
* perms: 拥有某个资源的权限才能访问
* role: 拥有某个角色权限才能访问
*/
// filterMap.put("/user/add","authc");
// filterMap.put("/user/update","authc");
//拦截
Map<String, String> filterMap = new LinkedHashMap<>();
//授权
filterMap.put("/user/add","perms[user:add]");
filterMap.put("/user/update","perms[user:update]");
filterMap.put("/user/*","authc");
bean.setFilterChainDefinitionMap(filterMap);
//设置登录的请求
bean.setLoginUrl("/toLogin");