Merge branch 'refs/heads/master' into spring-boot3

# Conflicts:
#	hsweb-authorization/hsweb-authorization-api/pom.xml
#	hsweb-authorization/hsweb-authorization-basic/pom.xml
#	hsweb-authorization/hsweb-authorization-oauth2/pom.xml
#	hsweb-authorization/pom.xml
#	hsweb-commons/hsweb-commons-api/pom.xml
#	hsweb-commons/hsweb-commons-crud/pom.xml
#	hsweb-commons/hsweb-commons-crud/src/test/java/org/hswebframework/web/crud/query/QueryAnalyzerImplTest.java
#	hsweb-commons/pom.xml
#	hsweb-concurrent/hsweb-concurrent-cache/pom.xml
#	hsweb-concurrent/pom.xml
#	hsweb-core/pom.xml
#	hsweb-datasource/hsweb-datasource-api/pom.xml
#	hsweb-datasource/hsweb-datasource-jta/pom.xml
#	hsweb-datasource/hsweb-datasource-web/pom.xml
#	hsweb-datasource/pom.xml
#	hsweb-logging/hsweb-access-logging-aop/pom.xml
#	hsweb-logging/hsweb-access-logging-api/pom.xml
#	hsweb-logging/pom.xml
#	hsweb-starter/pom.xml
#	hsweb-starter/src/main/java/org/hswebframework/web/starter/jackson/CustomJackson2jsonEncoder.java
#	hsweb-system/hsweb-system-authorization/hsweb-system-authorization-api/pom.xml
#	hsweb-system/hsweb-system-authorization/hsweb-system-authorization-default/pom.xml
#	hsweb-system/hsweb-system-authorization/hsweb-system-authorization-oauth2/pom.xml
#	hsweb-system/hsweb-system-authorization/pom.xml
#	hsweb-system/hsweb-system-dictionary/pom.xml
#	hsweb-system/hsweb-system-file/pom.xml
#	hsweb-system/pom.xml
#	pom.xml
This commit is contained in:
zhouhao
2024-08-21 16:02:40 +08:00
6 changed files with 85 additions and 47 deletions

View File

@@ -19,6 +19,7 @@ import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.core.ReactiveAdapterRegistry;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -65,37 +66,37 @@ public class AopAuthorizingController extends StaticMethodMatcherPointcutAdvisor
Supplier<? extends Publisher<?>> invoker) {
return Authentication
.currentReactive()
.switchIfEmpty(Mono.error(UnAuthorizedException::new))
.flatMapMany(auth -> {
context.setAuthentication(auth);
Function<Runnable, Publisher> afterRuner = runnable -> {
MethodInterceptorContext interceptorContext = holder.createParamContext(invoker.get());
context.setParamContext(interceptorContext);
runnable.run();
return (Publisher<?>) interceptorContext.getInvokeResult();
};
if (context.getDefinition().getPhased() != Phased.after) {
authorizingHandler.handRBAC(context);
if (context.getDefinition().getResources().getPhased() != Phased.after) {
authorizingHandler.handleDataAccess(context);
return invoker.get();
} else {
return afterRuner.apply(() -> authorizingHandler.handleDataAccess(context));
}
.currentReactive()
.switchIfEmpty(Mono.error(UnAuthorizedException::new))
.flatMapMany(auth -> {
context.setAuthentication(auth);
Function<Runnable, Publisher> afterRuner = runnable -> {
MethodInterceptorContext interceptorContext = holder.createParamContext(invoker.get());
context.setParamContext(interceptorContext);
runnable.run();
return (Publisher<?>) interceptorContext.getInvokeResult();
};
if (context.getDefinition().getPhased() != Phased.after) {
authorizingHandler.handRBAC(context);
if (context.getDefinition().getResources().getPhased() != Phased.after) {
authorizingHandler.handleDataAccess(context);
return invoker.get();
} else {
if (context.getDefinition().getResources().getPhased() != Phased.after) {
authorizingHandler.handleDataAccess(context);
return invoker.get();
} else {
return afterRuner.apply(() -> {
authorizingHandler.handRBAC(context);
authorizingHandler.handleDataAccess(context);
});
}
return afterRuner.apply(() -> authorizingHandler.handleDataAccess(context));
}
});
} else {
if (context.getDefinition().getResources().getPhased() != Phased.after) {
authorizingHandler.handleDataAccess(context);
return invoker.get();
} else {
return afterRuner.apply(() -> {
authorizingHandler.handRBAC(context);
authorizingHandler.handleDataAccess(context);
});
}
}
});
}
@SneakyThrows
@@ -109,7 +110,9 @@ public class AopAuthorizingController extends StaticMethodMatcherPointcutAdvisor
MethodInterceptorContext paramContext = holder.createParamContext();
AuthorizeDefinition definition = aopMethodAuthorizeDefinitionParser.parse(methodInvocation.getThis().getClass(), methodInvocation.getMethod(), paramContext);
AuthorizeDefinition definition = aopMethodAuthorizeDefinitionParser.parse(methodInvocation
.getThis()
.getClass(), methodInvocation.getMethod(), paramContext);
Object result = null;
boolean isControl = false;
if (null != definition && !definition.isEmpty()) {
@@ -185,8 +188,9 @@ public class AopAuthorizingController extends StaticMethodMatcherPointcutAdvisor
public boolean matches(Method method, Class<?> aClass) {
Authorize authorize;
boolean support = AnnotationUtils.findAnnotation(aClass, Controller.class) != null
|| AnnotationUtils.findAnnotation(aClass, RestController.class) != null
|| ((authorize = AnnotationUtils.findAnnotation(aClass, method, Authorize.class)) != null && !authorize.ignore()
|| AnnotationUtils.findAnnotation(aClass, RestController.class) != null
|| AnnotationUtils.findAnnotation(aClass, RequestMapping.class) != null
|| ((authorize = AnnotationUtils.findAnnotation(aClass, method, Authorize.class)) != null && !authorize.ignore()
);
if (support && autoParse) {
@@ -198,10 +202,11 @@ public class AopAuthorizingController extends StaticMethodMatcherPointcutAdvisor
@Override
public void run(String... args) throws Exception {
if (autoParse) {
List<AuthorizeDefinition> definitions = aopMethodAuthorizeDefinitionParser.getAllParsed()
.stream()
.filter(def -> !def.isEmpty())
.collect(Collectors.toList());
List<AuthorizeDefinition> definitions = aopMethodAuthorizeDefinitionParser
.getAllParsed()
.stream()
.filter(def -> !def.isEmpty())
.collect(Collectors.toList());
log.info("publish AuthorizeDefinitionInitializedEvent,definition size:{}", definitions.size());
eventPublisher.publishEvent(new AuthorizeDefinitionInitializedEvent(definitions));