Commit aef833fb9f619b4b61491e9bc5716100d378b779

Authored by YunaiV
1 parent 39bf9cf5

【代码优化】全局:userId 为空时,直接校验权限不通过

yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/security/core/service/SecurityFrameworkServiceImpl.java
... ... @@ -27,7 +27,11 @@ public class SecurityFrameworkServiceImpl implements SecurityFrameworkService {
27 27  
28 28 @Override
29 29 public boolean hasAnyPermissions(String... permissions) {
30   - return permissionApi.hasAnyPermissions(getLoginUserId(), permissions);
  30 + Long userId = getLoginUserId();
  31 + if (userId == null) {
  32 + return false;
  33 + }
  34 + return permissionApi.hasAnyPermissions(userId, permissions);
31 35 }
32 36  
33 37 @Override
... ... @@ -37,7 +41,11 @@ public class SecurityFrameworkServiceImpl implements SecurityFrameworkService {
37 41  
38 42 @Override
39 43 public boolean hasAnyRoles(String... roles) {
40   - return permissionApi.hasAnyRoles(getLoginUserId(), roles);
  44 + Long userId = getLoginUserId();
  45 + if (userId == null) {
  46 + return false;
  47 + }
  48 + return permissionApi.hasAnyRoles(userId, roles);
41 49 }
42 50  
43 51 @Override
... ...