当前位置:   article > 正文

shiro报错No SecurityManager accessible to the calling code, either bound to the org.apache.shiro

no securitymanager accessible to the calling code, either bound to the org.a

问题

今天在调试代码的时候,报了这么一个错,排查半天,终于找到解决方法,具体报错如下图

No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton.This is an invalid application configuration

  1. 16:29:03.059 [http-nio-80-exec-25] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - [log,175] - Servlet.service() for servlet [dispatcherServlet] threw exception
  2. org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton. This is an invalid application configuration.
  3. at org.apache.shiro.SecurityUtils.getSecurityManager(SecurityUtils.java:123)
  4. at org.apache.shiro.subject.Subject$Builder.<init>(Subject.java:626)
  5. at org.apache.shiro.SecurityUtils.getSubject(SecurityUtils.java:56)
  6. at org.apache.shiro.web.servlet.ShiroHttpServletRequest.getSubject(ShiroHttpServletRequest.java:89)
  7. at org.apache.shiro.web.servlet.ShiroHttpServletRequest.getSession(ShiroHttpServletRequest.java:154)
  8. at org.springframework.web.util.WebUtils.getSessionId(WebUtils.java:359)
  9. at org.springframework.web.servlet.FrameworkServlet.publishRequestHandledEvent(FrameworkServlet.java:1145)
  10. at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1023)
  11. at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
  12. at javax.servlet.http.HttpServlet.service(HttpServlet.java:655)
  13. at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
  14. at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
  15. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
  16. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
  17. at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
  18. at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
  19. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
  20. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
  21. at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:102)
  22. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
  23. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
  24. at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:102)
  25. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
  26. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
  27. at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:711)
  28. at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:632)
  29. at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:600)
  30. at org.apache.catalina.core.AsyncContextImpl$AsyncRunnable.run(AsyncContextImpl.java:587)
  31. at org.apache.catalina.core.AsyncContextImpl.doInternalDispatch(AsyncContextImpl.java:353)
  32. at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:194)
  33. at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
  34. at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
  35. at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
  36. at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
  37. at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
  38. at org.apache.catalina.connector.CoyoteAdapter.asyncDispatch(CoyoteAdapter.java:250)
  39. at org.apache.coyote.AbstractProcessor.dispatch(AbstractProcessor.java:241)
  40. at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:59)
  41. at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890)
  42. at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743)
  43. at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
  44. at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
  45. at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
  46. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  47. at java.lang.Thread.run(Thread.java:748)
  48. 16:29:03.060 [http-nio-80-exec-25] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - [log,175] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [java.lang.RuntimeException: Error during asynchronous dispatch] with root cause
  49. org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton. This is an invalid application configuration.
  50. at org.apache.shiro.SecurityUtils.getSecurityManager(SecurityUtils.java:123)
  51. at org.apache.shiro.subject.Subject$Builder.<init>(Subject.java:626)
  52. at org.apache.shiro.SecurityUtils.getSubject(SecurityUtils.java:56)
  53. at org.apache.shiro.web.servlet.ShiroHttpServletRequest.getSubject(ShiroHttpServletRequest.java:89)
  54. at org.apache.shiro.web.servlet.ShiroHttpServletRequest.getSession(ShiroHttpServletRequest.java:154)
  55. at org.springframework.web.util.WebUtils.getSessionId(WebUtils.java:359)
  56. at org.springframework.web.servlet.FrameworkServlet.publishRequestHandledEvent(FrameworkServlet.java:1145)
  57. at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1023)
  58. at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
  59. at javax.servlet.http.HttpServlet.service(HttpServlet.java:655)
  60. at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
  61. at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
  62. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
  63. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
  64. at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
  65. at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
  66. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
  67. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
  68. at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:102)
  69. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
  70. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
  71. at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:102)
  72. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
  73. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
  74. at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:711)
  75. at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:632)
  76. at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:600)
  77. at org.apache.catalina.core.AsyncContextImpl$AsyncRunnable.run(AsyncContextImpl.java:587)
  78. at org.apache.catalina.core.AsyncContextImpl.doInternalDispatch(AsyncContextImpl.java:353)
  79. at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:194)
  80. at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
  81. at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
  82. at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
  83. at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
  84. at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
  85. at org.apache.catalina.connector.CoyoteAdapter.asyncDispatch(CoyoteAdapter.java:250)
  86. at org.apache.coyote.AbstractProcessor.dispatch(AbstractProcessor.java:241)
  87. at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:59)
  88. at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890)
  89. at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743)
  90. at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
  91. at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
  92. at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
  93. at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  94. at java.lang.Thread.run(Thread.java:748)

问题解析

是因为Apache Shiro无法找到SecurityManager。在Apache Shiro中,SecurityManager是中心安全控制器,所有安全相关的操作都会与它交互。这个错误可能的原因是没有正确地设置或者初始化Shiro的SecurityManager。

解决方案

在调用接口处添加以下代码(初始化一下)

  1. DefaultSecurityManager securityManager = new DefaultSecurityManager();
  2. SecurityUtils.setSecurityManager(securityManager);

问题要是解决了,记得点个赞

 如果小伙伴们有什么疑问,欢迎下面评论。欢迎指正。如还有什么不懂的加我 QQ:517861659

如果没有及时回复,可以点我先问问AI机器人https://chatgpt.byabstudio.com/login?code=202307011314

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/534001
推荐阅读
相关标签
  

闽ICP备14008679号