From 0f667ba5729624899966794ecf56e510b4e7cb70 Mon Sep 17 00:00:00 2001 From: lihongjie0209 Date: Thu, 24 Aug 2023 21:54:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/lihongjie/coal/aop/OrgScopeAop.java | 46 +++++++++---------- .../coal/entity/base/OrgCommonEntity.java | 2 +- .../cn/lihongjie/coal/filter/AuthFilter.java | 4 +- 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/main/java/cn/lihongjie/coal/aop/OrgScopeAop.java b/src/main/java/cn/lihongjie/coal/aop/OrgScopeAop.java index 99da2d63..09e62d02 100644 --- a/src/main/java/cn/lihongjie/coal/aop/OrgScopeAop.java +++ b/src/main/java/cn/lihongjie/coal/aop/OrgScopeAop.java @@ -15,6 +15,7 @@ import org.aspectj.lang.annotation.Before; import org.aspectj.lang.reflect.MethodSignature; import org.hibernate.Filter; import org.hibernate.Session; +import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; import java.lang.reflect.Method; @@ -22,6 +23,7 @@ import java.lang.reflect.Method; @Aspect @Component @Slf4j +@Order public class OrgScopeAop { @PersistenceContext @@ -42,33 +44,11 @@ public class OrgScopeAop { } if (annotation != null) { - Boolean old = orgScope.get(); - orgScope.set(annotation.value()); - try { - return pjp.proceed(); - } finally { - orgScope.set(old); - - } - - - } else { - - return pjp.proceed(); - } - - - } - - - @Before(value = "@annotation(org.springframework.transaction.annotation.Transactional))") - public void beforeTransactionMethod() { - - - if (orgScope.get() != null) { + boolean enabled = annotation.value(); Session session = entityManager.unwrap(Session.class); - if (orgScope.get()) { + + if (enabled) { if (StringUtils.isEmpty(Ctx.currentUser().getOrganizationId())) { throw new BizException("当前用户未绑定机构, 无法进行机构数据过滤"); @@ -97,6 +77,22 @@ public class OrgScopeAop { } } + + + } + return pjp.proceed(); + + + } + + + @Before(value = "@annotation(org.springframework.transaction.annotation.Transactional))") + public void beforeTransactionMethod() { + + + if (orgScope.get() != null) { + + Session session = entityManager.unwrap(Session.class); } } diff --git a/src/main/java/cn/lihongjie/coal/entity/base/OrgCommonEntity.java b/src/main/java/cn/lihongjie/coal/entity/base/OrgCommonEntity.java index ca8bfd46..df594e27 100644 --- a/src/main/java/cn/lihongjie/coal/entity/base/OrgCommonEntity.java +++ b/src/main/java/cn/lihongjie/coal/entity/base/OrgCommonEntity.java @@ -13,7 +13,7 @@ import org.hibernate.annotations.ParamDef; @Getter @Setter @FilterDef(name = "orgFilter", parameters = @ParamDef(name = "organizationId", type = String.class)) -@Filter(name = "orgFilter", condition = "organizationId = :organizationId") +@Filter(name = "orgFilter", condition = "organization_id = :organizationId") public class OrgCommonEntity extends CommonEntity { diff --git a/src/main/java/cn/lihongjie/coal/filter/AuthFilter.java b/src/main/java/cn/lihongjie/coal/filter/AuthFilter.java index 24cf02ea..c71a0b1f 100644 --- a/src/main/java/cn/lihongjie/coal/filter/AuthFilter.java +++ b/src/main/java/cn/lihongjie/coal/filter/AuthFilter.java @@ -32,7 +32,7 @@ import java.io.IOException; import java.util.Optional; @Component -@Order(Integer.MIN_VALUE + 100) +@Order(0) public class AuthFilter extends OncePerRequestFilter { @Autowired @@ -127,7 +127,7 @@ public class AuthFilter extends OncePerRequestFilter { .filter(x -> StringUtils.equals(x.getId(), resource.get().getId())).findAny(); - if (userResource.isEmpty()) { + if (userResource.isEmpty() && !user.getSysAdmin()) { writeResponse(new BizException("invalidAccess", "当前资源未授权,请联系机构管理员处理。"), response); } else {