面对下一个问题:我需要从子线程获取当前登录的用户名,为此我使用SecurityContextHolder的MODE_INHERITABLETHREADLOCAL
策略。一切正常,直到用户注销并再次登录。之后MODE_INHERITABLETHREADLOCAL
不起作用。我不知道为什么,并试图找到解决方案。问题是,在从子线程调用的重新登录SecurityContextHolder.getContext().getAuthentication()
之后,返回null
(SecurityContextHolder.getContextHolderStrategy()
返回MODE_INHERITABLETHREADLOCAL
)。
我在security-config.xml中设置了上下文持有者策略
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass" value="org.springframework.security.core.context.SecurityContextHolder"/>
<property name="targetMethod" value="setStrategyName"/>
<property name="arguments"><list><value>MODE_INHERITABLETHREADLOCAL</value></list></property>
</bean>
如果有人能帮助我,我将不胜感激。提前谢谢!