会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 133800个问题
Python 全系列/第一阶段:AI驱动的Python编程/编程基本概念 15497楼
JAVA 全系列/第五阶段:网页编程和设计/JavaScript语言 15500楼
Python 全系列/第一阶段:AI驱动的Python编程/控制语句 15501楼
Python 全系列/第一阶段:AI驱动的Python编程/Python入门(动画版) 15504楼
Python 全系列/第一阶段:AI驱动的Python编程/编程基本概念 15506楼

这个里面提示没有方法,这个方法应该在那里创建呢?

图片.png

图片.png

图片.png

图片.png

package com.bjsxt.config.shiro;
import com.bjsxt.domain.User;
import com.bjsxt.service.UserService;
import com.bjsxt.vo.ActiverUser;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.util.ByteSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
/**
 * @Author: GHP
 * 自定义 realm 去匹配用户名和密码
 */
public class UserRealm extends AuthorizingRealm {
    @Autowired
    @Lazy
    private UserService userService;
    @Override
    public String getName() {
        return this.getClass().getSimpleName();
    }
    /**
     * 做认证 --就是登陆
     * @param token
     * @return
    45
     * @throws AuthenticationException
     */
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws
            AuthenticationException {
//得到用户登陆名
        String phone=token.getPrincipal().toString();
//根据电话查询用户是否存在
        User user = userService.queryUserByPhone(phone);
        if(null!=user){//说明用户存在,但是密码可能不正确
//组装存放到 reids 里面的对象
            ActiverUser activerUser=new ActiverUser();
            activerUser.setUser(user);
//匹配密码
            SimpleAuthenticationInfo info=new SimpleAuthenticationInfo(
                    activerUser,user.getPassword(),
                    ByteSource.Util.bytes(user.getSalt()),this.getName()
            );
            return info;
        }else{
            return null;//代表用户不存在
        }
    }
    /**
     * 做授权 --登陆成功之后判断用户是否有某个菜单或按钮的权限
     * @param principals
     * @return
     */
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
        ActiverUser activerUser= (ActiverUser) principals.getPrimaryPrincipal();//身份得到的就是上一个方法的返回值的值 第一个参数 activerUser
        SimpleAuthorizationInfo info=new SimpleAuthorizationInfo();
        return info;
    }
}


JAVA 全系列/第二十三阶段:分布式医疗云平台/系统管理前后端开发(旧) 15507楼
JAVA 全系列/第六阶段:JavaWeb开发/Servlet技术详解 15508楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/网络编程(旧) 15510楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637