2012年7月29日Apache Shiro开源小组发布了Apache Shiro 1.2.1,此版本主要是修复了1.2.0版本中的11个bug。
Apache Shiro 1.2版本有哪些新功能点呢?通过其官方网站可以看到主要包含在4个方面:Tools, Core, Web, and Support Modules。
Tools
提供了一个命令行工具包可以为各种数据生成哈希值:shiro-tools-hasher-1.2.1-cli.jar
。
运行 java -jar shiro-tools-hasher-1.2.1-cli.jar 可看到帮助信息,此工具包可以为各种形式的数据生成哈希值,比如:标准的文本,密码,字符串,文件或是URL资源等。
帮助信息如下,已经很直观了:
usage: java -jar shiro-tools-hasher-<version>.jar [options] [<value>]
Print a cryptographic hash (aka message digest) of the specified <value>.
--
Options:
-a,--algorithm <name> hash algorithm name. Defaults to SHA-256
when password hashing, MD5 otherwise.
-d,--debug show additional error (stack trace)
information.
-f,--format <arg> hash output format. Defaults to 'shiro1'
when password hashing, 'hex' otherwise.
See below for more information.
-gs,--gensalt generate and use a random salt. Defaults
to true when password hashing, false
otherwise.
-gss,--gensaltsize <numBits> the number of salt bits (not bytes!) to
generate. Defaults to 128.
-help,--help show this help message.
-i,--iterations <num> number of hash iterations. Defaults to
500000 when password hashing, 1 otherwise.
-ngs,--nogensalt do NOT generate and use a random salt
(valid during password hashing).
-p,--password hash a password (disable typing echo)
-pnc,--pnoconfirm hash a password (disable typing echo) but
disable password confirmation prompt.
-r,--resource read and hash the resource located at
<value>. See below for more information.
-s,--salt <sval> use the specified salt. <arg> is
plaintext.
-sb,--saltbytes <encTxt> use the specified salt bytes. <arg> is
hex or base64 encoded text.
<value> is optional only when hashing passwords (see below). It is
required all other times.
Password Hashing:
---------------------------------
Specify the -p/--password option and DO NOT enter a <value>. You will
be prompted for a password and characters will not echo as you type.
Salting:
---------------------------------
Specifying a salt:
You may specify a salt using the -s/--salt option followed by the salt
value. If the salt value is a base64 or hex string representing a
byte array, you must specify the -sb/--saltbytes option to indicate this,
otherwise the text value bytes will be used directly.
When using -sb/--saltbytes, the -s/--salt value is expected to be a
base64-encoded string by default. If the value is a hex-encoded string,
you must prefix the string with 0x (zero x) to indicate a hex value.
Generating a salt:
Use the -sg/--saltgenerated option if you don't want to specify a salt,
but want a strong random salt to be generated and used during hashing.
The generated salt size defaults to 128 bits. You may specify
a different size by using the -sgs/--saltgeneratedsize option followed by
a positive integer (size is in bits, not bytes).
Because a salt must be specified if computing the
hash later, generated salts will be printed, defaulting to base64
encoding. If you prefer to use hex encoding, additionally use the
-sgh/--saltgeneratedhex option.
Files, URLs and classpath resources:
---------------------------------
If using the -r/--resource option, the <value> represents a resource path.
By default this is expected to be a file path, but you may specify
classpath or URL resources by using the classpath: or url: prefix
respectively.
Some examples:
<command> -r fileInCurrentDirectory.txt
<command> -r ../../relativePathFile.xml
<command> -r ~/documents/myfile.pdf
<command> -r /usr/local/logs/absolutePathFile.log
<command> -r url:http://foo.com/page.html
<command> -r classpath:/WEB-INF/lib/something.jar
Output Format:
---------------------------------
Specify the -f/--format option followed by either 1) the format ID (as defined
by the org.apache.shiro.crypto.hash.format.DefaultHashFormatFactory
JavaDoc) or 2) the fully qualified org.apache.shiro.crypto.hash.format.HashFormat
implementation class name to instantiate and use for formatting.
The default output format is 'shiro1' which is a Modular Crypt Format (MCF)
that shows all relevant information as a dollar-sign ($) delimited string.
This format is ideal for use in Shiro's text-based user configuration (e.g.
shiro.ini or a properties file).
Core
增加了PasswordService组件,目的是将密码相关的一些逻辑和配置抽象出来,使程序的开发人员只关注密码本身即可。相应哈希算法,迭代,密码加盐等都在组件内部实现。
同时这种组件形式可以很好地复用。
增加了PasswordMatcher组件,PasswordMatcher实现了CredentialsMatcher接口,在认证过程中使用PasswordService时进行密码的比对。
password service 和 password matcher都可配置到Realm中使用。
如果使用文本方式配置用户账号的话,可以使用上述新增的组件和命令行工具在文本中安全地存储用户的密码。
认证缓存是一个新加的功能,主要应用在一些无状态的框架中,如REST或者基于SOAP的应用程序,在这些应用中每个请求都需要进行身份验证。这样就需要支持应用程序在相对较短的时间内对相同账号进行重复验证。如果每次验证时都需要访问数据源就会造成很大的压力,认证缓存将账号信息进行缓存以被短时间内的使用来减轻后台的数据源压力。
想要使用认证缓存机制必须实现3步:
1、你自己的认证Realm必须继承AuthenticatingRealm类或者是AuthorizingRealm;
2、必须为SecurityManager配置CacheManager. cacheManager = com.foo.some.CacheManager securityManager.cacheManager = $cacheManager
3、必须为认证Realm启用认证缓存 myRealm.authenicationCachingEnabled = true
WEB
增加了两个接口Environment 和 WebEnvironment。可允许开发人员通过Environment实例获得Shiro相关的实例对象。Shiro Filter将依赖于WebEnvironment中的对象,
当Servlet Context Listener初始化好后它将放到WebEnvironment实例中供应用程序来访问。你可以通过WebUtils类来访问WebEnvironment和它包含的对象。
通过配置可非常方便地启用或停用过滤器,如下:
[main]
…
# uncomment the following line to disable the ‘ssl’ filter:
# ssl.enabled = false
[urls]
/securedEndpoint/** = ssl, someFilter, anotherFilter, ...
在开发的时候可以去掉注释ssl.enabled = false
这样就不会执行ssl通讯,在实际应用时加上注释就会执行ssl。
新增了LogoutFilter实现将用户注销然后重定向到一个默认页。
新增了NoSessionCreationFilter过滤器主要应用于象REST或者基于SOAP这样的应用框架中。使用此过滤器可防止有人意外地创建会话,NoSessionCreationFilter对实现认证缓存的作用很大,可很好支持象REST这样的无状态应用。
New Support Modules
Apache Shiro本身就支持很多第三方的接口,例如Spring Framework 和 AspectJ等。在1.2版本里又新增了三个模块:
1、Shiro support for Google Guice
2、Shiro support for Jasig CAS
3、Apache Karaf features.xml
分享到:
相关推荐
Apache Shiro 是一个框架,可用于身份验证和授权。Apache Shiro的教程(PDF),相关jar包,源码等。
springboot、shiro、mybatis、mybatis plus、mysql、thymeleaf、 3、实现功能:登陆认证、密码加密、权限授权等 4、优点:快速上手、全面支持验证、授权、加密和会话、灵活自定义设计、支持web环境、可以无缝集成...
Apache_Shiro_使用手册(一)Shiro架构介绍
Apache Shiro。 官网 Apache Shiro API。 Apache Shiro开发文档。
Apache Shiro中文版使用手册!
shiro最简单整合版本shiro最简单整合版本shiro最简单整合版本shiro最简单整合版本shiro最简单整合版本
Apache shiro 1.13.0源码 https://shiro.apache.org/
Apache Shiro 是一个强大而灵活的开源安全框架,它干净利落地处理身份认证,授权,企业会话管理和加密。 Apache Shiro 的首要目标是易于使用和理解。安全有时候是很复杂的,甚至是痛苦的,但它没有必要这样。框架...
采用SpringBoot + Apache Shiro + Mybatis Plus + Thymeleaf 实现的内容管理系统(附带权限管理),是搭建博客、网站的不二之选。 技术栈:Spring Boot、Apache Shiro、MyBatis-Plus、Alibaba Druid、Redis、MySQL、...
2020年8月17日,shiro发布了1.6.0版本,修复了绕过认证的bug。这里面包含1.1、1.6版本的jar包
apache shiro 实例 apache shiro 实例
apache shiro 管理用户权限与数据库交互
Shiro 是一个 Apache Incubator 项目,旨在简化身份验证和授权。在本文中,了解 Apache Shiro 并通过示例来在一个 Groovy web 应用程序中尝试使用 Shiro 进行身份验证和授权
本系统(基于SpringBoot+MyBatis+Apache Shiro+Bootstrap+Thymeleaf) 可用于开发所有企业级WEB应用系统(如:各种后台管理系统、CRM、ERP、CMS、OA、博客、论坛等...)。响应式布局,支持大部分浏览器(如:IE9+...
Apache shiro1.2.4反序列化漏洞介绍 Apache Shiro是一个Java安全框架,执行身份验证、授权、密码和会话管理。Apache Shiro框架提供了记住我(RememberMe)的功能,关闭了浏览器下次再打开时还是能记住你是谁,下次...
Apache Shiro是一个强大易用的Java安全框架,提供了认证、授权、加密和会话管理等功能。 使用Shiro的易于理解的API,您可以快速、轻松地获得任何应用程序,从最小的移动应用程序到最大的网络和企业应用程序。
Apache_Shiro 4个jar, 上传了个中文手册 赚一分,这个免费
Apache Shiro(发音为“shee-roh”,日语“堡垒(Castle)”的意思)是一个强大易用的Java安全框架,提供了认证、授权、加密和会话管理功能,可为任何应用提供安全保障 - 从命令行应用、移动应用到大型网络及企业...
spring mvc、apache shiro、mysql 框架搭建,基于maven构建
Apache Shiro是一个强大且易用的Java安全框架,执行身份验证、授权、密码和会话管理。使用Shiro的易于理解的API,您可以快速、轻松地获得任何应用程序,从最小的移动应用程序到最大的网络和企业应用程序。