标题:基于SpringBoot+Shiro的权限管理实现
来源:成都大学信息工程与科学学院,成都,610100
关键字:Shiro 框架;SpringBoot 框架;权限管理
xml <! --集成shiro--> <dependency> <group|d> org.apache.shiro </group|d> <artifact|d> shiro-spring </artifact|d> <version> 1.4.0 </version> </dependency>
@Component
public class MyShiroUserRealm extends AuthorizingRealm {
@Autowired
UserServiceImpl userService;
/**
* 用于授权
*
* @param principa|s
* @return 授权信息
*/
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
UserInforMation userInfo = (UserInforMation) principals.getPrimaryPrincipal();
//用户权限列表
Set<String> userPermsSet = userService.getUserPermissions(userInfo);
SimpleAuthorizationInfo authorizationInfo = new SimpleAuthorizationInfo();
authorizationInfo.setStringPermissions(userPermsSet);
return info;
}
/**
* 用于认证
*
* @param token
* @return 认证信息
* @throws AuthenticationException
*/
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
//用户信息获取
String userNameInput = (String) token.getPrincipal();
String passwordInput = new String((char[]) token.getCredentials());
//查询用户信息
UserInforMation user = userService.findld(userNameInput);
//用户不存在
if (user == null) {
throw new UnknownAccountException("用户账号不存在! ");
}
//密码错误
if (!passwordInput.equals(user.getPassword())) {
throw new IncorrectCredentialsException("账号用户名或者密码错误! ");
}
//账号被注销
if (user.getState().equals("0")) {
throw new LockedAccountException("账户已被注销! ");
}
System.out.println("用户登陆成功! ");
SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user, user.getPassword(), user.getName());
return info;
}
}
《基于SpringBoot+Shiro的权限管理实现》论文笔记
原文:https://www.cnblogs.com/clamye/p/12045432.html