Shiro错误之No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util

prompt: 

No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton.

This means: you have not logged in yet, so I cannot provide you with the information of the currently logged in person .

The specific error message is as follows:

20:43:04.495 ERROR org.apache.juli.logging.DirectJDKLog 175 log - Servlet.service() for servlet [dispatcherServlet] threw exception 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.
	at org.apache.shiro.SecurityUtils.getSecurityManager(SecurityUtils.java:123) ~[shiro-core-1.4.2.jar:1.4.2]
	at org.apache.shiro.subject.Subject$Builder.<init>(Subject.java:626) ~[shiro-core-1.4.2.jar:1.4.2]
	at org.apache.shiro.SecurityUtils.getSubject(SecurityUtils.java:56) ~[shiro-core-1.4.2.jar:1.4.2]

Analysis process:

Find the location where the error is thrown : at org.apache.shiro.SecurityUtils.getSecurityManager(SecurityUtils.java:123) 

SecurityUtils

Debug found that the current thread did not create a SecurityManager, so the problem is: the request came in, but the SecurityManager was not initialized.

Why is there no initialization? Because you have not logged in correctly.

Only after the login method is correctly called subject.login(usernamePasswordToken) , the corresponding subject information will exist.

So you need to exclude the subject information by calling SecurityUtils.getSubject() from shiro before calling the /login interface .

Check the error code here, the location where the code you wrote is reporting the error: com.fast.admin.interceptor.LoginInterceptor.preHandle(LoginInterceptor.java:37

Caused by: 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.
	at org.apache.shiro.SecurityUtils.getSecurityManager(SecurityUtils.java:123) ~[shiro-core-1.4.2.jar:1.4.2]
	at org.apache.shiro.subject.Subject$Builder.<init>(Subject.java:626) ~[shiro-core-1.4.2.jar:1.4.2]
	at org.apache.shiro.SecurityUtils.getSubject(SecurityUtils.java:56) ~[shiro-core-1.4.2.jar:1.4.2]
	at com.fast.framework.utils.ShiroUtil.getSubjct(ShiroUtil.java:20) ~[classes/:?]
	at com.fast.framework.utils.ShiroUtil.getUser(ShiroUtil.java:33) ~[classes/:?]
	at com.fast.admin.interceptor.LoginInterceptor.preHandle(LoginInterceptor.java:37) ~[classes/:?]

In this place, avoid calling SecurityUtils.getSubject() before calling the login interface , and solve the problem after fixing.

Guess you like

Origin blog.csdn.net/Mint6/article/details/104346675