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;
}
}
最近下载更多
最近浏览更多
khmumuno
10月24日
暂无贡献等级
求学的熊猫 LV11
10月10日
xiao小果 LV13
8月25日
微信网友_7651521897680896
8月22日
暂无贡献等级
康日澜 LV10
8月2日
d3834632 LV2
7月14日
短巷拥猫 LV12
6月18日
潜心小白来到 LV3
6月10日
2225906816
5月26日
暂无贡献等级
zxdfdcfffddssd
5月21日
暂无贡献等级

