问题详述:在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错误解决