shiro 配置-ini配置方式

来源:互联网 发布:淘宝购买不了系统繁忙 编辑:程序博客网 时间:2024/06/07 09:19

ini文件格式

1. [main]

[main]sha256Matcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher  MyRealm = com.company.security.shiro.DatabaseRealmmyRealm.connectionTimeout = 30000myRealm.username= jsmithmyRealm.password = secretmyRealm.credentialsMatcher = $sha256MatchersecurityManager.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 = $sha256MatchermyRealm1 = cn.javass.hello.MyRealm1myRealm2 = cn.javass.hello.MyRealm2authenticator=org.apache.shiro.authc.pam.ModularRealmAuthenticatorauthcStrategy=org.apache.shiro.authc.pam.AllSuccessfulStrategyauthenticator.authenticationStrategy = $authcStrategyauthenticator.realms = $myRealm1, $myRealm2securityManager.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 = falseiniRealm.credentialsMatcher = $sha256Matcher[users]javass = NVsbv8lnJc3Oj0onCP2jEKgObRMxWuxOXu0qdf6AMs4=,role1

3. [roles]

把角色和权限关联起来

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

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

4.[urls]

和web相关 ,到web时再学习