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. Reviewing notes 2.1 of Mathematical analysis

    Chapter2 Numerical sequence and function Cartesian product set If S and T are sets,then the cartesia ...

  2. 两种unix网络编程线程池的设计方法

    unp27章节中的27.12中,我们的子线程是通过操作共享任务缓冲区,得到task的,也就是通过线程间共享的clifd[]数组,这个数组其实就是我们的任务数组,得到其中的connfd资源. 我们对这个 ...

  3. C#中实现https的双向认证

    1.  把浏览器中的证书导出为cer文件. 2.   代码如下: using System; using System.Net; using System.IO; using System.Secur ...

  4. 解压与压缩(把dataset转为string、、 )

    /// <summary> /// 压缩 解压 /// </summary> public class ZipHelper { #region 压缩解缩 /// <sum ...

  5. angular-ui-select 下拉框支持过滤单选多选解决方案(系列一)

    angular-ui-select  官方文档:github地址:https://github.com/angular-ui/ui-select 请大家多看文档     首先注意版本的问题,如果版本不 ...

  6. C++_基础3-循环和关系表达式

    这一部分内容节选自<C++ Primer Plus>的第五章 程序需要有执行重复的操作和进行决策的工具. ========================================= ...

  7. hdu 2570 贪心

    贪心的经典题型 该死的精度问题,WA了好几次,以后能用乘的绝不用除!! #include<iostream> #include<algorithm> #include<c ...

  8. springboot(五)-使用Redis

    Redis服务器 springboot要使用redis,首先当然要确保redis服务器能够正常跑起来. pom.xml 这里添加redis的依赖,当然也是springboot集成好的. <!-- ...

  9. Phyton Flask框架学习记录。

    注意:在左侧菜单栏(在JQuery插件库下载的)右边是采用<iframe> 标签嵌入其他页面,此时标签的src应用用后台中的方法名称(本人测试用的是无参数的方法), 而页面跳转window ...

  10. maven-eclipse-plugin downloadSources downloadJavadocs

    <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-eclip ...