设为首页 收藏本站
查看: 966|回复: 0

[经验分享] Apache Shiro 1.2.1版本发布

[复制链接]

尚未签到

发表于 2017-1-6 10:43:55 | 显示全部楼层 |阅读模式
  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

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-324616-1-1.html 上篇帖子: org.apache.commons包介绍及应用 下篇帖子: Apache 安装完成后出现“No services installed”错误
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表