首页 > 应用开发 > IT综合 > shiro 的INI配置
INI配置文件是一种key/value的键值对配置,提供了分类的概念,每一个类中的key不可重复。在这个示例中我们使用一个INI文件来配置Shiro SecurityManager,首先,在pom.xml同目录中创建一个src/main/resources子目录,在该子目录中创建一个shiro.ini文件,内容如下:
点击(此处)折叠或打开
点击(此处)折叠或打开
- [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
- ...
数组类型注入:
点击(此处)折叠或打开
- # 'cipherKey' 是数组类型的默认使用Base64编码
- securityManager.rememberMeManager.cipherKey = kPH+bIxk5D2deZiIxcaaaA==
- ...
- securityManager.rememberMeManager.cipherKey = 0x3707344A4093822299F31D008
集合类型的注入:
Array/Set/List setter,多个值通过逗号分隔
点击(此处)折叠或打开
- 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
点击(此处)折叠或打开
- anObject.map = $objectKey1:$objectValue1, $objectKey2:$objectValue2
- ...
注入顺序:
点击(此处)折叠或打开
- ...
- myRealm = com.company.security.MyRealm
- ...
- myRealm = com.company.security.DatabaseRealm
- ...
默认值:
点击(此处)折叠或打开
- [users]
- admin = 123
- lonestarr = 123, role1, role2
- darkhelmet = 123, role1, role2
- username = password, roleName1, roleName2, ..., roleNameN
点击(此处)折叠或打开
- [main]
- ...
- sha256Matcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher
- ...
- iniRealm.credentialsMatcher = $sha256Matcher
- ...
- [users]
- # user1 = sha256-hashed-hex-encoded password, role1, role2, ...
- user1 = 2bb80d537b1da3e38bd30361aa855686bde0eacd7162fef6a25fe97bf527a25b, role1, role2, ...
- 如果你想让你的密码是base64编码,则如下配置。
点击(此处)折叠或打开
- [main]
- ...
- # true = hex, false = base64:
- sha256Matcher.storedCredentialsHexEncoded = false
点击(此处)折叠或打开
- [roles]
- # 'admin' 拥有所有权限
- admin = *
- # 'schwartz' 拥有lightsaber下所有权限
- schwartz = lightsaber:*
- # 'goodguy' 拥有winnebago下的'drive' 下的 'eagle5'权限
- goodguy = winnebago:drive:eagle5
- rolename = permissionDefinition1, permissionDefinition2, ..., permissionDefinitionN
点击(此处)折叠或打开
- [urls]
- /admin/** = authc, roles[admin], perms["permission1"]
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9399028/viewspace-2102780/ ,如需转载,请注明出处,否则将追究法律责任。