【发布时间】:2017-12-29 03:44:40
【问题描述】:
我安装了 Apache Shiro 1.4.0 并关注 this official tutorial 以进行设置。
当我尝试使用教程中的这段代码用 SecurityManager 初始化 SecurityUtils 时:
Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini");
SecurityManager securityManager = factory.getInstance();
SecurityUtils.setSecurityManager(securityManager);
我收到一条消息,现在 IniSecurityManagerFactory 已弃用,取而代之的是 Shiro 的 Environment。
我找不到任何说明如何使用 Environment 初始化 Shiro 的教程,而且它的文档也没有多大帮助:
Environment 实例封装了 Shiro 的所有对象 需要发挥作用。它本质上是一个“元”对象,所有 可以为应用程序获取 Shiro 组件。
Environment 实例通常是通过解析 Shiro 配置文件。环境实例可以存储在 应用程序认为必要并从中检索的任何地方 实施中可能需要的任何 Shiro 组件 安全行为。
例如,通过环境可访问的最明显的组件 instance 是应用程序的 securityManager。
那么,我该如何使用这个新的初始化机制呢?
【问题讨论】:
-
FWIW,好像1.4.0还没有正式发布。至少,该网站称 1.4.0 仍处于“抢先体验模式”。所以最好坚持使用 1.3.2,至少在网站更新之前。 (
IniSecurityManagerFactory在 1.3.2 中未弃用。) -
FWIW,我们今天在 Shiro 1.4.2,文档仍然过时。
-
FWI 仍然是 W,当使用 Shiro 1.7.1 跟随 10 minute tutorial 时也会发生同样的情况。
标签: java apache security shiro