@IocBean
public class UserRealm extends AuthorizingRealm{
static final Log logging = Logs.get();
@Inject
private UserService userService;
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection collection) {
return null;
}
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken toke) {
UsernamePasswordToken token = (UsernamePasswordToken) toke;
String username = token.getUsername().trim();
char[] password = token.getPassword();
//下面空指针
User user = userService.getUserByUsername(username);
SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(username, ByteSource.Util.bytes(user.getPassword()),ByteSource.Util.bytes(user.getSalt()), this.getName());
return info;
}
}
@IocBean
public class UserService {
@Inject
private Dao dao;
public User getUserByUsername(String username){
return dao.fetch(User.class,Cnd.where("username","=",username));
}
}