Apache Shiro知识点总览
名词解释
权限认证
授权
ini文件配置
jsp标签授权
Shiro会话机制
自定义Realm
加密、解密
特性
与spring整合
名词解释
Subject:认证主体
Reaml:认证来源[jdbc、property、text、jndi]
权限认证
谁访问什么资源
权限:页面
角色:权限的集合
用户:subject
授权
为角色分配权限
例如:admin = user : *
ini文件配置
[main]
authc.loginUrl = /login
roles.unauthorizedUrl = /unauthorized
perms.unauthorizedUrl = /unauthorized.jsp
[users]
jack = 123,admin
[roles]
admin = user : *
[urls]
/login = anon
/admin = authc
/student = roles[teacher]
/teacher = perms["user:create"]
Url匹配规则
/admin 匹配/admin
/admin? 匹配/admin1
/admin* 匹配/admin123
/admin/** 匹配/admin/1/2/3
jsp标签授权
依赖
shiro-web.jar
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
例如:
<shiro:guest> Hi there! Please
<a href="login.jsp">Login</a> or
<a href="signup.jsp">Signup</a> today!
</shiro:guest>
Shiro会话机制
Subject currentUser = SecurityUtils.getSubject();
Session session = currentUser.getSession();
session.setAttribute( "someKey", someValue);
getSession calls work in any application, even non-web applications.
自定义Realm
Most people choose to subclass the AuthorizingRealm abstract class instead of starting from scratch. This class implements common authentication and authorization workflow to save you time and effort.
加密、解密
例如:
new Md5Hash(data)
特性
Web Support: Shiro’s web support APIs help easily secure web applications.
Caching: Caching is a first-tier citizen in Apache Shiro’s API to ensure that security operations remain fast and efficient.
Concurrency: Apache Shiro supports multi-threaded applications with its concurrency features.
Testing: Test support exists to help you write unit and integration tests and ensure your code will be secured as expected.
“Run As”: A feature that allows users to assume the identity of another user (if they are allowed), sometimes useful in administrative scenarios.
“Remember Me”: Remember users’ identities across sessions so they only need to log in when mandatory.
与spring整合
web.xml
<!-- The filter-name matches name of a 'shiroFilter' bean inside applicationContext.xml -->
<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>...
<!-- Make sure any request you want accessible to Shiro is filtered. /* catches all --><!-- requests. Usually this filter mapping is defined first (before all others) to --><!-- ensure that Shiro works in subsequent filters in the filter chain: -->
<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
applicationContext.xml
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager"/>
<property name="loginUrl" value="/login.jsp"/>
<property name="successUrl" value="/home.jsp"/>
<property name="unauthorizedUrl" value="/unauthorized.jsp"/>
<property name="filterChainDefinitions">
<value>
# some example chain definitions:
/admin/** = authc, roles[admin]
/docs/** = authc, perms[document:read]
/** = authc
# more URL-to-FilterChain definitions here
</value>
</property>
</bean>
<bean id="someFilter" class="..."/>
<bean id="anotherFilter" class="..."> ...
</bean>...
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="realm" ref="myRealm"/>
</bean>
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"/>
<bean id="myRealm" class="..."> ...
</bean>
Apache Shiro知识点总览的更多相关文章
- Apache Shiro系列四,概述 —— Shiro的架构
Shiro的设计目标就是让应用程序的安全管理更简单.更直观. 软件系统一般是基于用户故事来做设计.也就是我们会基于一个客户如何与这个软件系统交互来设计用户界面和服务接口.比如,你可能会说:“如 ...
- Apache Shiro(六)-基于URL配置权限
数据库 先准备数据库啦. DROP DATABASE IF EXISTS shiro; CREATE DATABASE shiro DEFAULT CHARACTER SET utf8; USE sh ...
- Apache Shiro(四)-登录认证和权限管理WEB支持(Servlet)
新建web项目 web.xml 修改web.xml,在里面加了个过滤器. 这个过滤器的作用,简单的说,就是 Shiro 入门里的TestShiro 这部分的工作,悄悄的干了. //加载配置文件,并获取 ...
- Apache Shiro(二)-登录认证和权限管理数据库操作
数据库支持 在上一篇中使用ini 配置文件进行了相关权限数据的配置. 但是实际工作中,我们都会把权限相关的内容放在数据库里. 所以本知识点讲解如何放在数据库里来撸. RBAC 概念 RBAC 是当下权 ...
- Apache Shiro 反序列化漏洞复现(CVE-2016-4437)
漏洞描述 Apache Shiro是一个Java安全框架,执行身份验证.授权.密码和会话管理.只要rememberMe的AES加密密钥泄露,无论shiro是什么版本都会导致反序列化漏洞. 漏洞原理 A ...
- Apache Shiro 学习记录5
本来这篇文章是想写从Factory加载ini配置到生成securityManager的过程的....但是貌似涉及的东西有点多...我学的又比较慢...很多类都来不及研究,我又怕等我后面的研究了前面的都 ...
- Apache Shiro 学习记录2
写完上篇随笔以后(链接).....我也想自己尝试一下写一个Strategy.....Shiro自带了3个Strategy,教程(链接)里作者也给了2个.....我想写个都不一样的策略.....看来看去 ...
- Apache Shiro系列(1)
Apache Shiro是啥呢,安全框架. 360百科是这么描述的: Apache Shiro(日语"堡垒(Castle)"的意思)是一个强大易用的Java安全框架, ...
- Apache Shiro系列之五,概述 —— 配置
Shiro设计的初衷就是可以运行于任何环境:无论是简单的命令行应用程序还是复杂的企业集群应用.由于运行环境的多样性,所以有多种配置机制可用于配置,本节我们将介绍Shiro内核支持的这几种配置机制. ...
随机推荐
- lvs虚拟服务器
NAT模式 1.模拟环境: LVS服务器有两块网卡,连接外网(用户端)和内网(服务器),充当"交警"角色. 优点: 节省ip开销 缺点: LVS服务器负载过高,数据吞吐量降低 三台 ...
- .net 开源框架--转载
Json.NET http://json.codeplex.com/ Json.Net 是一个读写Json效率比较高的.Net框架.Json.Net 使得在.Net环境下使用Json更加简单.通过Li ...
- BZOJ2539: [Ctsc2000]丘比特的烦恼
BZOJ2539: [Ctsc2000]丘比特的烦恼 Description 随着社会的不断发展,人与人之间的感情越来越功利化. 最近,爱神丘比特发现,爱情也已不再是完全纯洁的了. 这使得丘比特很是苦 ...
- Ubuntu12.04如何修改窗口背景色为眼睛保护色来保护眼睛,强力推荐!!
最近突然发现盯着屏幕看的久了,眼睛会非常的痛苦,因此想改变一下系统的窗口背景颜色.其实看代码主要是在Eclipse里面察看,因此一开始我就想改变Eclipse的文本编辑框的背景颜色,效果如下图所示. ...
- 2016WWDC详解
今年苹果WWDC 2016上把所有系统都更新了个遍,watchOS.tvOS.macOS 和 iOS 都或多或少带来了新功能. 本文的主角是更新最多的 iOS 10,第一时间在一部 iPhone 6s ...
- Automator 实例:使用快捷键 实现 快速在当前路径 打开 iTerm
1. 在 finder -> 应用程序 或 通过 Spotlight 打开:Automator.app 2. 选择新建 “服务” 3. 设置服务,见下图,设置完成之后,command + s 保 ...
- mySql执行效率分析
1.关于SQL查询效率,100w数据,查询只要1秒,与您分享: 机器情况p4: 2.4内存: 1 Gos: windows 2003数据库: ms sql server 2000目的: 查询性能测试, ...
- Git core objects
Git core objects Core objects in git blob object tree object commit object Git low level commands gi ...
- 51nod 1225
题目 题解:看数据范围就估计是根号算法.考虑我们要求的式子: $ \sum\limits_{i = 1}^n {n - \left\lfloor {\frac{n}{i}} \right\rfloor ...
- UER#7 T2
题意:给定n个数,对于2到n,分别输出一个答案.答案定义为:对于当前的数k,在原数组中找一个长度为k的区间,使得区间最值之差最小,输出差值.注意,差值允许5%的误差. 很少看见近似算法的题啊..跪烂V ...