From 009ac75229725c5d83f80c6d62357b65a6b11e7b Mon Sep 17 00:00:00 2001
From: 疯狂的狮子Li <15040126243@163.com>
Date: 星期四, 14 十一月 2024 16:57:10 +0800
Subject: [PATCH] fix 修复 数据权限多角色与权限标识符共用导致的问题 https://gitee.com/dromara/RuoYi-Vue-Plus/issues/IB4CS4
---
ruoyi-admin/src/main/java/org/dromara/web/controller/AuthController.java | 55 ++++++++++++++++++++++++++++++++++++++++---------------
1 files changed, 40 insertions(+), 15 deletions(-)
diff --git a/ruoyi-admin/src/main/java/org/dromara/web/controller/AuthController.java b/ruoyi-admin/src/main/java/org/dromara/web/controller/AuthController.java
index 43e689b..89fe607 100644
--- a/ruoyi-admin/src/main/java/org/dromara/web/controller/AuthController.java
+++ b/ruoyi-admin/src/main/java/org/dromara/web/controller/AuthController.java
@@ -1,6 +1,8 @@
package org.dromara.web.controller;
import cn.dev33.satoken.annotation.SaIgnore;
+import cn.dev33.satoken.exception.NotLoginException;
+import cn.hutool.core.codec.Base64;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import jakarta.servlet.http.HttpServletRequest;
@@ -10,7 +12,7 @@
import me.zhyd.oauth.model.AuthUser;
import me.zhyd.oauth.request.AuthRequest;
import me.zhyd.oauth.utils.AuthStateUtils;
-import org.dromara.common.core.constant.UserConstants;
+import org.dromara.common.core.constant.SystemConstants;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.domain.model.LoginBody;
import org.dromara.common.core.domain.model.RegisterBody;
@@ -22,9 +24,9 @@
import org.dromara.common.social.config.properties.SocialLoginConfigProperties;
import org.dromara.common.social.config.properties.SocialProperties;
import org.dromara.common.social.utils.SocialUtils;
+import org.dromara.common.sse.dto.SseMessageDto;
+import org.dromara.common.sse.utils.SseMessageUtils;
import org.dromara.common.tenant.helper.TenantHelper;
-import org.dromara.common.websocket.dto.WebSocketMessageDto;
-import org.dromara.common.websocket.utils.WebSocketUtils;
import org.dromara.system.domain.bo.SysTenantBo;
import org.dromara.system.domain.vo.SysClientVo;
import org.dromara.system.domain.vo.SysTenantVo;
@@ -42,7 +44,10 @@
import org.springframework.web.bind.annotation.*;
import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@@ -87,7 +92,7 @@
if (ObjectUtil.isNull(client) || !StringUtils.contains(client.getGrantType(), grantType)) {
log.info("瀹㈡埛绔痠d: {} 璁よ瘉绫诲瀷锛歿} 寮傚父!.", clientId, grantType);
return R.fail(MessageUtils.message("auth.grant.type.error"));
- } else if (!UserConstants.NORMAL.equals(client.getStatus())) {
+ } else if (!SystemConstants.NORMAL.equals(client.getStatus())) {
return R.fail(MessageUtils.message("auth.grant.type.blocked"));
}
// 鏍¢獙绉熸埛
@@ -97,11 +102,11 @@
Long userId = LoginHelper.getUserId();
scheduledExecutorService.schedule(() -> {
- WebSocketMessageDto dto = new WebSocketMessageDto();
+ SseMessageDto dto = new SseMessageDto();
dto.setMessage("娆㈣繋鐧诲綍RuoYi-Vue-Plus鍚庡彴绠$悊绯荤粺");
- dto.setSessionKeys(List.of(userId));
- WebSocketUtils.publishMessage(dto);
- }, 3, TimeUnit.SECONDS);
+ dto.setUserIds(List.of(userId));
+ SseMessageUtils.publishMessage(dto);
+ }, 5, TimeUnit.SECONDS);
return R.ok(loginVo);
}
@@ -112,13 +117,18 @@
* @return 缁撴灉
*/
@GetMapping("/binding/{source}")
- public R<String> authBinding(@PathVariable("source") String source) {
+ public R<String> authBinding(@PathVariable("source") String source,
+ @RequestParam String tenantId, @RequestParam String domain) {
SocialLoginConfigProperties obj = socialProperties.getType().get(source);
if (ObjectUtil.isNull(obj)) {
return R.fail(source + "骞冲彴璐﹀彿鏆備笉鏀寔");
}
AuthRequest authRequest = SocialUtils.getAuthRequest(source, socialProperties);
- String authorizeUrl = authRequest.authorize(AuthStateUtils.createState());
+ Map<String, String> map = new HashMap<>();
+ map.put("tenantId", tenantId);
+ map.put("domain", domain);
+ map.put("state", AuthStateUtils.createState());
+ String authorizeUrl = authRequest.authorize(Base64.encode(JsonUtils.toJsonString(map), StandardCharsets.UTF_8));
return R.ok("鎿嶄綔鎴愬姛", authorizeUrl);
}
@@ -185,8 +195,26 @@
*/
@GetMapping("/tenant/list")
public R<LoginTenantVo> tenantList(HttpServletRequest request) throws Exception {
+ // 杩斿洖瀵硅薄
+ LoginTenantVo result = new LoginTenantVo();
+ boolean enable = TenantHelper.isEnable();
+ result.setTenantEnabled(enable);
+ // 濡傛灉鏈紑鍚鎴疯繖鐩存帴杩斿洖
+ if (!enable) {
+ return R.ok(result);
+ }
+
List<SysTenantVo> tenantList = tenantService.queryList(new SysTenantBo());
List<TenantListVo> voList = MapstructUtils.convert(tenantList, TenantListVo.class);
+ try {
+ // 濡傛灉鍙秴绠¤繑鍥炴墍鏈夌鎴�
+ if (LoginHelper.isSuperAdmin()) {
+ result.setVoList(voList);
+ return R.ok(result);
+ }
+ } catch (NotLoginException ignored) {
+ }
+
// 鑾峰彇鍩熷悕
String host;
String referer = request.getHeader("referer");
@@ -199,11 +227,8 @@
// 鏍规嵁鍩熷悕杩涜绛涢��
List<TenantListVo> list = StreamUtils.filter(voList, vo ->
StringUtils.equals(vo.getDomain(), host));
- // 杩斿洖瀵硅薄
- LoginTenantVo vo = new LoginTenantVo();
- vo.setVoList(CollUtil.isNotEmpty(list) ? list : voList);
- vo.setTenantEnabled(TenantHelper.isEnable());
- return R.ok(vo);
+ result.setVoList(CollUtil.isNotEmpty(list) ? list : voList);
+ return R.ok(result);
}
}
--
Gitblit v1.9.3