首页>代码>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()); } }

zjjhzjb LV15
4月16日
微信网友_7134912998903808 LV15
2024年9月11日
jiyun2021 LV9
2024年7月15日
FF加菲猫 LV4
2024年2月15日
woshiwo LV3
2024年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日

zjb243665659 LV7
4月16日
zjjhzjb LV15
4月16日
TaoTaot
4月7日
暂无贡献等级
blanknb
3月18日
暂无贡献等级
abdkfksdkf LV16
2月23日
zhihou LV2
2月6日
2602275348 LV12
1月6日
暂无贡献等级
WHY-small LV15
2024年12月28日
清清凉 LV5
2024年10月14日