shiro 配置-ini配置方式

ini文件格式

1. [main]

[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

上述实例包括
1.定义对象
2.设置对象属性,如果是原始类型的值,就直接设置。如果是引用类型的值,就用$+名称的方式来设置。密码值,map,set,list
3.可以使用遍历对象图的方式来设置数据
4.securityManager是缺省对象

[main]配置的内容

  1. 定义加密方式 密码进制 认证域 认证策略 认证器
  2. 给认证域 设置加密方式
  3. 给认证器 设置认证域和认证策略
  4. 给securityManager 设置认证器
[main]
#sha256Matcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher  
#sha256Matcher.storedCredentialsHexEncoded = false
#iniRealm.credentialsMatcher = $sha256Matcher


myRealm1 = cn.javass.hello.MyRealm1
myRealm2 = cn.javass.hello.MyRealm2

authenticator=org.apache.shiro.authc.pam.ModularRealmAuthenticator
authcStrategy=org.apache.shiro.authc.pam.AllSuccessfulStrategy
authenticator.authenticationStrategy = $authcStrategy
authenticator.realms = $myRealm1, $myRealm2

securityManager.authenticator = $authenticator

2. [users] 定义一组静态的用户账户

[users]
javass=cc,role1

每行的格式: username = password,rolename1,rolename2……

自动初始化realm:仅定义非空的[users]或[roles],section会自动创建IniRealm的实例,并使它在[main]可以用并且名为iniRealm

加密密码 16进制

// 获取密码的hex加密字符串 16进制
String ss = new Sha256Hash("cc").toHex();
[main]
sha256Matcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher   
iniRealm.credentialsMatcher = $sha256Matcher

[users]
javass = 355b1bbfc96725cdce8f4a2708fda310a80e6d13315aec4e5eed2a75fe8032ce,role1

加密密码 64进制

//获取密码的hex加密字符串 64进制
String ss1 = new Sha256Hash("cc").toBase64();
[main]
sha256Matcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher  
sha256Matcher.storedCredentialsHexEncoded = false
iniRealm.credentialsMatcher = $sha256Matcher


[users]
javass = NVsbv8lnJc3Oj0onCP2jEKgObRMxWuxOXu0qdf6AMs4=,role1

3. [roles]

把角色和权限关联起来

[roles]
role1="p1:create,update",p2

每行格式: rolename = permissionName1,permissionName2……

4.[urls]

和web相关 ,到web时再学习

posted on 2017-09-26 16:29  dreamstar  阅读(216)  评论(0编辑  收藏  举报