Forráskód Böngészése

优化权限维度

zhou-hao 5 éve
szülő
commit
f35469731c
14 módosított fájl, 183 hozzáadás és 15 törlés
  1. 2 0
      hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/DimensionProvider.java
  2. 1 1
      hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/simple/DefaultAuthorizationAutoConfiguration.java
  3. 7 5
      hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/configuration/EasyormProperties.java
  4. 6 0
      hsweb-system/hsweb-system-authorization/hsweb-system-authorization-api/src/main/java/org/hswebframework/web/system/authorization/api/UserDimensionProvider.java
  5. 3 2
      hsweb-system/hsweb-system-authorization/hsweb-system-authorization-default/src/main/java/org/hswebframework/web/system/authorization/defaults/configuration/AuthorizationServiceAutoConfiguration.java
  6. 6 4
      hsweb-system/hsweb-system-authorization/hsweb-system-authorization-default/src/main/java/org/hswebframework/web/system/authorization/defaults/configuration/AuthorizationWebAutoConfiguration.java
  7. 42 1
      hsweb-system/hsweb-system-authorization/hsweb-system-authorization-default/src/main/java/org/hswebframework/web/system/authorization/defaults/service/DefaultDimensionService.java
  8. 30 0
      hsweb-system/hsweb-system-authorization/hsweb-system-authorization-default/src/main/java/org/hswebframework/web/system/authorization/defaults/service/DynamicDimension.java
  9. 28 0
      hsweb-system/hsweb-system-authorization/hsweb-system-authorization-default/src/main/java/org/hswebframework/web/system/authorization/defaults/service/DynamicDimensionType.java
  10. 3 0
      hsweb-system/hsweb-system-authorization/hsweb-system-authorization-default/src/main/java/org/hswebframework/web/system/authorization/defaults/webflux/WebFluxAuthorizationSettingController.java
  11. 14 1
      hsweb-system/hsweb-system-authorization/hsweb-system-authorization-default/src/main/java/org/hswebframework/web/system/authorization/defaults/webflux/WebFluxDimensionController.java
  12. 34 0
      hsweb-system/hsweb-system-authorization/hsweb-system-authorization-default/src/main/java/org/hswebframework/web/system/authorization/defaults/webflux/WebFluxDimensionUserController.java
  13. 2 0
      hsweb-system/hsweb-system-authorization/hsweb-system-authorization-default/src/test/java/org/hswebframework/web/system/authorization/defaults/service/reactive/DefaultReactiveAuthenticationManagerTest.java
  14. 5 1
      hsweb-system/hsweb-system-authorization/hsweb-system-authorization-default/src/test/java/org/hswebframework/web/system/authorization/defaults/service/reactive/ReactiveTestApplication.java

+ 2 - 0
hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/DimensionProvider.java

@@ -4,6 +4,8 @@ import reactor.core.publisher.Flux;
 
 public interface DimensionProvider {
 
+    Flux<DimensionType> getAllType();
+
     Flux<Dimension> getDimensionByUserId(String userId);
 
     Flux<String> getUserIdByDimensionId(String dimensionId);

+ 1 - 1
hsweb-authorization/hsweb-authorization-api/src/main/java/org/hswebframework/web/authorization/simple/DefaultAuthorizationAutoConfiguration.java

@@ -41,7 +41,7 @@ public class DefaultAuthorizationAutoConfiguration {
 
     @Bean
     @ConditionalOnMissingBean
-    @ConditionalOnBean(ReactiveAuthenticationManagerProvider.class)
+//    @ConditionalOnBean(ReactiveAuthenticationManagerProvider.class)
     public ReactiveAuthenticationManager reactiveAuthenticationManager(List<ReactiveAuthenticationManagerProvider> providers) {
         return new CompositeReactiveAuthenticationManager(providers);
     }

+ 7 - 5
hsweb-commons/hsweb-commons-crud/src/main/java/org/hswebframework/web/crud/configuration/EasyormProperties.java

@@ -30,6 +30,8 @@ public class EasyormProperties {
 
     private boolean allowAlter = false;
 
+    private boolean allowTypeAlter = true;
+
     private DialectEnum dialect = DialectEnum.h2;
 
     private Class<? extends Dialect> dialectType;
@@ -73,31 +75,31 @@ public class EasyormProperties {
     @Getter
     @AllArgsConstructor
     public enum DialectEnum {
-        mysql(Dialect.MYSQL,"?") {
+        mysql(Dialect.MYSQL, "?") {
             @Override
             public RDBSchemaMetadata createSchema(String name) {
                 return new MysqlSchemaMetadata(name);
             }
         },
-        mssql(Dialect.MSSQL,"@arg") {
+        mssql(Dialect.MSSQL, "@arg") {
             @Override
             public RDBSchemaMetadata createSchema(String name) {
                 return new SqlServerSchemaMetadata(name);
             }
         },
-        oracle(Dialect.ORACLE,"?") {
+        oracle(Dialect.ORACLE, "?") {
             @Override
             public RDBSchemaMetadata createSchema(String name) {
                 return new OracleSchemaMetadata(name);
             }
         },
-        postgres(Dialect.POSTGRES,"$") {
+        postgres(Dialect.POSTGRES, "$") {
             @Override
             public RDBSchemaMetadata createSchema(String name) {
                 return new PostgresqlSchemaMetadata(name);
             }
         },
-        h2(Dialect.H2,"$") {
+        h2(Dialect.H2, "$") {
             @Override
             public RDBSchemaMetadata createSchema(String name) {
                 return new H2SchemaMetadata(name);

+ 6 - 0
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-api/src/main/java/org/hswebframework/web/system/authorization/api/UserDimensionProvider.java

@@ -3,10 +3,16 @@ package org.hswebframework.web.system.authorization.api;
 import org.hswebframework.web.authorization.DefaultDimensionType;
 import org.hswebframework.web.authorization.Dimension;
 import org.hswebframework.web.authorization.DimensionProvider;
+import org.hswebframework.web.authorization.DimensionType;
 import reactor.core.publisher.Flux;
 
 public class UserDimensionProvider implements DimensionProvider {
 
+    @Override
+    public Flux<DimensionType> getAllType() {
+        return Flux.just(DefaultDimensionType.user);
+    }
+
     @Override
     public Flux<Dimension> getDimensionByUserId(String userId) {
         return Flux.just(userId)

+ 3 - 2
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-default/src/main/java/org/hswebframework/web/system/authorization/defaults/configuration/AuthorizationServiceAutoConfiguration.java

@@ -2,17 +2,17 @@ package org.hswebframework.web.system.authorization.defaults.configuration;
 
 import org.hswebframework.ezorm.rdb.mapping.ReactiveRepository;
 import org.hswebframework.web.authorization.ReactiveAuthenticationInitializeService;
-import org.hswebframework.web.authorization.ReactiveAuthenticationManager;
 import org.hswebframework.web.authorization.ReactiveAuthenticationManagerProvider;
+import org.hswebframework.web.authorization.simple.DefaultAuthorizationAutoConfiguration;
 import org.hswebframework.web.system.authorization.api.UserDimensionProvider;
 import org.hswebframework.web.system.authorization.api.service.reactive.ReactiveUserService;
 import org.hswebframework.web.system.authorization.defaults.service.DefaultDimensionService;
 import org.hswebframework.web.system.authorization.defaults.service.DefaultReactiveAuthenticationInitializeService;
 import org.hswebframework.web.system.authorization.defaults.service.DefaultReactiveAuthenticationManager;
 import org.hswebframework.web.system.authorization.defaults.service.DefaultReactiveUserService;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
 import org.springframework.boot.autoconfigure.AutoConfigureBefore;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
@@ -21,6 +21,7 @@ import org.springframework.context.annotation.Configuration;
 public class AuthorizationServiceAutoConfiguration {
 
     @Configuration(proxyBeanMethods = false)
+    @AutoConfigureBefore(DefaultAuthorizationAutoConfiguration.class)
     static class ReactiveAuthorizationServiceAutoConfiguration{
         @ConditionalOnBean(ReactiveRepository.class)
         @Bean

+ 6 - 4
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-default/src/main/java/org/hswebframework/web/system/authorization/defaults/configuration/AuthorizationWebAutoConfiguration.java

@@ -1,9 +1,6 @@
 package org.hswebframework.web.system.authorization.defaults.configuration;
 
-import org.hswebframework.web.system.authorization.defaults.webflux.WebFluxAuthorizationSettingController;
-import org.hswebframework.web.system.authorization.defaults.webflux.WebFluxDimensionController;
-import org.hswebframework.web.system.authorization.defaults.webflux.WebFluxPermissionController;
-import org.hswebframework.web.system.authorization.defaults.webflux.WebFluxUserController;
+import org.hswebframework.web.system.authorization.defaults.webflux.*;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
@@ -36,6 +33,11 @@ public class AuthorizationWebAutoConfiguration {
         public WebFluxUserController webFluxUserController() {
             return new WebFluxUserController();
         }
+
+        @Bean
+        public WebFluxDimensionUserController webFluxDimensionUserController() {
+            return new WebFluxDimensionUserController();
+        }
     }
 
 }

+ 42 - 1
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-default/src/main/java/org/hswebframework/web/system/authorization/defaults/service/DefaultDimensionService.java

@@ -1,16 +1,29 @@
 package org.hswebframework.web.system.authorization.defaults.service;
 
+import org.hswebframework.ezorm.rdb.mapping.ReactiveRepository;
+import org.hswebframework.web.authorization.Dimension;
+import org.hswebframework.web.authorization.DimensionProvider;
+import org.hswebframework.web.authorization.DimensionType;
 import org.hswebframework.web.crud.service.GenericReactiveCrudService;
 import org.hswebframework.web.crud.service.ReactiveTreeSortEntityService;
 import org.hswebframework.web.id.IDGenerator;
 import org.hswebframework.web.system.authorization.api.entity.DimensionEntity;
+import org.hswebframework.web.system.authorization.api.entity.DimensionUserEntity;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.StringUtils;
+import reactor.core.publisher.Flux;
 
 import java.util.List;
+import java.util.function.Function;
+import java.util.stream.Collectors;
 
 public class DefaultDimensionService
         extends GenericReactiveCrudService<DimensionEntity, String>
-        implements ReactiveTreeSortEntityService<DimensionEntity, String> {
+        implements ReactiveTreeSortEntityService<DimensionEntity, String>,
+        DimensionProvider {
+
+    @Autowired
+    private ReactiveRepository<DimensionUserEntity, String> dimensionUserRepository;
 
     @Override
     public IDGenerator<String> getIDGenerator() {
@@ -28,5 +41,33 @@ public class DefaultDimensionService
     }
 
 
+    @Override
+    public Flux<DimensionType> getAllType() {
+        return createQuery()
+                .fetch()
+                .map(DynamicDimensionType::of);
+    }
+
+    @Override
+    public Flux<Dimension> getDimensionByUserId(String userId) {
+        return createQuery().fetch()
+                .map(DynamicDimensionType::of)
+                .collect(Collectors.toMap(DimensionType::getId, Function.identity()))
+                .flatMapMany(typeGrouping -> dimensionUserRepository.createQuery()
+                        .where(DimensionUserEntity::getUserId, userId)
+                        .fetch()
+                        .map(entity -> DynamicDimension.of(entity, typeGrouping.get(entity.getDimensionId()))));
 
+    }
+
+    @Override
+    @SuppressWarnings("all")
+    public Flux<String> getUserIdByDimensionId(String dimensionId) {
+        return dimensionUserRepository
+                .createQuery()
+                .select(DimensionUserEntity::getUserId)
+                .where(DimensionUserEntity::getDimensionId, dimensionId)
+                .fetch()
+                .map(DimensionUserEntity::getUserId);
+    }
 }

+ 30 - 0
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-default/src/main/java/org/hswebframework/web/system/authorization/defaults/service/DynamicDimension.java

@@ -0,0 +1,30 @@
+package org.hswebframework.web.system.authorization.defaults.service;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.hswebframework.web.authorization.Dimension;
+import org.hswebframework.web.authorization.DimensionType;
+import org.hswebframework.web.system.authorization.api.entity.DimensionUserEntity;
+
+import java.util.Map;
+
+@Getter
+@Setter
+public class DynamicDimension implements Dimension {
+
+    private String id;
+    private String name;
+    private DimensionType type;
+    private Map<String, Object> options;
+
+
+    public static DynamicDimension of(DimensionUserEntity entity,
+                                      DimensionType type){
+        DynamicDimension dynamicDimension=new DynamicDimension();
+        dynamicDimension.setId(entity.getDimensionId());
+        dynamicDimension.setName(entity.getDimensionName());
+        dynamicDimension.setType(type);
+        return dynamicDimension;
+
+    }
+}

+ 28 - 0
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-default/src/main/java/org/hswebframework/web/system/authorization/defaults/service/DynamicDimensionType.java

@@ -0,0 +1,28 @@
+package org.hswebframework.web.system.authorization.defaults.service;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.hswebframework.web.authorization.DimensionType;
+import org.hswebframework.web.system.authorization.api.entity.DimensionEntity;
+
+@Getter
+@Setter
+public class DynamicDimensionType implements DimensionType {
+
+    private String id;
+
+    private String name;
+
+    private String parentId;
+
+    private String describe;
+
+    public static DimensionType of(DimensionEntity e) {
+        DynamicDimensionType type = new DynamicDimensionType();
+        type.id = e.getId();
+        type.parentId = e.getParentId();
+        type.name = e.getName();
+        type.describe = e.getDescribe();
+        return type;
+    }
+}

+ 3 - 0
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-default/src/main/java/org/hswebframework/web/system/authorization/defaults/webflux/WebFluxAuthorizationSettingController.java

@@ -23,4 +23,7 @@ public class WebFluxAuthorizationSettingController implements ReactiveCrudContro
     public ReactiveRepository<AuthorizationSettingEntity, String> getRepository() {
         return reactiveRepository;
     }
+
+
+
 }

+ 14 - 1
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-default/src/main/java/org/hswebframework/web/system/authorization/defaults/webflux/WebFluxDimensionController.java

@@ -1,6 +1,8 @@
 package org.hswebframework.web.system.authorization.defaults.webflux;
 
 import org.hswebframework.web.api.crud.entity.QueryParamEntity;
+import org.hswebframework.web.authorization.DimensionProvider;
+import org.hswebframework.web.authorization.DimensionType;
 import org.hswebframework.web.authorization.annotation.Authorize;
 import org.hswebframework.web.authorization.annotation.QueryAction;
 import org.hswebframework.web.authorization.annotation.Resource;
@@ -11,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
+import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 
 import java.util.List;
@@ -18,9 +21,12 @@ import java.util.List;
 @RestController
 @RequestMapping("/dimension")
 @Authorize
-@Resource(id = "dimension",name = "权限维度管理",group = "system")
+@Resource(id = "dimension", name = "权限维度管理", group = "system")
 public class WebFluxDimensionController implements ReactiveServiceCrudController<DimensionEntity, String> {
 
+    @Autowired
+    private List<DimensionProvider> dimensionProviders;
+
     @Autowired
     private DefaultDimensionService defaultDimensionService;
 
@@ -34,4 +40,11 @@ public class WebFluxDimensionController implements ReactiveServiceCrudController
     public DefaultDimensionService getService() {
         return defaultDimensionService;
     }
+
+    @GetMapping("/types")
+    @QueryAction
+    public Flux<DimensionType> findAllType() {
+        return Flux.fromIterable(dimensionProviders)
+                .flatMap(DimensionProvider::getAllType);
+    }
 }

+ 34 - 0
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-default/src/main/java/org/hswebframework/web/system/authorization/defaults/webflux/WebFluxDimensionUserController.java

@@ -0,0 +1,34 @@
+package org.hswebframework.web.system.authorization.defaults.webflux;
+
+import org.hswebframework.ezorm.rdb.mapping.ReactiveRepository;
+import org.hswebframework.web.api.crud.entity.QueryParamEntity;
+import org.hswebframework.web.authorization.annotation.Authorize;
+import org.hswebframework.web.authorization.annotation.QueryAction;
+import org.hswebframework.web.authorization.annotation.Resource;
+import org.hswebframework.web.crud.web.reactive.ReactiveCrudController;
+import org.hswebframework.web.crud.web.reactive.ReactiveServiceCrudController;
+import org.hswebframework.web.system.authorization.api.entity.DimensionEntity;
+import org.hswebframework.web.system.authorization.api.entity.DimensionUserEntity;
+import org.hswebframework.web.system.authorization.defaults.service.DefaultDimensionService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import reactor.core.publisher.Mono;
+
+import java.util.List;
+
+@RestController
+@RequestMapping("/dimension-user")
+@Authorize
+@Resource(id = "dimension",name = "权限维度管理",group = "system")
+public class WebFluxDimensionUserController implements ReactiveCrudController<DimensionUserEntity, String> {
+
+    @Autowired
+    private ReactiveRepository<DimensionUserEntity, String> repository;
+
+    @Override
+    public ReactiveRepository<DimensionUserEntity, String> getRepository() {
+        return repository;
+    }
+}

+ 2 - 0
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-default/src/test/java/org/hswebframework/web/system/authorization/defaults/service/reactive/DefaultReactiveAuthenticationManagerTest.java

@@ -68,6 +68,8 @@ public class DefaultReactiveAuthenticationManagerTest {
                     setting.setActions(Collections.singleton("add"));
                     setting.setDimension(entity.getId());
                     setting.setDimensionName("测试用户");
+                    setting.setSettingTarget("admin");
+                    setting.setSettingTargetName("admin");
                     setting.setState((byte) 1);
                     return setting;
                 })

+ 5 - 1
hsweb-system/hsweb-system-authorization/hsweb-system-authorization-default/src/test/java/org/hswebframework/web/system/authorization/defaults/service/reactive/ReactiveTestApplication.java

@@ -1,5 +1,6 @@
 package org.hswebframework.web.system.authorization.defaults.service.reactive;
 
+import org.hswebframework.web.authorization.simple.DefaultAuthorizationAutoConfiguration;
 import org.hswebframework.web.crud.configuration.JdbcSqlExecutorConfiguration;
 import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -9,7 +10,10 @@ import org.springframework.boot.autoconfigure.transaction.reactive.ReactiveTrans
          //TransactionAutoConfiguration.class,
         JdbcSqlExecutorConfiguration.class
 })
-@ImportAutoConfiguration(ReactiveTransactionAutoConfiguration.class)
+@ImportAutoConfiguration({
+        ReactiveTransactionAutoConfiguration.class,
+        DefaultAuthorizationAutoConfiguration.class
+})
 public class ReactiveTestApplication {