package com.aaa.config; import com.aaa.entity.User; import com.aaa.service.MenuService; import com.aaa.service.UserService; import org.apache.shiro.SecurityUtils; 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.subject.Subject; import org.apache.shiro.util.ByteSource; import org.springframework.beans.factory.annotation.Autowired; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; public class UserRealm extends AuthorizingRealm { @Autowired private MenuService menuService; /* * 认证 * */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException { //获取的前台username String username = (String) authenticationToken.getPrincipal(); User sysUser = null; try { sysUser = menuService.loginname(username); } catch (Exception e) { e.printStackTrace(); } //判断对象是否有值 if (sysUser == null) { return null; } //密码不需要我们比对,shiro会给我们比对 //对象 //获取前台密码 SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(sysUser, sysUser.getPwd(), ByteSource.Util.bytes(sysUser.getSalt()), getName()); return info; } /* * 授权 * */ @Override protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) { return null; } }
最近下载更多
微信网友_6927932988952576 LV12
3月31日
提灯寻白鹿 LV2
3月27日
qqttuu LV3
3月4日
Hopu2024 LV2
2月22日
xk16675552250 LV33
1月5日
小安同学 LV7
2023年12月30日
阿桐吖 LV2
2023年12月29日
牛Bgtp LV1
2023年12月22日
lllxxxwofhoa LV2
2023年12月10日
2010160433 LV3
2023年12月7日
最近浏览更多
Gzp0822
4月12日
暂无贡献等级
李朝磊 LV18
4月8日
玖零定制问题修复 LV34
4月4日
chenglei1314 LV6
4月2日
微信网友_6927932988952576 LV12
3月31日
微信网友_6928193041338368
3月29日
暂无贡献等级
微信网友_6927790581157888
3月29日
暂无贡献等级
提灯寻白鹿 LV2
3月27日
微信网友_6914427966033920 LV4
3月25日
plecon LV1
3月25日