NutzCN Logo
问答 用shiro做登录后,为什么登录会走三遍NutDaoRealm里面的doGetAuthorizationInfo
发布于 3043天前 作者 congratulations1 3200 次浏览 复制 上一个帖子 下一个帖子
标签:

用shiro做登录后,为什么登录时会走三遍NutDaoRealm里面的doGetAuthorizationInfo

2016-08-24 10:02:28,463 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:212) DEBUG - SELECT * FROM t_user  WHERE name=? LIMIT 0, 1 
    |     1 |
    |-------|
    | admin |
  For example:> "SELECT * FROM t_user  WHERE name='admin' LIMIT 0, 1 "
2016-08-24 10:02:28,527 org.apache.shiro.realm.AuthenticatingRealm.getAuthenticationInfo(AuthenticatingRealm.java:569) DEBUG - Looked up AuthenticationInfo [1] from doGetAuthenticationInfo
2016-08-24 10:02:28,527 org.apache.shiro.realm.AuthenticatingRealm.cacheAuthenticationInfoIfPossible(AuthenticatingRealm.java:507) DEBUG - AuthenticationInfo caching is disabled for info [1].  Submitted token: [org.nutz.integration.shiro.CaptchaUsernamePasswordToken - admin, rememberMe=false (127.0.0.1)].
2016-08-24 10:02:28,528 org.apache.shiro.authc.credential.SimpleCredentialsMatcher.equals(SimpleCredentialsMatcher.java:95) DEBUG - Performing credentials equality check for tokenCredentials of type [org.apache.shiro.crypto.hash.SimpleHash and accountCredentials of type [org.apache.shiro.crypto.hash.SimpleHash]
2016-08-24 10:02:28,528 org.apache.shiro.authc.credential.SimpleCredentialsMatcher.equals(SimpleCredentialsMatcher.java:101) DEBUG - Both credentials arguments can be easily converted to byte arrays.  Performing array equals comparison
2016-08-24 10:02:28,528 org.apache.shiro.authc.AbstractAuthenticator.authenticate(AbstractAuthenticator.java:231) DEBUG - Authentication successful for token [org.nutz.integration.shiro.CaptchaUsernamePasswordToken - admin, rememberMe=false (127.0.0.1)].  Returned account [1]
2016-08-24 10:02:28,528 org.apache.shiro.subject.support.DefaultSubjectContext.resolveSecurityManager(DefaultSubjectContext.java:102) DEBUG - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.
2016-08-24 10:02:28,528 org.apache.shiro.mgt.DefaultSecurityManager.resolveSession(DefaultSecurityManager.java:436) DEBUG - Context already contains a session.  Returning.
2016-08-24 10:02:28,528 org.apache.shiro.subject.support.DefaultSubjectContext.resolveSecurityManager(DefaultSubjectContext.java:102) DEBUG - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.
2016-08-24 10:02:28,528 org.apache.shiro.web.servlet.SimpleCookie.addCookieHeader(SimpleCookie.java:226) DEBUG - Added HttpServletResponse Cookie [rememberMe=deleteMe; Path=/ERPCloud; Max-Age=0; Expires=Tue, 23-Aug-2016 02:02:28 GMT]
2016-08-24 10:02:28,529 org.apache.shiro.mgt.AbstractRememberMeManager.onSuccessfulLogin(AbstractRememberMeManager.java:300) DEBUG - AuthenticationToken did not indicate RememberMe is requested.  RememberMe functionality will not be executed for corresponding account.
2016-08-24 10:02:28,543 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:92) DEBUG - Found mapping for [GET] path=/user/toHome : UserAction.toHome(...)
2016-08-24 10:02:28,543 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:145) DEBUG - Get 'userAction'<class com.erpc.base.action.user.UserAction>
2016-08-24 10:02:28,545 org.apache.shiro.realm.AuthorizingRealm.getAuthorizationCacheLazy(AuthorizingRealm.java:234) DEBUG - No authorizationCache instance set.  Checking for a cacheManager...
2016-08-24 10:02:28,546 org.apache.shiro.realm.AuthorizingRealm.getAuthorizationCacheLazy(AuthorizingRealm.java:248) INFO  - No cache or cacheManager properties have been set.  Authorization cache cannot be obtained.
2016-08-24 10:02:31,166 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:212) DEBUG - SELECT * FROM t_user  WHERE id=?
    | 1 |
    |---|
    | 1 |
  For example:> "SELECT * FROM t_user  WHERE id=1"
2016-08-24 10:02:31,212 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:193) DEBUG - SELECT * FROM t_role  WHERE id IN (SELECT role_id FROM t_user_role WHERE u_id=1)
2016-08-24 10:02:31,382 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:193) DEBUG - SELECT * FROM t_permission  WHERE id IN (SELECT permission_id FROM t_role_permission WHERE role_id=1)
2016-08-24 10:02:31,634 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:193) DEBUG - SELECT * FROM t_permission  WHERE id IN (SELECT permission_id FROM t_role_permission WHERE role_id=2)
2016-08-24 10:02:31,767 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:193) DEBUG - SELECT * FROM t_permission  WHERE id IN (SELECT permission_id FROM t_role_permission WHERE role_id=3)
2016-08-24 10:02:31,847 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:193) DEBUG - SELECT * FROM t_permission  WHERE id IN (SELECT permission_id FROM t_role_permission WHERE role_id=4)
2016-08-24 10:02:31,915 org.apache.shiro.realm.AuthorizingRealm.getAuthorizationCacheLazy(AuthorizingRealm.java:234) DEBUG - No authorizationCache instance set.  Checking for a cacheManager...
2016-08-24 10:02:31,915 org.apache.shiro.realm.AuthorizingRealm.getAuthorizationCacheLazy(AuthorizingRealm.java:248) INFO  - No cache or cacheManager properties have been set.  Authorization cache cannot be obtained.
2016-08-24 10:02:32,022 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:212) DEBUG - SELECT * FROM t_user  WHERE id=?
    | 1 |
    |---|
    | 1 |
  For example:> "SELECT * FROM t_user  WHERE id=1"
2016-08-24 10:02:32,089 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:193) DEBUG - SELECT * FROM t_role  WHERE id IN (SELECT role_id FROM t_user_role WHERE u_id=1)
2016-08-24 10:02:32,252 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:193) DEBUG - SELECT * FROM t_permission  WHERE id IN (SELECT permission_id FROM t_role_permission WHERE role_id=1)
2016-08-24 10:02:32,326 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:193) DEBUG - SELECT * FROM t_permission  WHERE id IN (SELECT permission_id FROM t_role_permission WHERE role_id=2)
2016-08-24 10:02:32,411 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:193) DEBUG - SELECT * FROM t_permission  WHERE id IN (SELECT permission_id FROM t_role_permission WHERE role_id=3)
2016-08-24 10:02:32,482 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:193) DEBUG - SELECT * FROM t_permission  WHERE id IN (SELECT permission_id FROM t_role_permission WHERE role_id=4)
2016-08-24 10:02:32,536 org.apache.shiro.realm.AuthorizingRealm.getAuthorizationCacheLazy(AuthorizingRealm.java:234) DEBUG - No authorizationCache instance set.  Checking for a cacheManager...
2016-08-24 10:02:32,536 org.apache.shiro.realm.AuthorizingRealm.getAuthorizationCacheLazy(AuthorizingRealm.java:248) INFO  - No cache or cacheManager properties have been set.  Authorization cache cannot be obtained.
2016-08-24 10:02:32,705 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:212) DEBUG - SELECT * FROM t_user  WHERE id=?
    | 1 |
    |---|
    | 1 |
  For example:> "SELECT * FROM t_user  WHERE id=1"
2016-08-24 10:02:32,752 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:193) DEBUG - SELECT * FROM t_role  WHERE id IN (SELECT role_id FROM t_user_role WHERE u_id=1)
2016-08-24 10:02:32,934 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:193) DEBUG - SELECT * FROM t_permission  WHERE id IN (SELECT permission_id FROM t_role_permission WHERE role_id=1)
2016-08-24 10:02:33,005 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:193) DEBUG - SELECT * FROM t_permission  WHERE id IN (SELECT permission_id FROM t_role_permission WHERE role_id=2)
2016-08-24 10:02:33,106 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:193) DEBUG - SELECT * FROM t_permission  WHERE id IN (SELECT permission_id FROM t_role_permission WHERE role_id=3)
2016-08-24 10:02:33,342 org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:193) DEBUG - SELECT * FROM t_permission  WHERE id IN (SELECT permission_id FROM t_role_permission WHERE role_id=4)
2016-08-24 10:02:33,406 com.erpc.base.mvc.LogTimeProcessor.process(LogTimeProcessor.java:29) DEBUG - [ GET]URI=/ERPCloud/user/toHome 4863ms

5 回复

仔细debug一下doGetAuthorizationInfo的话,你会发现3次调用的原因都不一样.

这个时候, 你需要配shiro-cache了, 如果添加的依赖是shiro-all则已经包含. PS: 不是maven项目的话,需要手动加入ehcache.jar

# 在realm定义之前加入
cacheManager = org.apache.shiro.cache.ehcache.EhCacheManager
#cacheManager.cacheManagerConfigFile=classpath:ehcache.xml
securityManager.cacheManager = $cacheManager

还有点不明白
securityManager.cacheManager = $cacheManager

nutzdao_realm.cacheManager = $cacheManager
的区别,分别代表了什么,望指教

@congratulations1 设置缓存管理器

来自炫酷的 NutzCN

我明白是设置缓存管理器
我是想问securityManager和nutzdao_realm
他俩不都是shiro里的么,什么情况下用nutzdao_realm,什么情况下用securityManager
他俩分别负责什么东西?

添加回复
请先登陆
回到顶部