mirror of
https://gitee.com/likeadmin/likeadmin_java.git
synced 2026-06-08 07:03:14 +08:00
修复bug
This commit is contained in:
@@ -3,6 +3,7 @@ package com.mdd.admin;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.mdd.admin.service.admin.IAdminRoleService;
|
||||
import com.mdd.common.aop.NotPower;
|
||||
import com.mdd.common.aop.NotLogin;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
@@ -33,6 +34,9 @@ public class LikeAdminInterceptor implements HandlerInterceptor {
|
||||
@Resource
|
||||
AdminMapper systemAuthAdminMapper;
|
||||
|
||||
@Resource
|
||||
IAdminRoleService iAdminRoleService;
|
||||
|
||||
/**
|
||||
* 前置处理器
|
||||
*
|
||||
@@ -177,6 +181,8 @@ public class LikeAdminInterceptor implements HandlerInterceptor {
|
||||
// 写入线程
|
||||
LikeAdminThreadLocal.put("adminId", id);
|
||||
LikeAdminThreadLocal.put("username", adminUser.getName());
|
||||
String roleIds = StringUtils.join(iAdminRoleService.getRoleIdAttr(Integer.parseInt(String.valueOf(id))), ",");
|
||||
LikeAdminThreadLocal.put("roleIds", roleIds);
|
||||
|
||||
// 权限校验
|
||||
if (!adminUser.getId().equals(1)) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.mdd.admin.config.stp;
|
||||
import cn.dev33.satoken.stp.StpInterface;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.mdd.admin.LikeAdminThreadLocal;
|
||||
import com.mdd.admin.service.admin.IAdminRoleService;
|
||||
import com.mdd.common.entity.system.SystemMenu;
|
||||
import com.mdd.common.entity.system.SystemRoleMenu;
|
||||
import com.mdd.common.mapper.system.SystemMenuMapper;
|
||||
@@ -25,6 +26,9 @@ public class StpInterConfig implements StpInterface {
|
||||
@Resource
|
||||
SystemMenuMapper systemAuthMenuMapper;
|
||||
|
||||
@Resource
|
||||
IAdminRoleService iAdminRoleService;
|
||||
|
||||
/**
|
||||
* 返回一个账号所拥有的权限码集合
|
||||
*
|
||||
@@ -36,14 +40,13 @@ public class StpInterConfig implements StpInterface {
|
||||
public List<String> getPermissionList(Object loginId, String loginType) {
|
||||
List<Integer> roleIds = LikeAdminThreadLocal.getRoleIds();
|
||||
List<String> perms = new LinkedList<>();
|
||||
|
||||
if (roleIds.isEmpty()) {
|
||||
return perms;
|
||||
}
|
||||
|
||||
List<SystemRoleMenu> permList = systemRoleMenuMapper.selectList(
|
||||
new QueryWrapper<SystemRoleMenu>()
|
||||
.select("id,role_id,menu_id")
|
||||
.select("role_id,menu_id")
|
||||
.in("role_id", roleIds));
|
||||
|
||||
if (permList.isEmpty()) {
|
||||
@@ -60,12 +63,12 @@ public class StpInterConfig implements StpInterface {
|
||||
.select("id,perms")
|
||||
.eq("is_disable", 0)
|
||||
.in("id", menuIds)
|
||||
.in("menu_type", Arrays.asList("C", "A"))
|
||||
.orderByAsc(Arrays.asList("menu_sort", "id")));
|
||||
.in("type", Arrays.asList("C", "A"))
|
||||
.orderByAsc(Arrays.asList("sort", "id")));
|
||||
|
||||
for (SystemMenu item : systemAuthMenus) {
|
||||
if (StringUtils.isNotNull(item.getPerms()) && StringUtils.isNotEmpty(item.getPerms())) {
|
||||
perms.add(item.getPerms().trim());
|
||||
perms.add(item.getPerms().trim().replace("/", ":"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,11 @@ package com.mdd.admin.controller.adminapi.auth;
|
||||
|
||||
import com.mdd.admin.LikeAdminThreadLocal;
|
||||
import com.mdd.admin.service.IIndexService;
|
||||
import com.mdd.admin.service.admin.IAdminRoleService;
|
||||
import com.mdd.admin.service.admin.IAdminService;
|
||||
import com.mdd.admin.vo.auth.AdminMySelfVo;
|
||||
import com.mdd.common.aop.NotLogin;
|
||||
import com.mdd.common.aop.NotPower;
|
||||
import com.mdd.common.core.AjaxResult;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -26,10 +28,17 @@ public class AdminController {
|
||||
@Resource
|
||||
IAdminService iAdminService;
|
||||
|
||||
@Resource
|
||||
IAdminRoleService iAdminRoleService;
|
||||
|
||||
@NotPower
|
||||
@GetMapping("/mySelf")
|
||||
@ApiOperation(value="获取当前管理员信息")
|
||||
public AjaxResult<AdminMySelfVo> mySelf() {
|
||||
List<Integer> roleIds = LikeAdminThreadLocal.getRoleIds();
|
||||
Integer adminId = LikeAdminThreadLocal.getAdminId();
|
||||
|
||||
List<Integer> roleIds = iAdminRoleService.getRoleIdAttr(adminId);
|
||||
|
||||
AdminMySelfVo mySelf = iAdminService.mySelf(LikeAdminThreadLocal.getAdminId(), roleIds);
|
||||
return AjaxResult.success(mySelf);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import com.mdd.admin.service.admin.IAuthService;
|
||||
import com.mdd.admin.vo.system.SystemAuthAdminDetailVo;
|
||||
import com.mdd.common.entity.admin.AdminDept;
|
||||
import com.mdd.common.mapper.admin.AdminDeptMapper;
|
||||
import com.mdd.common.mapper.system.SystemMenuMapper;
|
||||
import com.mdd.common.mapper.system.SystemRoleMenuMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -21,6 +23,13 @@ public class AuthServiceImpl implements IAuthService {
|
||||
|
||||
@Resource
|
||||
IAdminService iAdminService;
|
||||
|
||||
@Resource
|
||||
SystemMenuMapper systemMenuMapper;
|
||||
|
||||
@Resource
|
||||
SystemRoleMenuMapper SystemRoleMenuMapper;
|
||||
|
||||
@Override
|
||||
public List<String> getBtnAuthByRoleId(Integer adminId) {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
@@ -29,7 +38,8 @@ public class AuthServiceImpl implements IAuthService {
|
||||
ret.add("*");
|
||||
return ret;
|
||||
} else {
|
||||
|
||||
List<Integer> menuIds = SystemRoleMenuMapper.getMenuIds(adminId);
|
||||
ret = this.systemMenuMapper.getPerms(menuIds);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -109,7 +109,6 @@ public class SystemLoginServiceImpl implements ISystemLoginService {
|
||||
throw new LoginException(ErrorEnum.FAILED.getCode(), ErrorEnum.LOGIN_DISABLE_ERROR.getMsg());
|
||||
}
|
||||
String md5Pwd = ToolUtils.makePassword(password);
|
||||
System.out.println(md5Pwd);
|
||||
if (!md5Pwd.equals(sysAdmin.getPassword())) {
|
||||
this.recordLoginLog(sysAdmin.getId(), loginsValidate.getAccount(), ErrorEnum.FAILED.getMsg());
|
||||
throw new LoginException(ErrorEnum.FAILED.getCode(), ErrorEnum.LOGIN_ACCOUNT_ERROR.getMsg());
|
||||
@@ -145,7 +144,7 @@ public class SystemLoginServiceImpl implements ISystemLoginService {
|
||||
} catch (Exception e) {
|
||||
Integer adminId = StringUtils.isNotNull(sysAdmin.getId()) ? sysAdmin.getId() : 0;
|
||||
String error = StringUtils.isEmpty(e.getMessage()) ? "未知错误" : e.getMessage();
|
||||
this.recordLoginLog(adminId, loginsValidate.getAccount(), error);
|
||||
// this.recordLoginLog(adminId, loginsValidate.getAccount(), error);
|
||||
throw new OperateException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class SystemMenuServiceImpl implements ISystemMenuService {
|
||||
|
||||
QueryWrapper<SystemMenu> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("type", Arrays.asList("M", "C"));
|
||||
queryWrapper.eq("is_disable", 0);
|
||||
// queryWrapper.eq("is_disable", 0);
|
||||
queryWrapper.orderByDesc("sort");
|
||||
queryWrapper.orderByAsc("id");
|
||||
if (!adminId.equals(1)) {
|
||||
|
||||
@@ -44,7 +44,7 @@ public class SystemRoleMenuServiceImpl implements ISystemRoleMenuService {
|
||||
|
||||
SystemRole systemAuthRole = systemAuthRoleMapper.selectOne(new QueryWrapper<SystemRole>()
|
||||
.in("id", roleIds)
|
||||
.eq("is_disable", 0)
|
||||
// .eq("is_disable", 0)
|
||||
.last("limit 1"));
|
||||
|
||||
if (StringUtils.isNull(systemAuthRole)) {
|
||||
|
||||
Reference in New Issue
Block a user