Shiro中的Rememberme後出現瀏覽器500錯誤

lonecloud發表於2018-05-30

問題詳述:在Shiro中新增Remember me功能後,只要勾選Remember me選項為true的時候,瀏覽器就會跳轉到一個不可達頁面,並且在Chrome中顯示HTTP 500錯誤。

問題追蹤:

1. 設定Shiro的日誌許可權級別為DEBUG

log4j設定

# Default Shiro logging
log4j.logger.org.apache.shiro=DEBUG

2.點選登入按鈕,檢視日誌輸入:

DEBUG - Authentication successful for token [org.apache.shiro.authc.UsernamePasswordToken - admin, rememberMe=true].  Returned account [com.ferelife.emms.sys.ActiveUser@3b907d0f]
DEBUG - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.
DEBUG - Context already contains a session.  Returning.
DEBUG - No SecurityManager available in subject context map.  Falling back to SecurityUtils.getSecurityManager() lookup.
DEBUG - Added HttpServletResponse Cookie [rememberMe=deleteMe; Path=/emms; Max-Age=0; Expires=Tue, 29-May-2018 08:45:08 GMT]
DEBUG - Added HttpServletResponse Cookie [rememberMe=aG7QqBPwS+FLAqZYwbdmwSpBD39s3OXjikv8iLYQ2NnKP9pXp6HDF2KkVsXtJF/1LlKFbm5sxoXdyMPycyU3pZKHXd6sznZaCvOL5b+wf88f7Rmwnl/3gUAWs2deu2SjHhXzF0qwiHmrk2eJ16/1uDmOyhvGuMvIhp2Aya4rAWvyBtONhDPvyTtLA8vcuE16OS00FgZGXRCogXS1W/gOKBBXEnrB77vJpzB2opMKqaESUoHFN5J1zNlHvB/3263aJeFWKuRWP5qF6ulzT2yyt14bqfLw0IbYp4/z2lJ2w+cdum8OFukhoEr68WdiM4RCS1NefDeM7EAeNEwZaeYO/Vsv9iGzYHGkjGECaHtkUcwqhorveqjymm1MMRRLdQ0/G8/93DpGd49124CGlB8OgWLZx4iS6yQwM7j7614DcJBchnrg/2x07tpvNeTGNkK6qbu1DS4to9JBQ4m73yTTpKVtMDD9exiA+WcDJ2gKpjIbVKP4RJntjte1g34hqC5UTg1H1q6/YxXMlDQmD+xTFbiE0zimcwe2/XZEhFaKKfV33E+nFmWx0b+FbbNBqsG04ZIaynjd4CJoKQAHcXtzdwb3v2GMJiuTRid3Ge9C29SWTucS6NMvNDQPtShsxyoqWgM8Iw5hitT9hc3XrX1LskZ2G; Path=/emms; Max-Age=2592000; Expires=Fri, 29-Jun-2018 08:45:08 GMT; HttpOnly]

  後出現cookie沒有下面的shiro輸入,至此懷疑cookies大小限制導致瀏覽器頁面不可達,

 查閱資料得到

https://blog.csdn.net/proglovercn/article/details/45514705

chrome中cookies大小限制在4Kb,由於在Remember me中將User通過base64加密後,大小大於4KB,導致cookies不能正常設定到瀏覽器中,導致其跳轉失敗

問題程式碼追溯:

在UserRleam中的protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException 方法中查詢了選單相關的許可權,並將該許可權設定到了User物件中,從而導致User物件的大小持續上升,從而導致Remember編碼後的物件大於4Kb從而無法進行cookies設定值,從而跳轉失敗。

問題解決:

將User設定選單以及相關操作放置到登入方法中,將如上程式碼移動到User登入方法中即可解決問題,此次,該500錯誤解決

 

相關文章