在做shiro的登录认证操作时, 应用的认证拦截成功。
功能是用户未登录,访问任何页面都拦截到登录页面。
但是在登录页面执行登录方法时却报出了 org.apache.shiro.UnavailableSecurityManagerException:错误
通过debug看到,代码是在action类的方法中SecurityUtils.getSubject();时抛出异常
调试了很久都没有发现代码和配置文件的错误。
最后发现,在web.xml配置文件中,我把shiro的过滤器写在了struts2的过滤器的下面,把shiro的过滤器写在struts2的过滤器上面就不回报错了。
结论:在读web.xml文件时,是按照从上到下的顺序读取。shiro过滤器要放在struts2过滤器的上面,保证struts2在加载的时候可以加载到shiro。如果写在后面加载不到,那么在action类中调用SecurityUtils.getSubject()方法时
会报出 No SecurityManager accessible to the calling code,错误。