NutzCN Logo
问答 初始化SysLog时报权限错误
发布于 2716天前 作者 qq_a930202f 1627 次浏览 复制 上一个帖子 下一个帖子
标签:

在Setup.init里面加入这个后

// 初始化SysLog,触发全局系统日志初始化
	    ioc.get(SlogService.class).log("method", "system", null, "系统启动", false);

报错如下:

-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)
	at org.apache.shiro.subject.Subject$Builder.<init>(Subject.java:627)
	at org.apache.shiro.SecurityUtils.getSubject(SecurityUtils.java:56)

不过插入数据正常

7 回复

贴完整报错日志

017-06-10 22:02:31 [localhost-startStop-1] ERROR net.bj.common.web.Toolkit -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)
	at org.apache.shiro.subject.Subject$Builder.<init>(Subject.java:627)
	at org.apache.shiro.SecurityUtils.getSubject(SecurityUtils.java:56)
	at net.bj.common.web.Toolkit.uid(Toolkit.java:103)
	at net.bj.app.MvcSetup$1.call(MvcSetup.java:49)
	at org.nutz.plugins.slog.service.SlogService.log(SlogService.java:95)
	at net.bj.app.MvcSetup.init(MvcSetup.java:54)
	at org.nutz.mvc.impl.NutLoading.evalSetup(NutLoading.java:277)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:121)
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
	at org.nutz.mvc.NutFilter._init(NutFilter.java:87)
	at org.nutz.mvc.NutFilter.init(NutFilter.java:65)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4700)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5340)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

2017-06-10 22:02:31 DEBUG org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) INSERT INTO t_syslog_201706(t,tg,src,u_id,ip,msg,ct) VALUES(?,?,?,?,?,?,?) 
    |      1 |      2 |                                             3 |  4 |    5 |    6 |                   7 |
    |--------|--------|-----------------------------------------------|----|------|------|---------------------|
    | method | system | org.nutz.plugins.slog.service.SlogService#log | -1 | NULL | 系统启动 | 2017-06-10 22:02:30 |

Toolkit.uid

public static Long uid() {
		Long uid = -1L;
		Object user;
		try {
			user = SecurityUtils.getSubject().getPrincipal();
		} catch (Throwable e) {
			 
			return -1L;
		}
		if (user != null) {
			if (user instanceof User) {
				uid = ((User) user).getId();
			} else if (user instanceof Number) {
				uid = ((Number) user).longValue();
			}
		}
		return uid;
	}

按这个逻辑看,是shiro自己打印报错信息了?不过没影响

不影响运行。不知道slog怎么影响的报错,注释初始化这一行,就不报错

记录一下系统启动,slog会读取用户is,但这个没有用户,所以获取用户id失败

是否能 优化下slog ^ - ^
不想看到报错信息啊

net.bj.common.web.Toolkit 这是你自己的类吧? 判断一下吧

添加回复
请先登陆
回到顶部