在web.xml中配置spring
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
在web.xml中配置springMvc
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
在web.xml中配置shiro代理过滤器
<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>
spring.xml中文件配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
">
设置扫描的包
<context:component-scan base-package="com"></context:component-scan>
开启注解支持
<mvc:annotation-driven/>
配置扫描的页面属性
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"></property>
<property name="suffix" value=".jsp"/>
</bean>
配置连接到数据库
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url"
value="jdbc:mysql://localhost:3306/shiro01?useUnicode=true&characterEncoding=utf-8"></property>
<property name="username" value="root"></property>
<property name="password" value="mmmm"></property>
</bean>
配置shiro的jdbccrealm
<bean id="jdbcrealm" class="org.apache.shiro.realm.jdbc.JdbcRealm">
<property name="permissionsLookupEnabled" value="true"></property>
<property name="dataSource" ref="dataSource"></property>
<property name="authenticationQuery" value=" SELECT password FROM sec_user WHERE user_name= ?"></property>
<property name="userRolesQuery" value="SELECT role_name from sec_user_role left join sec_role using(role_id) left join sec_user using(user_id) WHERE user_name= ?"></property>
<property name="permissionsQuery" value="SELECT permission_name FROM sec_role_permission left join sec_role using(role_id) left join sec_permission using(permission_id) WHERE role_name = ? "></property>
</bean>
配置shiro的缓存管理
<bean id="cacheManager" class="org.apache.shiro.cache.MemoryConstrainedCacheManager"></bean>
配置shiro的安全管理
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="cacheManager" ref="cacheManager"></property>
<property name="realm" ref="jdbcrealm"></property>
</bean>
配置shiro的过滤器
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager"></property>
配置默认登录界面
<property name="loginUrl" value="login.jsp"></property>
配置无权访问时去的界面
<property name="unauthorizedUrl" value="noqx.jsp"></property>
配置各个权限能访问的页面
<property name="filterChainDefinitions">
<value>
/index.jsp=anon
/result.jsp=authc,roles[admin]
</value>
</property>
</bean>
配置识别注解时各个权限访问
<bean class="org.apache.shiro.spring.LifecycleBeanPostProcessor"></bean>
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator">
<property name="proxyTargetClass" value="true"></property>
</bean>
<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
<property name="securityManager" ref="securityManager"></property>
</bean>
配置各个异常时访问的页面
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="org.apache.shiro.authz.UnauthorizedException">
redirect:/noqx.jsp
</prop>
</props>
</property>
</bean>
</beans>
分享到:
相关推荐
shiro-spring-1.2.4
提供一套基于SpringBoot-shiro-vue的权限管理思路. 前后端都加以控制,做到按钮/接口级别的权限 DEMO 测试地址 admin/123456 管理员身份登录,可以新增用户,角色. 角色可以分配权限 控制菜单是否显示,新增/删除按钮...
spring+mybatis+shiro整合。。。简单入门案例,maven项目
jsets-shiro-spring-boot-starter项目说明springboot中使用shiro大都是通过shiro-spring.jar进行的整合的,虽然不是太复杂,但是也无法做到spring-boot-starter风格的开箱即用。项目中经常用到的功能比如:验证码、...
spring下使用shiro+cas配置单点登录,多个系统之间的访问,每次只需要登录一次 ## 系统模块说明 1. cas: 单点登录模块,这里直接拿的是cas的项目改了点样式而已 2. doc: 文档目录,里面有数据库生成语句,采用的...
Spring-boot-shiro-spring-session-redis-example项目启动后输入:该项目中, 增加了对url的拦截,用admin/123456,拥有index权限reports未任何权限, jdonee/123456尚未分配任何权限.参考shiro Cache交于Redis进行管理...
使用spring框架,shiro权限管理的后台权限管理应用,可以做为企业基础架构
提供一套基于SpringBoot-shiro-vue的权限管理思路. 前后端都加以控制,做到按钮/接口级别的权限 DEMO admin/123456 管理员身份登录,可以新增用户,角色. 角色可以分配权限 控制菜单是否显示,新增/删除按钮是否显示 ...
Spring Boot 2.0.4 & Shiro1.4.0 权限管理系统。 文章地址:https://xttblog.blog.csdn.net/article/details/88353878 FEBS是一个简单高效的后台权限管理系统。项目基础框架采用全新的Java Web开发框架 —— Spring ...
它是一个很易用与Java项目的的安全框架,提供了认证、授权、加密、会话管理,与spring Security 一样都是做一个权限的安全框架,但是与Spring Security 相比,在于 Shiro 使用了比较简单易懂易于使用的授权方式。...
SpringBoot与Shiro整合-权限管理实战源码
maven+springboot+jpa+shiro权限管理内有数据库sql,只要哪里这个基础代码之后的功能添加很方便,适合快速实现项目
Apache Shiro是一个应用广泛的权限管理的用户认证与授权框架。近日,shiro被爆出Apache Shiro 身份验证绕过漏洞 (CVE-2020-11989),攻击者可以使用包含payload的恶意请求绕过Shiro的身份认证,漏洞于1.5.3修复。实际...
Springboot + shiro权限管理shiro-master.zip
springboot+vue+shiro 前后盾分离,权限整合,vue路由配置解析,有sql语句,shiro 权限验证。
spring shiro 权限管理框架 1. 授权需要继承 AuthorizingRealm 类, 并实现其 doGetAuthorizationInfo 方法 2. AuthorizingRealm 类继承自 AuthenticatingRealm, 但没有实现 AuthenticatingRealm 中的 ...
shiro用于权限管理很强大,而且比spring security简单易懂
目前,使用 Apache Shiro 的人越来越多,因为它相 当简单,对比 Spring Security,可能没有 Spring Security 做的功能强大,但是在实际工作时 可能并不需要那么复杂的东西,所以使用小而简单的 Shiro 就足够了。
Apache Shiro是一个应用广泛的权限管理的用户认证与授权框架。近日,shiro被爆出Apache Shiro 身份验证绕过漏洞 (CVE-2020-11989),攻击者可以使用包含payload的恶意请求绕过Shiro的身份认证,漏洞于1.5.3修复。实际...
管理系统系列--Spring Boot & Shiro 权限管理系统