Apache Shiro系列之五,概述 —— 配置
Shiro设计的初衷就是可以运行于任何环境:无论是简单的命令行应用程序还是复杂的企业集群应用。由于运行环境的多样性,所以有多种配置机制可用于配置,本节我们将介绍Shiro内核支持的这几种配置机制。
Realm realm =//instantiate or acquire a Realm instance. We'll discuss Realms later.
SecurityManager securityManager =newDefaultSecurityManager(realm);
//Make the SecurityManager instance available to the entire application via static memory:
SecurityUtils.setSecurityManager(securityManager);
...
DefaultSecurityManager securityManager =newDefaultSecurityManager(realm);
SessionDAO sessionDAO =newCustomSessionDAO();
((DefaultSessionManager)securityManager.getSessionManager()).setSessionDAO(sessionDAO);
...
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.util.Factory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.config.IniSecurityManagerFactory;
...
Factory<SecurityManager> factory =newIniSecurityManagerFactory("classpath:shiro.ini");
SecurityManager securityManager = factory.getInstance();
SecurityUtils.setSecurityManager(securityManager);
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.util.Factory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.config.Ini;
import org.apache.shiro.config.IniSecurityManagerFactory;
...
Ini ini =newIni();
//populate the Ini instance as necessary
...
Factory<SecurityManager> factory =newIniSecurityManagerFactory(ini);
SecurityManager securityManager = factory.getInstance();
SecurityUtils.setSecurityManager(securityManager);
#=======================
#Shiro INI configuration
#=======================
[main]
#Objects and their properties are defined here,
#Such as the securityManager,Realms and anything
#else needed to build the SecurityManager
[users]
#The'users' section is for simple deployments
# when you only need a small number of statically-defined
# set of User accounts.
[roles]
#The'roles' section is for simple deployments
# when you only need a small number of statically-defined
# roles.
[urls]
#The'urls' section is used for url-based security
# in web applications.We'll discuss this section in the
#Web documentation
[main]
sha256Matcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher
myRealm = com.company.security.shiro.DatabaseRealm
myRealm.connectionTimeout =30000
myRealm.username = jsmith
myRealm.password = secret
myRealm.credentialsMatcher = $sha256Matcher
securityManager.sessionManager.globalSessionTimeout =1800000
[main]
myRealm = com.company.shiro.realm.MyRealm
...
...
myRealm.connectionTimeout =30000
myRealm.username = jsmith
...
...
myRealm.setConnectionTimeout(30000);
myRealm.setUsername("jsmith");
...
...
sha256Matcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher
...
myRealm.credentialsMatcher = $sha256Matcher
...
...
securityManager.sessionManager.globalSessionTimeout =1800000
...
securityManager.getSessionManager().setGlobalSessionTimeout(1800000);
#The'cipherKey' attribute is a byte array.Bydefault, text values
#for all byte array properties are expected to be Base64 encoded:
securityManager.rememberMeManager.cipherKey = kPH+bIxk5D2deZiIxcaaaA==
...
sessionListener1 = com.company.my.SessionListenerImplementation
...
sessionListener2 = com.company.my.other.SessionListenerImplementation
...
securityManager.sessionManager.sessionListeners = $sessionListener1, $sessionListener2
object1 = com.company.some.Class
object2 = com.company.another.Class
...
anObject = some.class.with.a.Map.property
anObject.mapProperty = key1:$object1, key2:$object2
...
myRealm = com.company.security.MyRealm
...
myRealm = com.company.security.DatabaseRealm
...
myRealm =...
securityManager.sessionManager.globalSessionTimeout =1800000
...
...
securityManager = com.company.security.shiro.MyCustomSecurityManager
...
[users]
admin = secret
lonestarr = vespa, goodguy, schwartz
darkhelmet = ludicrousspeed, badguy, schwartz
[main]
...
sha256Matcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher
...
iniRealm.credentialsMatcher = $sha256Matcher
...
[users]
# user1 = sha256-hashed-hex-encoded password, role1, role2,...
user1 =2bb80d537b1da3e38bd30361aa855686bde0eacd7162fef6a25fe97bf527a25b, role1, role2,...
org.apache.shiro.authc.credential.HashedCredentialsMatcher
的API文档。[main]
...
#true= hex,false= base64:
sha256Matcher.storedCredentialsHexEncoded =false
[roles]
#'admin' role has all permissions, indicated by the wildcard '*'
admin =*
#The'schwartz' role can do anything (*) with any lightsaber:
schwartz = lightsaber:*
#The'goodguy' role is allowed to 'drive'(action) the winnebago (type) with
# license plate 'eagle5'(instance specific id)
goodguy = winnebago:drive:eagle5
org.apache.shiro.authz.permission.WildcardPermission
格式兼容的文本格式,这种格式简单而又灵活。可以查看权限( Permissions)章节来了解更多关于这种权限格式的信息。本系列相关:
Apache Shiro系列之五,概述 —— 配置的更多相关文章
- Apache Shiro系列四,概述 —— Shiro的架构
Shiro的设计目标就是让应用程序的安全管理更简单.更直观. 软件系统一般是基于用户故事来做设计.也就是我们会基于一个客户如何与这个软件系统交互来设计用户界面和服务接口.比如,你可能会说:“如 ...
- Apache Shiro系列三,概述 —— 10分钟入门
一.介绍 看完这个10分钟入门之后,你就知道如何在你的应用程序中引入和使用Shiro.以后你再在自己的应用程序中使用Shiro,也应该可以在10分钟内搞定. 二.概述 关于Shiro的废话就不多说了 ...
- Apache Shiro系列一,概述 —— 初识
一.什么是Shiro Apache Shiro是一个强大.灵活.开源的安全框架,它支持用户认证.权限控制.企业会话管理以及加密等. Apache Shiro的第一个也是最重要的一个目标就是易于使用和理 ...
- Apache Shiro系列教程之二:十分钟上手Shiro
在本教程中,我们会写一个简单的.仅仅输出一些内容命令行程序,从而对Shiro有一个大体的感觉. 一.准备工作 本教程需要Java1.5+,并且我们用Maven生成项目,当然Maven不是必须的,你也可 ...
- Apache Shiro(六)-基于URL配置权限
数据库 先准备数据库啦. DROP DATABASE IF EXISTS shiro; CREATE DATABASE shiro DEFAULT CHARACTER SET utf8; USE sh ...
- Apache Shiro系列(1)
Apache Shiro是啥呢,安全框架. 360百科是这么描述的: Apache Shiro(日语"堡垒(Castle)"的意思)是一个强大易用的Java安全框架, ...
- Apache Shiro系列二,概述 —— 基本概念
做任何事情,首先要双方就一些概念的理解达成一致,这样大家就有共同语言,后续的沟通效率会高一些. #,Authentication,认证,也就是验证用户的身份,就是确定你是不是你,比如通过用户名.密码的 ...
- Apache Shiro系列教程之三:Shiro的结构
Shiro的设计目标是简化应用的安全管理工作.软件通常是以用户为基础设计的.也就是说,我们经常是根据用户是怎样和我们的软件交互的来设计相关的用户接口.比如,你可能会说"如果是已经登录的用户与 ...
- Apache Shiro学习-2-Apache Shiro Web Support
Apache Shiro Web Support 1. 配置 将 Shiro 整合到 Web 应用中的最简单方式是在 web.xml 的 Servlet ContextListener 和 Fil ...
随机推荐
- MySQL中CURRENT_TIMESTAMP(转)
1. MySQL 获得当前时间戳函数:current_timestamp, current_timestamp() 代码如下 mysql> select current_timestamp ...
- UITextView 开始编辑时,文字没有左上角对齐解决办法 tableview整体上移
现实情况如上所示 我出现这种情况的原因有两种: 其一:没有给textview对齐方式: 其二:没有将BOOL类型的“ automaticallyAdjustsScrollViewInsets ”属性置 ...
- 源代码管理工具之SVN
源代码管理工具SVN是一款非常强大的源代码管理工具,现在国内70%-90%的公司都在使用SVN来管理源代码,下面就让小编给大家着重介绍一下SVN的使用,SVN的使用主要分为下面几块. SVN的使用环境 ...
- iOS Class 使用NSProxy和NSObject设计代理类的差异
经常发现在一些需要使用消息转发而创建代理类时, 不同的程序员都有着不同的使用方法, 有些采用继承于NSObject, 而有一些采用继承自NSProxy. 二者都是Foundation框架中的基类, 并 ...
- 敏捷开发与jira之研发管理模式
以IPD方法论为基础,采用原型+迭代的开发模式,并以质量优先为原则,持续对用户做价值交付. 使用JIRA+WIKI+SVN管理整个的研发过程:JIRA管理任务和进度:SVN管理代码和过程文档:WIKI ...
- [C#6] 2-nameof 运算符
0. 目录 C#6 新增特性目录 1. 老版本的代码 using System; namespace csharp6 { internal class Program { private static ...
- SQL SERVER 2012 修改数据库默认位置不立即生效
今天修改SQL SERVER 2012的数据库默认位置:即数据文件.日志文件默认位置时遇到一个问题,单击"服务器属性"(Server Properties)--> 数据库设置 ...
- SQL SERVER 重组含有特殊字符的索引时遇到“关键字 'with' 附近有语法错误.”
案例描述 这是在索引重组过程中遇到的有意思的错误案例,搜索了一下也没有看到相关资料,估计我第一个碰到这类错误的人(It's just a joke).具体情况是YourSQLDba在做维护数据库索引时 ...
- c#获取时间
DateTime.Now.AddDays(10).ToShortDateString().ToString() addDays(整数) 一天前DateTime.Now.AddDays(-1).ToSh ...
- List tuple 类型转成数组
SKlearning大部分的输入数据都是M * N数组. 然而我们从数据库或文件读取得来的通常是Python内定的类型tuple或list 它们的优势就不说了,但是直接把list或tuple构成的二维 ...