diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/define/DataAccessDefinition.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/define/DataAccessDefinition.java index 848527a9d..3b6a4b2b6 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/define/DataAccessDefinition.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/define/DataAccessDefinition.java @@ -13,7 +13,6 @@ public class DataAccessDefinition { List dataAccessTypes=new ArrayList<>(); - public Optional getType(String typeId){ return dataAccessTypes .stream() diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/define/ResourceDefinition.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/define/ResourceDefinition.java index 44a6a2dcc..e38d7028a 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/define/ResourceDefinition.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/define/ResourceDefinition.java @@ -1,5 +1,6 @@ package org.hswebframework.web.authorization.define; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; @@ -18,22 +19,23 @@ public class ResourceDefinition { private String description; - private List actions=new ArrayList<>(); + private List actions = new ArrayList<>(); private List group; @Setter(value = AccessLevel.PRIVATE) + @JsonIgnore private volatile Set actionIds; private Logical logical = Logical.DEFAULT; - public void addAction(ResourceActionDefinition action){ + public void addAction(ResourceActionDefinition action) { actions.add(action); } - public Optional getAction(String action){ + public Optional getAction(String action) { return actions.stream() - .filter(act->act.getId().equalsIgnoreCase(action)) + .filter(act -> act.getId().equalsIgnoreCase(action)) .findAny(); } @@ -47,15 +49,16 @@ public class ResourceDefinition { return actionIds; } - public List getDataAccessAction(){ + @JsonIgnore + public List getDataAccessAction() { return actions.stream() - .filter(act->act.getDataAccess()!=null) + .filter(act -> CollectionUtils.isNotEmpty(act.getDataAccess().getDataAccessTypes())) .collect(Collectors.toList()); } - public boolean hasDataAccessAction(){ + public boolean hasDataAccessAction() { return actions.stream() - .anyMatch(act->act.getDataAccess()!=null); + .anyMatch(act -> CollectionUtils.isNotEmpty(act.getDataAccess().getDataAccessTypes())); } public boolean hasAction(Collection actions) { diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/define/ResourcesDefinition.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/define/ResourcesDefinition.java index f130c8191..2c0e48ed3 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/define/ResourcesDefinition.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/define/ResourcesDefinition.java @@ -1,5 +1,6 @@ package org.hswebframework.web.authorization.define; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Getter; import lombok.Setter; import org.apache.commons.collections.CollectionUtils; @@ -40,6 +41,7 @@ public class ResourcesDefinition { .findAny(); } + @JsonIgnore public List getDataAccessResources() { return resources .stream() diff --git a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/simple/CompositeReactiveAuthenticationManager.java b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/simple/CompositeReactiveAuthenticationManager.java index 68f61f2dc..d48ea6429 100644 --- a/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/simple/CompositeReactiveAuthenticationManager.java +++ b/hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/simple/CompositeReactiveAuthenticationManager.java @@ -2,12 +2,12 @@ package org.hswebframework.web.authorization.simple; import lombok.AllArgsConstructor; import org.hswebframework.web.authorization.*; -import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.util.List; import java.util.function.Function; +import java.util.stream.Collectors; @AllArgsConstructor public class CompositeReactiveAuthenticationManager implements ReactiveAuthenticationManager { @@ -16,17 +16,14 @@ public class CompositeReactiveAuthenticationManager implements ReactiveAuthentic @Override public Mono authenticate(Mono request) { - return Flux - .fromStream(providers.stream() - .map(manager -> manager - .authenticate(request) - .onErrorResume((err) -> { - return Mono.empty(); - }) - )) - .flatMap(Function.identity()) - .reduceWith(SimpleAuthentication::of, Authentication::merge) - .filter(a -> a.getUser() != null); + return Flux.concat(providers.stream() + .map(manager -> manager + .authenticate(request) + .onErrorResume((err) -> { + return Mono.empty(); + })).collect(Collectors.toList())) + .take(1) + .next(); } @Override diff --git a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/aop/AopAuthorizingController.java b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/aop/AopAuthorizingController.java index e112ea9a5..10772ccaa 100644 --- a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/aop/AopAuthorizingController.java +++ b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/aop/AopAuthorizingController.java @@ -43,7 +43,7 @@ public class AopAuthorizingController extends StaticMethodMatcherPointcutAdvisor @Autowired private AopMethodAuthorizeDefinitionParser aopMethodAuthorizeDefinitionParser; - private DefaultAopMethodAuthorizeDefinitionParser defaultParser = new DefaultAopMethodAuthorizeDefinitionParser(); +// private DefaultAopMethodAuthorizeDefinitionParser defaultParser = new DefaultAopMethodAuthorizeDefinitionParser(); private boolean autoParse = false; @@ -209,7 +209,7 @@ public class AopAuthorizingController extends StaticMethodMatcherPointcutAdvisor || AnnotationUtils.findAnnotation(aClass, method, Authorize.class) != null; if (support && autoParse) { - defaultParser.parse(aClass, method); + aopMethodAuthorizeDefinitionParser.parse(aClass, method); } return support; } @@ -217,13 +217,14 @@ public class AopAuthorizingController extends StaticMethodMatcherPointcutAdvisor @Override public void run(String... args) throws Exception { if (autoParse) { - List definitions = defaultParser.getAllParsed() - .stream().filter(def -> !def.isEmpty()) + List definitions = aopMethodAuthorizeDefinitionParser.getAllParsed() + .stream() + .filter(def -> !def.isEmpty()) .collect(Collectors.toList()); log.info("publish AuthorizeDefinitionInitializedEvent,definition size:{}", definitions.size()); eventPublisher.publishEvent(new AuthorizeDefinitionInitializedEvent(definitions)); - defaultParser.destroy(); + // defaultParser.destroy(); } } diff --git a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/define/DefaultBasicAuthorizeDefinition.java b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/define/DefaultBasicAuthorizeDefinition.java index d9178a16e..6eaf28a29 100644 --- a/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/define/DefaultBasicAuthorizeDefinition.java +++ b/hsweb-authorization/hsweb-authorization-basic/src/main/java/org/hswebframework/web/authorization/basic/define/DefaultBasicAuthorizeDefinition.java @@ -1,5 +1,6 @@ package org.hswebframework.web.authorization.basic.define; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.*; import org.hswebframework.web.authorization.annotation.*; import org.hswebframework.web.authorization.define.*; @@ -24,8 +25,11 @@ import java.util.stream.Collectors; @ToString public class DefaultBasicAuthorizeDefinition implements AopAuthorizeDefinition { + @JsonIgnore private Class targetClass; + + @JsonIgnore private Method targetMethod; private ResourcesDefinition resources = new ResourcesDefinition(); diff --git a/hsweb-core/src/test/java/org/hswebframework/web/dict/EnumDictTest.java b/hsweb-core/src/test/java/org/hswebframework/web/dict/EnumDictTest.java index 1588855b1..590ab4956 100644 --- a/hsweb-core/src/test/java/org/hswebframework/web/dict/EnumDictTest.java +++ b/hsweb-core/src/test/java/org/hswebframework/web/dict/EnumDictTest.java @@ -25,7 +25,7 @@ public class EnumDictTest { String val = mapper.writer().writeValueAsString(new TestEntity()); - + System.out.println(val); TestEntity testEntity = mapper.readerFor(TestEntity.class) .readValue(val); diff --git a/hsweb-core/src/test/java/org/hswebframework/web/dict/TestEnum.java b/hsweb-core/src/test/java/org/hswebframework/web/dict/TestEnum.java index b2069d498..de22bddf4 100644 --- a/hsweb-core/src/test/java/org/hswebframework/web/dict/TestEnum.java +++ b/hsweb-core/src/test/java/org/hswebframework/web/dict/TestEnum.java @@ -1,6 +1,7 @@ package org.hswebframework.web.dict; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/hsweb-starter/src/main/java/org/hswebframework/web/starter/jackson/CustomCodecsAutoConfiguration.java b/hsweb-starter/src/main/java/org/hswebframework/web/starter/jackson/CustomCodecsAutoConfiguration.java index cafa28e7f..03ca4b066 100644 --- a/hsweb-starter/src/main/java/org/hswebframework/web/starter/jackson/CustomCodecsAutoConfiguration.java +++ b/hsweb-starter/src/main/java/org/hswebframework/web/starter/jackson/CustomCodecsAutoConfiguration.java @@ -1,7 +1,10 @@ package org.hswebframework.web.starter.jackson; +import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.module.SimpleModule; import org.hswebframework.web.api.crud.entity.EntityFactory; +import org.hswebframework.web.dict.EnumDict; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; @@ -25,6 +28,12 @@ public class CustomCodecsAutoConfiguration { @ConditionalOnBean(ObjectMapper.class) CodecCustomizer jacksonDecoderCustomizer(EntityFactory entityFactory, ObjectMapper objectMapper) { objectMapper.setTypeFactory(new CustomTypeFactory(entityFactory)); + SimpleModule module = new SimpleModule(); + JsonDeserializer deserialize = new EnumDict.EnumDictJSONDeserializer(); + module.addDeserializer(Enum.class, (JsonDeserializer) deserialize); + objectMapper.registerModule(module); + + return (configurer) -> { CodecConfigurer.DefaultCodecs defaults = configurer.defaultCodecs(); defaults.jackson2JsonDecoder(new CustomJackson2JsonDecoder(objectMapper));