Springboot + shiro 整合之Url拦截设置
2017-06-15 10:45
591 查看
shiro 整合到springboot 还是比较简单的,只需要新建一个spring-shiro.xml的配置文件:
自定义的身份验证就不多说了,主要还是关注本文重点,解释一下filterChainDefinitions:
1、springboot 默认访问路径 resources 下的 static(好像最高级别),它就这么定的爱咋咋地。。,所以静态资源文件(js,css,jpg等)的访问配置要去掉 /static (/static/js/**=anon)
2、/** 必须要放在最下面 ,注意是必须
我个人觉得springboot 的WebMvcConfigurerAdapter bean注解方式不如以前xml方便,只需要导入一下这个xml 文件,并将这个文件放到classpath 下就OK了。
@Configuration //标注此文件为一个配置项,spring boot才会扫描到该配置。
@ImportResource(locations={"classpath:spring-shiro.xml"})
public class BootConfiguration extends WebMvcConfigurerAdapter {
}
上面这个类可以随便放src下的任意目录,springboot 它会找到的。
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd" default-lazy-init="true"> <description>Shiro Configuration</description> <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager"> <property name="realm" ref="ShiroRealm" /> </bean> <!-- 項目自定义的Realm --> <bean id="ShiroRealm" class="org.spring.springboot.interceptor.shiro.ShiroRealm" ></bean> <!-- Shiro Filter --> <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean"> <property name="securityManager" ref="securityManager" /> <property name="loginUrl" value="/login" /> <property name="successUrl" value="/backstage/index" /> <property name="unauthorizedUrl" value="/login" /> <!-- anon:匿名拦截器,即不需要登录即可访问;一般用于静态资源过滤 authc:如果没有登录会跳到相应的登录页面登录 user:用户拦截器,用户已经身份验证/记住我登录的都可 --> <property name="filterChainDefinitions"> <value> /plugins/** = anon /images/** = anon /css/** = anon /** = authc </value> </property> </bean> <!-- 缓存管理器 使用Ehcache实现--> <bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager"> <property name="cacheManagerConfigFile" value="classpath:ehcache.xml"/> </bean> <!-- AOP式方法级权限检查 --> <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor"> <property name="proxyTargetClass" value="true" /> </bean> <!-- 保证实现了Shiro内部lifecycle函数的bean执行 --> <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" /></beans>
自定义的身份验证就不多说了,主要还是关注本文重点,解释一下filterChainDefinitions:
1、springboot 默认访问路径 resources 下的 static(好像最高级别),它就这么定的爱咋咋地。。,所以静态资源文件(js,css,jpg等)的访问配置要去掉 /static (/static/js/**=anon)
2、/** 必须要放在最下面 ,注意是必须
我个人觉得springboot 的WebMvcConfigurerAdapter bean注解方式不如以前xml方便,只需要导入一下这个xml 文件,并将这个文件放到classpath 下就OK了。
@Configuration //标注此文件为一个配置项,spring boot才会扫描到该配置。
@ImportResource(locations={"classpath:spring-shiro.xml"})
public class BootConfiguration extends WebMvcConfigurerAdapter {
}
上面这个类可以随便放src下的任意目录,springboot 它会找到的。
相关文章推荐
- Springboot + shiro 整合之Url拦截设置(转)
- Spring Boot整合shiro出现UnavailableSecurityManagerException
- SpringBoot+shiro整合学习之登录认证和权限控制
- springboot(十四):springboot整合shiro-登录认证和权限管理
- SpringBoot Web项目的参数绑定:URL传参及默认参数设置
- SpringBoot整合mybatis、shiro、redis实现基于数据库的细粒度动态权限管理系统实例
- SpringBoot+shiro整合学习之登录认证和权限控制
- spring 整合shiro ,并实现动态url 配置
- Angular2 和springboot 整合后 url 解析出现的问题解决方案
- springboot整合shiro
- spring boot整合redis,实现shiro的CacheManager
- springboot shiro 整合
- SpringBoot学习:整合shiro(身份认证和权限认证),使用EhCache缓存
- IDEA上搭建maven项目整合springboot+mybatis+shiro
- Spring Boot Shiro权限管理--自定义 FormAuthenticationFilter验证码整合
- springboot shiro 整合
- SpringBoot学习:整合shiro(验证码功能和登录次数限制功能)
- spring boot整合shiro引用配置文件配置是出现的问题
- spring boot整合shiro
- SpringBoot 整和 shiro 把拦截路径提出到配置文件中