step1  web.xml

<!-- Shiro filter start -->
<filter>
<filter-name>shiroFilter</filter-name>
<filter-class>
org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
<init-param>
<param-name>targetFilterLifecycle</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
   <!-- Shiro filter end -->

step2  spring-mvc.xml

设置访问的静态资源(资源目录根据自己的项目需要配置)

	<!-- 对静态资源文件的访问 restful -->
<mvc:resources mapping="/admin/**" location="/,/admin/" />
<mvc:resources mapping="/static/**" location="/,/static/" />
<mvc:resources mapping="/plugins/**" location="/,/plugins/" />
<mvc:resources mapping="/uploadFiles/**" location="/,/uploadFiles/" />
<mvc:resources mapping="/swagger/**" location="/,/swagger/" />
  <mvc:resources mapping="/swagger-ui.html" location="classpath:/META-INF/resources/"/>
  <mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>

  

shiro 自定义的realm

public class ShiroRealm extends AuthorizingRealm {

	/*
* 登录信息和用户验证信息验证(non-Javadoc)
* @see org.apache.shiro.realm.AuthenticatingRealm#doGetAuthenticationInfo(org.apache.shiro.authc.AuthenticationToken)
*/
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { String username = (String)token.getPrincipal(); //得到用户名
String password = new String((char[])token.getCredentials()); //得到密码 if(null != username && null != password){
return new SimpleAuthenticationInfo(username, password, getName());
}else{
return null;
} } /*
* 授权查询回调函数, 进行鉴权但缓存中无用户的授权信息时调用,负责在应用程序中决定用户的访问控制的方法(non-Javadoc)
* @see org.apache.shiro.realm.AuthorizingRealm#doGetAuthorizationInfo(org.apache.shiro.subject.PrincipalCollection)
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection pc) { System.out.println("========2"); return null;
} }

  

step3 applicationContext.xml 需要拦截的请求路径权限,anon 匿名权限 authc 需要认证权限  认证权限根据的是项目自定义的realm来实现

<!-- ================ Shiro start ================ -->
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="realm" ref="ShiroRealm" />
</bean> <!-- 項目自定义的Realm -->
<bean id="ShiroRealm" class="com.fh.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="/" /> <property name="successUrl" value="/main/index" /> <property name="unauthorizedUrl" value="/login_toLogin" /> <property name="filterChainDefinitions">
<value>
/static/login/** = anon
/static/js/myjs/** = authc
/static/js/** = anon
/code.do = anon
/login_login = anon
/app**/** = anon
/weixin/** = anon
/swagger/** = anon
/api/** = anon
/api-docs = anon
/swagger-ui.html = anon
/webjars/** = anon
/swagger-resources/** = anon
/v2/** = anon
/** = authc
</value>
</property>
</bean>
<!-- ================ Shiro end ================ -->

  

shiro 安全管理框架配置的更多相关文章

  1. Shiro权限管理框架(一):Shiro的基本使用

    首发地址:https://www.guitu18.com/post/2019/07/26/43.html 核心概念 Apache Shiro是一个强大且易用的Java安全框架,执行身份验证.授权.密码 ...

  2. Shiro权限管理框架(二):Shiro结合Redis实现分布式环境下的Session共享

    首发地址:https://www.guitu18.com/post/2019/07/28/44.html 本篇是Shiro系列第二篇,使用Shiro基于Redis实现分布式环境下的Session共享. ...

  3. Shiro权限管理框架(三):Shiro中权限过滤器的初始化流程和实现原理

    本篇是Shiro系列第三篇,Shiro中的过滤器初始化流程和实现原理.Shiro基于URL的权限控制是通过Filter实现的,本篇从我们注入的ShiroFilterFactoryBean开始入手,翻看 ...

  4. Shiro权限管理框架(四):深入分析Shiro中的Session管理

    其实关于Shiro的一些学习笔记很早就该写了,因为懒癌和拖延症晚期一直没有落实,直到今天公司的一个项目碰到了在集群环境的单点登录频繁掉线的问题,为了解决这个问题,Shiro相关的文档和教程没少翻.最后 ...

  5. Shiro权限管理框架(五):自定义Filter实现及其问题排查记录

    明确需求 在使用Shiro的时候,鉴权失败一般都是返回一个错误页或者登录页给前端,特别是后台系统,这种模式用的特别多.但是现在的项目越来越多的趋向于使用前后端分离的方式开发,这时候就需要响应Json数 ...

  6. Apache shiro集群实现 (二) shiro 的INI配置

    Apache shiro集群实现 (一) shiro入门介绍 Apache shiro集群实现 (二) shiro 的INI配置 Apache shiro集群实现 (三)shiro身份认证(Shiro ...

  7. shiro 权限管理配置

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  8. shiro+spring相关配置

    首先pom中添加所需jar包: <!-- shiro start --> <dependency> <groupId>org.apache.shiro</gr ...

  9. shiro 集成spring 配置 学习记录(一)

    首先当然是项目中需要增加shiro的架包依赖: <!-- shiro --> <dependency> <groupId>org.apache.shiro</ ...

随机推荐

  1. 解决因为链表过长,sql查询慢的问题

    /** * 解决因为链表过长,sql查询慢的问题 * 使用分治算法,先切分链表,然后查询结果,最后合并结果 *  * @author lingpy * @since 1.0 */public clas ...

  2. python学习之路---day07

    一:先看什么事赋值? 以例子举例说明:. a=[1,2,3,[11,22,33]] b=a print(b) -->b=[1,2,3,[11,22,33]] 01):赋值 浅拷贝:我们创建a时, ...

  3. 洛谷 P1272 重建道路

    题目链接 题解 树形dp \(f_{i, j}\)表示以\(i\)为根的子树切出联通块大小为\(j\)的最小答案 显然\(f[i][1]\)为与\(i\)连的边数 设\(v\)是\(u\)的儿子 那么 ...

  4. HDU6396 (贪心+fread 挂)

    题意:初始值你有k个属性的攻击vi,有n个怪兽,每个怪兽有k种属性的血量ai,并且有k种属性的加成bi,当你的k种属性的值全部大于等于某只怪兽的k种属性的血量,你可以杀死他,并且你的攻击力vi会升级, ...

  5. UVA - 11584 DP 最少线段覆盖

    题意:用最少的不可交线段覆盖整个区间,求该最小值 课上摸鱼的时候没注意到题意的转换,写了没啥卵用的回文中心最长枚举,所以代码里的st和h/h2是几乎没用的 注意状态转移的时候不要只用最长线段去转移,这 ...

  6. python-基础学习篇(一)

    python基础学习(一) 不积硅步,无以至千里.基础的学习越加透彻,才能更清楚的理解和分析需求,我贯彻基础学习“永无止境”的理念,故把自学的知识梳理在博客中,基础学习篇无限更新. python介绍 ...

  7. python 可迭代对象,迭代器和生成器,lambda表达式

    分页查找 #5.随意写一个20行以上的文件(divmod) # 运行程序,先将内容读到内存中,用列表存储. # l = [] # 提示:一共有多少页 # 接收用户输入页码,每页5条,仅输出当页的内容 ...

  8. Mercedes BENZ C5 SD Connect Xentry Tab Kit Technical Support

    Why MB Star Diagnostic tool is so well-received by thousands of users, its technology and quality is ...

  9. C#生成二維碼(ThoughtWorks.QRCode)

    本人使用的是ThoughtWorks.QRCode.dll,在網上可以下載,但要注意dll文件的完整性和準確性,本人之前下載的dll就是不正確導致調試時出現錯誤. 以下為cs文件代碼: using S ...

  10. 将libFM模型变换成tensorflow可serving的形式

    fm_model是libFM生成的模型 model.ckpt是可以tensorflow serving的模型结构 亲测输出正确. 代码: import tensorflow as tf # libFM ...