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; } }
最近下载更多
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日
lvhongquan LV11
2023年9月19日
yqyqyqyqy LV4
2023年7月23日