bug原图

是在shiro配置的自定义的Realm中,查询用户信息是char[]类型转换为String类型的方式错了

原代码

   //认证
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        //1.查询用户信息
        //UsernamePasswordToken userToken=(UsernamePasswordToken)token;
        String loginName =(String) token.getPrincipal();
   //就是下面的一行代码出错了
        String loginPwd =(String) token.getCredentials();
        //2.查询用户的其他信息
        YunUser yunUser = new YunUser();
        yunUser.setUserName(loginName);
        yunUser.setPassWord(loginPwd);

        //使用mybatispluscha查询
        QueryWrapper qw = new QueryWrapper();
        qw.setEntity(yunUser); //mybatis  查询条件类
        YunUser user = yunService.getOne(qw);
        if (null == user) {
            throw  new UnknownAccountException("账号不存在");
        }

        SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user, loginPwd, getName());

        return info;
    }

修改后的代码:

   //认证
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        //1.查询用户信息
        //UsernamePasswordToken userToken=(UsernamePasswordToken)token;
        String loginName =(String) token.getPrincipal();
        String loginPwd =new String((char[]) token.getCredentials());
        //2.查询用户的其他信息
        YunUser yunUser = new YunUser();
        yunUser.setUserName(loginName);
        yunUser.setPassWord(loginPwd);

        //使用mybatispluscha查询
        QueryWrapper qw = new QueryWrapper();
        qw.setEntity(yunUser); //mybatis  查询条件类
        YunUser user = yunService.getOne(qw);
        if (null == user) {
            throw  new UnknownAccountException("账号不存在");
        }

        SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user, loginPwd, getName());

        return info;
    }

Last modification:February 19th, 2020 at 02:47 pm
如果觉得我的文章对你有用,请随意赞赏