您的位置:首页 > 其它

shiro 配置-ini配置方式

2017-09-26 16:29 148 查看
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]配置的内容

定义加密方式 密码进制 认证域 认证策略 认证器

给认证域 设置加密方式

给认证器 设置认证域和认证策略

给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时再学习
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  shiro ini