我只是在学习Apache并面临一个问题。在我在internet中看到的示例中,线程安全的入口点是以下代码:
try {
ThreadContext.bind(subject);
//main code here
} finally {
ThreadContext.unbindSubject();
}但是,根据文档,有以下方法:
静态空洞绑定( SecurityManager securityManager)简化了将应用程序的SecurityManager实例绑定到ThreadContext的方便方法。 简化将主题绑定到ThreadContext的静态无效绑定( subject)方便方法。 静态SecurityManager unbindSecurityManager()方便方法,它简化了从线程中删除应用程序的SecurityManager实例。 静态主题unbindSubject()方便方法,它简化了从线程中删除线程本地主题的过程。
谁能解释一下,什么时候(在什么情况下)我们需要绑定主体和何时SecurityManager?
发布于 2020-05-07 14:41:46
这取决于您的代码正在做什么,大多数情况下您只需要对主题的引用,但是,如果您的自定义代码使用SecurityManager做了一些事情,Shiro也为此提供了一个实用程序。
也就是说,在大多数情况下,您可能希望使用subject.excute(...):https://shiro.apache.org/subject.html#thread-association
DR,除非您有直接使用安全管理器的代码,否则通过subject.execute自动使用线程关联
https://stackoverflow.com/questions/61623552
复制相似问题