Shiro错误之Org.apache.shiro.utilにバインドされている、呼び出し元のコードにアクセスできるSecurityManagerがありません

促す: 

org.apache.shiro.util.ThreadContextにバインドされているか、vm静的シングルトンとしてバインドされているSecurityManagerが呼び出し元のコードにアクセスできません。

つまり、まだログインしていないため、現在ログインしている人の情報を提供することはできません

具体的なエラーメッセージは次のとおりです。

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]

分析プロセス:

エラーがスローされた場所を見つけます:org.apache.shiro.SecurityUtils.getSecurityManager(SecurityUtils.java:123) 

SecurityUtils

デバッグにより、現在のスレッドがSecurityManagerを作成していないことが判明したため、問題は次のとおりです。要求は受信されましたが、SecurityManagerが初期化されていません。

初期化がないのはなぜですか?正しくログインしていないためです。

ログインメソッドがsubject.login(usernamePasswordToken)と正しく呼び出された後でのみ、対応するサブジェクト情報が存在します。

したがって/ loginインターフェイスを呼び出す前に、ShiroからSecurityUtils.getSubject()を呼び出して件名情報除外する必要があります

ここでエラーコードを確認してください。作成したコードがエラーを報告している場所: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/:?]

この場所では、ログインインターフェイスを呼び出す前にSecurityUtils.getSubject()を呼び出さないようにし、修正後に問題を解決します。

おすすめ

転載: blog.csdn.net/Mint6/article/details/104346675