mirror of
https://github.com/hs-web/hsweb-framework.git
synced 2026-05-21 07:15:59 +08:00
优化
This commit is contained in:
@@ -13,7 +13,6 @@ public class DataAccessDefinition {
|
||||
|
||||
List<DataAccessTypeDefinition> dataAccessTypes=new ArrayList<>();
|
||||
|
||||
|
||||
public Optional<DataAccessTypeDefinition> getType(String typeId){
|
||||
return dataAccessTypes
|
||||
.stream()
|
||||
|
||||
@@ -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<ResourceActionDefinition> actions=new ArrayList<>();
|
||||
private List<ResourceActionDefinition> actions = new ArrayList<>();
|
||||
|
||||
private List<String> group;
|
||||
|
||||
@Setter(value = AccessLevel.PRIVATE)
|
||||
@JsonIgnore
|
||||
private volatile Set<String> actionIds;
|
||||
|
||||
private Logical logical = Logical.DEFAULT;
|
||||
|
||||
public void addAction(ResourceActionDefinition action){
|
||||
public void addAction(ResourceActionDefinition action) {
|
||||
actions.add(action);
|
||||
}
|
||||
|
||||
public Optional<ResourceActionDefinition> getAction(String action){
|
||||
public Optional<ResourceActionDefinition> 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<ResourceActionDefinition> getDataAccessAction(){
|
||||
@JsonIgnore
|
||||
public List<ResourceActionDefinition> 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<String> actions) {
|
||||
|
||||
@@ -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<ResourceDefinition> getDataAccessResources() {
|
||||
return resources
|
||||
.stream()
|
||||
|
||||
@@ -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<Authentication> authenticate(Mono<AuthenticationRequest> 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
|
||||
|
||||
@@ -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<AuthorizeDefinition> definitions = defaultParser.getAllParsed()
|
||||
.stream().filter(def -> !def.isEmpty())
|
||||
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));
|
||||
|
||||
defaultParser.destroy();
|
||||
// defaultParser.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<EnumDict> 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));
|
||||
|
||||
Reference in New Issue
Block a user