(注:初始登录账号:admin 密码:123456)
简介:本篇博客讲解了关于Shiro的四个部分
一:Shiro的基本介绍
二:Shiro的项目搭建
三:Shiro代码下载参考(项目+sql文件)
四:关于Shrio的问题分析
五:数据库表设计
一:Shiro的基本介绍
1:什么是Shiro、有什么用、什么时候使用?
shiro是一个安全框架,可以集成spring框架,
主要功能:认证、授权、加密、回话管理
一般在进行权限分配的项目中使用(总监、经理、员工...)
2:三大核心组件(缺一不可)
subject:用户
SecurityManager:安全管理
Realm:充当Shiro与安全数据间的桥梁(最少配置一个)
二:Shiro的项目搭建
项目流程介绍
web.xml中配置 ----> applicationContext-shiro.xml ----> 相应类
流程详解:
1:在web.xml中配置两处
1.1:过滤器代理(不配置则Shiro不生效)
<filter>
<!-- 此处的name 要和配置文件中 filter工厂的id一样 -->
<filter-name>shiroFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<!-- 让shiro过滤器的生命周期 交给web容器管理 -->
<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>
1.2:在配置懒加载和监听器(已配置就不要重复配置)
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/applicationContext*.xml</param-value>
org.springframework.web.context.ContextLoaderListener
2:在pom.xml导入相应jar
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-all</artifactId>
<version>1.2.3</version>
</dependency>
3:新建applicationContext-shiro.xml,并进行相关配置
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
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
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0