标签:唯一性 border 原因 license 抽象 智能 静态 nis 比较
Shiro设计的初衷就是可以运行于任何环境:无论是简单的命令行应用程序还是复杂的企业集群应用。由于运行环境的多样性,所以有多种配置机制可用于配置,本节我们将介绍Shiro内核支持的这几种配置机制。
1 Realm realm =//instantiate or acquire a Realm instance. We‘ll discuss Realms later. 2 SecurityManager securityManager =newDefaultSecurityManager(realm); 3 //Make the SecurityManager instance available to the entire application via static memory: 4 SecurityUtils.setSecurityManager(securityManager);
... DefaultSecurityManager securityManager =newDefaultSecurityManager(realm); SessionDAO sessionDAO =newCustomSessionDAO(); ((DefaultSessionManager)securityManager.getSessionManager()).setSessionDAO(sessionDAO); ...
1 import org.apache.shiro.SecurityUtils; 2 import org.apache.shiro.util.Factory; 3 import org.apache.shiro.mgt.SecurityManager; 4 import org.apache.shiro.config.IniSecurityManagerFactory; 5 ... 6 Factory<SecurityManager> factory =newIniSecurityManagerFactory("classpath:shiro.ini"); 7 SecurityManager securityManager = factory.getInstance(); 8 SecurityUtils.setSecurityManager(securityManager);
1 import org.apache.shiro.SecurityUtils; 2 import org.apache.shiro.util.Factory; 3 import org.apache.shiro.mgt.SecurityManager; 4 import org.apache.shiro.config.Ini; 5 import org.apache.shiro.config.IniSecurityManagerFactory; 6 ... 7 Ini ini =newIni(); 8 //populate the Ini instance as necessary 9 ... 10 Factory<SecurityManager> factory =newIniSecurityManagerFactory(ini); 11 SecurityManager securityManager = factory.getInstance(); 12 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 ...
1 ... 2 myRealm.setConnectionTimeout(30000); 3 myRealm.setUsername("jsmith"); 4 ...
1 ... 2 sha256Matcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher 3 ... 4 myRealm.credentialsMatcher = $sha256Matcher 5 ...
... securityManager.sessionManager.globalSessionTimeout =1800000 ...
1 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)章节来了解更多关于这种权限格式的信息。
本系列相关:
标签:唯一性 border 原因 license 抽象 智能 静态 nis 比较
原文地址:http://www.cnblogs.com/strinkbug/p/6158522.html