首先贴出realm方法
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
SimpleShiroToken upToken = (SimpleShiroToken) token;
User user = (User) upToken.getPrincipal();
return new SimpleAccount(user.getId(), user.getName(), getName());
}
slogservice里面每次到
if (uid != null && uid instanceof Number)
slog.setUid(((Number)uid).intValue());
的时候直接跳过不执行,debug显示的uid是1啊!
然后我自己重写了方法才好的
public static Callable<Integer> GET_USER_ID = new Callable<Integer>() {
public Integer call() throws Exception {
Integer u;
try {
u = Integer.valueOf(SecurityUtils.getSubject().getPrincipal().toString());
} catch (Throwable e) {
return Integer.valueOf(-1);
}
if (u != null) {
return u;
}
return Integer.valueOf(0);
}
};
public void log(String t, String tag, String source, String msg, boolean async) {
SlogBean slog = c(t, tag, source, msg);
try {
Integer uid = GET_USER_ID.call();
if (uid != null && uid instanceof Number)
slog.setUid(uid);
}
catch (Exception e) {
log.debug("get user id fail", e);
}
if (async)
async(slog);
else
sync(slog);
}