Apache Shiro 已經有內建 Cache 機制,http://shiro.apache.org/caching.html
但也能自行 implement,整合其它的 Cache Server (JCache, Ehcache, JCS, OSCache, JBossCache, TerraCotta, Coherence, GigaSpaces)
implement 方式,可以參考這個網址
http://www.java2s.com/Open-Source/Java/Authentication-Authorization/shrio/org/apache/shiro/cache/ehcache/Catalogehcache.htm
使用時,需在 shiro.ini 增加幾行資料
#Use Infinispan HotRod Cache
cacheManager = com.test.cache.SessionCacheManager
securityManager.cacheManager = $cacheManager
sessionDAO = org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO
securityManager.sessionManager.sessionDAO = $sessionDAO
Google Code Prettify
2013年10月8日 星期二
Apache Shiro JdbcRealm and RememberMe
僅需要在 shiro.ini 增加幾行資料
#Setting JdbcRealm
jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
#取得帳號密碼
jdbcRealm.authenticationQuery = select user_pass from users where user_name = ?
#取得Roles資料
jdbcRealm.userRolesQuery = select role_name from user_roles where user_name = ?
#使用JNDI DataSource
dataSource = org.apache.shiro.jndi.JndiObjectFactory
dataSource.resourceName = java:/comp/env/jdbc/EmployeeDB
jdbcRealm.dataSource = $dataSource
securityManager.realms = $jdbcRealm
#-----------------------------------------------------------------------------------------
#Setting RememberMe
rememberMeManager = org.apache.shiro.web.mgt.CookieRememberMeManager
securityManager.rememberMeManager = $rememberMeManager
securityManager.rememberMeManager.cookie.name = remember_me
#設定cookie.maxAge = blah , cookie會無法正常寫入
#securityManager.rememberMeManager.cookie.maxAge = blah
securityManager.rememberMeManager.cookie.domain = testdomain.com
#Setting JdbcRealm
jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
#取得帳號密碼
jdbcRealm.authenticationQuery = select user_pass from users where user_name = ?
#取得Roles資料
jdbcRealm.userRolesQuery = select role_name from user_roles where user_name = ?
#使用JNDI DataSource
dataSource = org.apache.shiro.jndi.JndiObjectFactory
dataSource.resourceName = java:/comp/env/jdbc/EmployeeDB
jdbcRealm.dataSource = $dataSource
securityManager.realms = $jdbcRealm
#-----------------------------------------------------------------------------------------
#Setting RememberMe
rememberMeManager = org.apache.shiro.web.mgt.CookieRememberMeManager
securityManager.rememberMeManager = $rememberMeManager
securityManager.rememberMeManager.cookie.name = remember_me
#設定cookie.maxAge = blah , cookie會無法正常寫入
#securityManager.rememberMeManager.cookie.maxAge = blah
securityManager.rememberMeManager.cookie.domain = testdomain.com
訂閱:
文章 (Atom)