首页>代码>spring boot整合freemaker开发医院管理系统>/hospital/src/main/java/com/gbq/hospital/config/shiro/MyShiroRealm.java
package com.gbq.hospital.config.shiro;

import com.alibaba.druid.util.StringUtils;
import com.gbq.hospital.dao.LoginMapper;
import com.gbq.hospital.entity.Login;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;


/**
 * @author aqian666
 */
public class MyShiroRealm extends AuthorizingRealm{

    @Autowired
    private LoginMapper loginMapper;
    @Autowired
    private HttpServletRequest request;

	@Override
	protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        return null;
	}

	@Override
	protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
	    //获取用户信息
	    String username = authenticationToken.getPrincipal().toString();
        String password = new String((char[]) authenticationToken.getCredentials());
        Login user = loginMapper.findByUsername(username);

        //验证登录账号
        if (user == null) {
            throw new UnknownAccountException("用户名不存在");
        }
        //验证密码
        if(!StringUtils.equals(user.getPassword(), password)){
            throw new UnknownAccountException("密码错误,请重新输入");
        }

        //把登录人存进session
        SecurityUtils.getSubject().getSession().setAttribute("currentManager", user);
        return new SimpleAuthenticationInfo(user, password, this.getName());
    }

}
最近下载更多
FF加菲猫  LV4 2月15日
woshiwo  LV3 1月17日
xuyang1991  LV2 2023年12月26日
adaddad  LV2 2023年11月11日
skook7  LV2 2023年8月31日
LYLHYC  LV5 2023年8月2日
五折也挺好的  LV13 2023年7月10日
泓鼎168  LV19 2023年6月30日
jlmarket  LV22 2023年6月16日
mosstianke  LV1 2023年5月10日
最近浏览更多
hmf1989 4月29日
暂无贡献等级
Gzp0822 4月12日
暂无贡献等级
chenglei1314  LV6 4月2日
提灯寻白鹿  LV2 3月27日
together love  LV2 3月21日
阿桐吖  LV2 3月12日
Hopu2024  LV2 2月22日
FF加菲猫  LV4 2月15日
woshiwo  LV3 1月17日
xk16675552250  LV33 1月4日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友