UnavailableSecurityManagerException: No SecurityManager accessible to the calling code, either bound

本文探讨了在操作日志切面中遇到的NoSecurityManagerException,原因可能是Shiro在多线程环境中未正确绑定到SecurityManager。通过手动绑定SecurityManager,解决了线上服务器操作日志保存失败的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Cause: 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.
操作日志切面发生这个问题导致无法保存操作日志;本地测试接口可以保存日志,但是上服务器就不行;
具体原因没弄明白,求教;
个人理解感觉像是因为我的操作日志切面是多线程的,shiro默认只绑定到一个线程上,我在线程里面又用了shiro的操作,所以导致这种情况发生;在本地测试接口没问题是因为我在本地测试只是单用户登录的操作,而上到服务器时是多用户的,所以就导致了问题的发生;有看到的麻烦解答一下是不是这个原因;谢谢!
目前的解决办法是

private static DefaultWebSecurityManager manager = new DefaultWebSecurityManager();



@AfterReturning(value = "within(com.etian.web..*) && @annotation(operationLog)", returning = "object")
    public void insertLog(JoinPoint joinPoint, OperationLog operationLog, Object object) throws Throwable {
        ThreadContext.bind(manager);
        Session session = SecurityUtils.getSubject().getSession();
        String loginIp = (String) session.getAttribute("loginIp");
        ThreadPoolTask task = new ThreadPoolTask(joinPoint,operationLog,object,loginIp);
        rejectWebThreadPool.execute(task);
    }

手动绑定了一下;照目前看是没有再出现过保存不了日志的问题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值