nutzsite中用户修改头像之后左侧导航栏头像无法更新,,点击左侧个人信息时头像是新修改的头像,但是导航位置显示默认头像,经调试发现user对象中有个image的对象为null;因此我在SimpleAuthorizingRealm中将doGetAuthenticationInfo方法简单的改了一下,希望下一个版本将这个问题更新一下:
7 回复
修改前代码如下:
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
UsernamePasswordToken upToken = (UsernamePasswordToken) token;
if (Lang.isEmpty(upToken) || Strings.isEmpty(upToken.getUsername())) {
throw Lang.makeThrow(AuthenticationException.class, "Account name is empty");
}
User user = userService.fetch(Cnd.where("login_name","=",upToken.getUsername()));
if (Lang.isEmpty(user)) {
throw Lang.makeThrow(UnknownAccountException.class, "Account [ %s ] not found", upToken.getUsername());
}
if (user.isStatus()) {
throw Lang.makeThrow(LockedAccountException.class, "Account [ %s ] is locked.", upToken.getUsername());
}
SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user,
user.getPassword().toCharArray(), ByteSource.Util.bytes(user.getSalt()), getName());
info.setCredentialsSalt(ByteSource.Util.bytes(user.getSalt()));
// info.
return info;
}
修改后:我自己的代码中我简单改了一下,不知道修改的合理不,希望新版将这个问题处理一下:
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
UsernamePasswordToken upToken = (UsernamePasswordToken) token;
if (Lang.isEmpty(upToken) || Strings.isEmpty(upToken.getUsername())) {
throw Lang.makeThrow(AuthenticationException.class, "Account name is empty");
}
User user = userService.fetch(Cnd.where("login_name","=",upToken.getUsername()));
if (Lang.isEmpty(user)) {
throw Lang.makeThrow(UnknownAccountException.class, "Account [ %s ] not found", upToken.getUsername());
}else{
if(Lang.isEmpty(user.getImage())) {
user = userService.fetchLinks(user, "image");
if (Lang.isEmpty(user)) {
throw Lang.makeThrow(UnknownAccountException.class, "Account [ %s ] not found", upToken.getUsername());
}
}
}
if (user.isStatus()) {
throw Lang.makeThrow(LockedAccountException.class, "Account [ %s ] is locked.", upToken.getUsername());
}
SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user,
user.getPassword().toCharArray(), ByteSource.Util.bytes(user.getSalt()), getName());
info.setCredentialsSalt(ByteSource.Util.bytes(user.getSalt()));
// info.
return info;
}
添加回复
请先登陆