diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7a64e249..61bd050e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,17 +17,25 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - name: Set up JDK 11 - uses: actions/setup-java@v2 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 with: - java-version: '11' distribution: 'adopt' - - name: Cache Maven packages - uses: actions/cache@v3 + java-version: '17' + + - name: Cache local Maven repository + uses: actions/cache@v3.3.1 + env: + cache-name: cache-mvn with: - path: ~/.m2 - key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-m2 + path: ~/.m2/repository + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + - name: Compile env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any diff --git a/.github/workflows/oss-deploy.yml b/.github/workflows/oss-deploy.yml index 5b71dbee..def4c05b 100644 --- a/.github/workflows/oss-deploy.yml +++ b/.github/workflows/oss-deploy.yml @@ -13,18 +13,24 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 - - name: Set up JDK 11 - uses: actions/setup-java@v2 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 with: - java-version: '11' distribution: 'adopt' - cache: maven - - name: Cache Maven packages - uses: actions/cache@v1 + java-version: '17' + + - name: Cache local Maven repository + uses: actions/cache@v3.3.1 + env: + cache-name: cache-mvn with: - path: ~/.m2 - key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-m2 + path: ~/.m2/repository + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- # - name: Build with Maven # run: mvn -B package --file pom.xml @@ -33,9 +39,8 @@ jobs: # run: mvn deploy # env: # GITHUB_TOKEN: ${{ github.token }} # GITHUB_TOKEN is the default env for the password - - name: Import GPG - uses: crazy-max/ghaction-import-gpg@v4.4.0 + uses: crazy-max/ghaction-import-gpg@v5.3.0 with: gpg_private_key: ${{ secrets.MAVEN_GPG_KEY }} passphrase: ${{ secrets.MAVEN_GPG_PASSPHRASE }} diff --git a/.springjavaformatconfig b/.springjavaformatconfig new file mode 100644 index 00000000..e69de29b diff --git a/README.md b/README.md index a0b4e90b..81e48537 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.power4j.fist/fist-kit-dependencies/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.power4j.fist/fist-kit-dependencies) ## 技术栈 - JDK: `11` diff --git a/fist-kit-app/fist-boot-apidoc/src/main/java/com/power4j/fist/boot/apidoc/DocParser.java b/fist-kit-app/fist-boot-apidoc/src/main/java/com/power4j/fist/boot/apidoc/DocParser.java index f89ca35f..675ae99c 100644 --- a/fist-kit-app/fist-boot-apidoc/src/main/java/com/power4j/fist/boot/apidoc/DocParser.java +++ b/fist-kit-app/fist-boot-apidoc/src/main/java/com/power4j/fist/boot/apidoc/DocParser.java @@ -60,8 +60,9 @@ private List parseFromJson(@Nullable String json) throws JsonProcessin } final JsonNode root = objectMapper.readTree(json); - Iterator> pathIter = Optional.ofNullable(root.get(KEY_PATHS)).map(JsonNode::fields) - .orElse(null); + Iterator> pathIter = Optional.ofNullable(root.get(KEY_PATHS)) + .map(JsonNode::fields) + .orElse(null); if (Objects.isNull(pathIter)) { return Collections.emptyList(); } @@ -73,8 +74,9 @@ private List parseFromJson(@Nullable String json) throws JsonProcessin apiModel.setMethod(kv.getKey().toLowerCase()); Optional methodInfo = Optional.ofNullable(kv.getValue()); methodInfo.ifPresent(o -> { - apiModel.setAction(Optional.ofNullable(o.get(KEY_OPERATION_ID)).map(JsonNode::asText) - .orElse(StringPool.EMPTY)); + apiModel.setAction(Optional.ofNullable(o.get(KEY_OPERATION_ID)) + .map(JsonNode::asText) + .orElse(StringPool.EMPTY)); apiModel.setDocTags(Optional.ofNullable(o.get(KEY_TAGS)).map(this::readStrArray).orElse(null)); apiModel.setDescription( Optional.ofNullable(o.get(KEY_SUMMARY)).map(JsonNode::asText).orElse(StringPool.EMPTY)); @@ -82,7 +84,7 @@ private List parseFromJson(@Nullable String json) throws JsonProcessin Optional secureDetails = methodInfo.map(o -> o.get(DocConstant.SECURE_API_DETAILS_EXTENSION)); if (secureDetails.isEmpty()) { secureDetails = methodInfo.map(o -> o.get(SWAGGER_EXTENSION_KEY)) - .map(o -> o.get(DocConstant.SECURE_API_DETAILS_EXTENSION)); + .map(o -> o.get(DocConstant.SECURE_API_DETAILS_EXTENSION)); } if (secureDetails.isEmpty()) { log.info("忽略注册 {} {}", kv.getKey(), path.getKey()); diff --git a/fist-kit-app/fist-boot-apidoc/src/main/java/com/power4j/fist/boot/apidoc/swagger/plugin/ApiTraitOperationPlugin.java b/fist-kit-app/fist-boot-apidoc/src/main/java/com/power4j/fist/boot/apidoc/swagger/plugin/ApiTraitOperationPlugin.java index d9f785f6..ed4d7ec1 100644 --- a/fist-kit-app/fist-boot-apidoc/src/main/java/com/power4j/fist/boot/apidoc/swagger/plugin/ApiTraitOperationPlugin.java +++ b/fist-kit-app/fist-boot-apidoc/src/main/java/com/power4j/fist/boot/apidoc/swagger/plugin/ApiTraitOperationPlugin.java @@ -47,8 +47,10 @@ public class ApiTraitOperationPlugin implements OperationBuilderPlugin { @Override public void apply(OperationContext context) { - context.findAnnotation(ApiTrait.class).map(DocUtil::createDetails).map(this::toObjectVendorExtension) - .ifPresent(extension -> context.operationBuilder().extensions(Collections.singletonList(extension))); + context.findAnnotation(ApiTrait.class) + .map(DocUtil::createDetails) + .map(this::toObjectVendorExtension) + .ifPresent(extension -> context.operationBuilder().extensions(Collections.singletonList(extension))); } diff --git a/fist-kit-app/fist-boot-apidoc/src/main/java/com/power4j/fist/boot/autoconfigure/apidoc/SwaggerDocAutoConfiguration.java b/fist-kit-app/fist-boot-apidoc/src/main/java/com/power4j/fist/boot/autoconfigure/apidoc/SwaggerDocAutoConfiguration.java index abca9255..23806c9f 100644 --- a/fist-kit-app/fist-boot-apidoc/src/main/java/com/power4j/fist/boot/autoconfigure/apidoc/SwaggerDocAutoConfiguration.java +++ b/fist-kit-app/fist-boot-apidoc/src/main/java/com/power4j/fist/boot/autoconfigure/apidoc/SwaggerDocAutoConfiguration.java @@ -61,17 +61,22 @@ public OperationBuilderPlugin apiTraitOperationPlugin() { @Bean public Docket docket() { // FIXME 可配置化 - return new Docket(DocumentationType.OAS_30).apiInfo(apiInfo()).enable(true).securitySchemes(apiKeyList()) - .securityContexts(securityContexts()).select() - .apis(RequestHandlerSelectors.withMethodAnnotation(Operation.class)) - // .apis(RequestHandlerSelectors.basePackage("com.power4j.fist")) - .paths(PathSelectors.any()).build(); + return new Docket(DocumentationType.OAS_30).apiInfo(apiInfo()) + .enable(true) + .securitySchemes(apiKeyList()) + .securityContexts(securityContexts()) + .select() + .apis(RequestHandlerSelectors.withMethodAnnotation(Operation.class)) + // .apis(RequestHandlerSelectors.basePackage("com.power4j.fist")) + .paths(PathSelectors.any()) + .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder().title("FIST 接口文档") - .contact(new Contact("power4j", "https://github.com/power4j", "amNsYXp6QG91dGxvb2suY29t")) - .version("1.0").build(); + .contact(new Contact("power4j", "https://github.com/power4j", "amNsYXp6QG91dGxvb2suY29t")) + .version("1.0") + .build(); } private List apiKeyList() { @@ -80,8 +85,10 @@ private List apiKeyList() { } private List securityContexts() { - SecurityContext securityContext = SecurityContext.builder().securityReferences(defaultAuth()) - .operationSelector(c -> true).build(); + SecurityContext securityContext = SecurityContext.builder() + .securityReferences(defaultAuth()) + .operationSelector(c -> true) + .build(); return Collections.singletonList(securityContext); } diff --git a/fist-kit-app/fist-data/fist-boot-crud-mybatis/src/main/java/com/power4j/fist/boot/autoconfigure/mybatis/MybatisAutoConfiguration.java b/fist-kit-app/fist-data/fist-boot-crud-mybatis/src/main/java/com/power4j/fist/boot/autoconfigure/mybatis/MybatisAutoConfiguration.java index ea9ce38c..3bb0e8ce 100644 --- a/fist-kit-app/fist-data/fist-boot-crud-mybatis/src/main/java/com/power4j/fist/boot/autoconfigure/mybatis/MybatisAutoConfiguration.java +++ b/fist-kit-app/fist-data/fist-boot-crud-mybatis/src/main/java/com/power4j/fist/boot/autoconfigure/mybatis/MybatisAutoConfiguration.java @@ -85,8 +85,8 @@ public AuditFiller auditAll() { @ConditionalOnProperty(prefix = TenantProperties.PROP_PREFIX, name = "enabled", havingValue = "true") public TenantLineInnerInterceptor tenantLineInnerInterceptor() { TenantLineInnerInterceptor innerInterceptor = new TenantLineInnerInterceptor(); - innerInterceptor.setTenantLineHandler( - new DynamicTenantHandler(tenantProperties.getColumn(), tenantProperties.getTables())); + innerInterceptor + .setTenantLineHandler(new DynamicTenantHandler(tenantProperties.getColumn(), tenantProperties.getTables())); return innerInterceptor; } diff --git a/fist-kit-app/fist-data/fist-boot-crud-mybatis/src/main/java/com/power4j/fist/boot/mybaits/crud/repository/BaseRepository.java b/fist-kit-app/fist-data/fist-boot-crud-mybatis/src/main/java/com/power4j/fist/boot/mybaits/crud/repository/BaseRepository.java index 823ad590..d2ef5cee 100644 --- a/fist-kit-app/fist-data/fist-boot-crud-mybatis/src/main/java/com/power4j/fist/boot/mybaits/crud/repository/BaseRepository.java +++ b/fist-kit-app/fist-data/fist-boot-crud-mybatis/src/main/java/com/power4j/fist/boot/mybaits/crud/repository/BaseRepository.java @@ -212,8 +212,9 @@ public long lambdaCount(Eq expr, @Nullable ID exclude) { @Override public long lambdaCount(List> expr, @Nullable ID exclude) { - Map parsed = expr.stream().collect(Collectors - .toMap(o -> lambdaHelper.colToStr(o.getColumn(), true), o -> Objects.requireNonNull(o.getValue()))); + Map parsed = expr.stream() + .collect(Collectors.toMap(o -> lambdaHelper.colToStr(o.getColumn(), true), + o -> Objects.requireNonNull(o.getValue()))); return countByColumns(parsed, exclude); } @@ -239,8 +240,11 @@ Object loadVersionValueById(T entity, TableInfo tableInfo) { if (!tableInfo.havePK()) { throw new UnsupportedOperationException("不支持没有ID字段的实体类型"); } - TableFieldInfo idField = tableInfo.getFieldList().stream() - .filter(o -> tableInfo.getKeyColumn().equals(o.getColumn())).findFirst().orElse(null); + TableFieldInfo idField = tableInfo.getFieldList() + .stream() + .filter(o -> tableInfo.getKeyColumn().equals(o.getColumn())) + .findFirst() + .orElse(null); assert idField != null; Object idValue = getFieldValue(entity, idField.getField()); diff --git a/fist-kit-app/fist-data/fist-boot-crud-mybatis/src/test/java/com/power4j/fist/boot/mybaits/crud/repository/QueryTest.java b/fist-kit-app/fist-data/fist-boot-crud-mybatis/src/test/java/com/power4j/fist/boot/mybaits/crud/repository/QueryTest.java index 279ce418..d9c50e47 100644 --- a/fist-kit-app/fist-data/fist-boot-crud-mybatis/src/test/java/com/power4j/fist/boot/mybaits/crud/repository/QueryTest.java +++ b/fist-kit-app/fist-data/fist-boot-crud-mybatis/src/test/java/com/power4j/fist/boot/mybaits/crud/repository/QueryTest.java @@ -47,7 +47,7 @@ public class QueryTest { long ID90001 = 90001L; List ids = Collections - .unmodifiableList(LongStream.range(ID90001, ID90001 + 5).boxed().collect(Collectors.toList())); + .unmodifiableList(LongStream.range(ID90001, ID90001 + 5).boxed().collect(Collectors.toList())); @Autowired private BookRepository bookRepository; @@ -96,8 +96,8 @@ void findAllBy() { List list2 = bookRepository.findAllBy(wrapper2); Assertions.assertEquals(0, list2.size()); - LambdaQueryWrapper wrapper3 = bookRepository.lambdaWrapper().in(Book::getId, - Arrays.asList(ID90001, ID90001 + 1)); + LambdaQueryWrapper wrapper3 = bookRepository.lambdaWrapper() + .in(Book::getId, Arrays.asList(ID90001, ID90001 + 1)); List list3 = bookRepository.findAllBy(wrapper3); Assertions.assertEquals(2, list3.size()); } diff --git a/fist-kit-app/fist-data/fist-boot-data/src/main/java/com/power4j/fist/boot/web/model/PageDTO.java b/fist-kit-app/fist-data/fist-boot-data/src/main/java/com/power4j/fist/boot/web/model/PageDTO.java new file mode 100644 index 00000000..d151d0c6 --- /dev/null +++ b/fist-kit-app/fist-data/fist-boot-data/src/main/java/com/power4j/fist/boot/web/model/PageDTO.java @@ -0,0 +1,33 @@ +package com.power4j.fist.boot.web.model; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * @author CJ (power4j@outlook.com) + * @since 1.0 + */ +@Data +public class PageDTO implements Serializable { + + private final static long serialVersionUID = 1L; + + @Schema(description = "数据") + private List content; + + @Schema(description = "总行数") + private Integer total; + + @Schema(description = "是否有下一页") + private Boolean hasNext; + + @Schema(description = "页码") + private Integer pageNumber; + + @Schema(description = "页大小") + private Integer pageSize; + +} diff --git a/fist-kit-app/fist-data/fist-boot-data/src/main/java/com/power4j/fist/boot/web/model/PageData.java b/fist-kit-app/fist-data/fist-boot-data/src/main/java/com/power4j/fist/boot/web/model/PageData.java index 092560e2..bde994d7 100644 --- a/fist-kit-app/fist-data/fist-boot-data/src/main/java/com/power4j/fist/boot/web/model/PageData.java +++ b/fist-kit-app/fist-data/fist-boot-data/src/main/java/com/power4j/fist/boot/web/model/PageData.java @@ -68,6 +68,20 @@ public static PageData of(Paged paged) { paged.getPageSize()); } + public static PageData of(PageDTO dto) { + return new PageData(dto.getContent(), dto.getTotal(), dto.getHasNext(), dto.getPageNumber(), dto.getPageSize()); + } + + public static PageDTO toPageDTO(PageData src) { + PageDTO dto = new PageDTO<>(); + dto.setContent(src.getContent()); + dto.setTotal(src.getTotal()); + dto.setHasNext(src.isHasNext()); + dto.setPageNumber(src.getPageNumber()); + dto.setPageSize(src.getPageSize()); + return dto; + } + public PageData(List content, int total, boolean hasNext, Integer pageNumber, Integer pageSize) { this.content = content; this.total = total; diff --git a/fist-kit-app/fist-data/fist-boot-data/src/main/java/com/power4j/fist/data/tenant/InTenantAspect.java b/fist-kit-app/fist-data/fist-boot-data/src/main/java/com/power4j/fist/data/tenant/InTenantAspect.java index 8bf08790..ce4257ab 100644 --- a/fist-kit-app/fist-data/fist-boot-data/src/main/java/com/power4j/fist/data/tenant/InTenantAspect.java +++ b/fist-kit-app/fist-data/fist-boot-data/src/main/java/com/power4j/fist/data/tenant/InTenantAspect.java @@ -16,9 +16,9 @@ package com.power4j.fist.data.tenant; -import com.power4j.fist.boot.common.aop.AopUtil; -import com.power4j.fist.boot.common.spel.MethodParameterResolver; -import com.power4j.fist.boot.common.spel.SpringElUtil; +import com.power4j.fist.support.spring.aop.AopUtil; +import com.power4j.fist.support.spring.spel.MethodParameterResolver; +import com.power4j.fist.support.spring.spel.SpringElUtil; import com.power4j.fist.data.tenant.annotation.InTenant; import com.power4j.fist.data.tenant.isolation.TenantBroker; import lombok.Data; diff --git a/fist-kit-app/fist-data/fist-boot-data/src/main/java/com/power4j/fist/data/tenant/annotation/InTenant.java b/fist-kit-app/fist-data/fist-boot-data/src/main/java/com/power4j/fist/data/tenant/annotation/InTenant.java index 84be4426..8c7539fa 100644 --- a/fist-kit-app/fist-data/fist-boot-data/src/main/java/com/power4j/fist/data/tenant/annotation/InTenant.java +++ b/fist-kit-app/fist-data/fist-boot-data/src/main/java/com/power4j/fist/data/tenant/annotation/InTenant.java @@ -24,6 +24,7 @@ /** * 租户隔离注解,表示在某个租户的上下文中执行,也可用于重新指定租户 + * * @author CJ (power4j@outlook.com) * @date 2021/11/11 * @since 1.0 diff --git a/fist-kit-app/fist-data/fist-boot-data/src/test/java/com/power4j/fist/boot/autoconfigure/data/DataAutoConfigurationTest.java b/fist-kit-app/fist-data/fist-boot-data/src/test/java/com/power4j/fist/boot/autoconfigure/data/DataAutoConfigurationTest.java index 3fc7e4f7..c91d2eff 100644 --- a/fist-kit-app/fist-data/fist-boot-data/src/test/java/com/power4j/fist/boot/autoconfigure/data/DataAutoConfigurationTest.java +++ b/fist-kit-app/fist-data/fist-boot-data/src/test/java/com/power4j/fist/boot/autoconfigure/data/DataAutoConfigurationTest.java @@ -15,7 +15,7 @@ class DataAutoConfigurationTest { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(DataAutoConfiguration.class)); + .withConfiguration(AutoConfigurations.of(DataAutoConfiguration.class)); @Test void shouldCreateDefaultBeans() { diff --git a/fist-kit-app/fist-data/fist-support-data/pom.xml b/fist-kit-app/fist-data/fist-support-data/pom.xml index 76549047..4e4df48a 100644 --- a/fist-kit-app/fist-data/fist-support-data/pom.xml +++ b/fist-kit-app/fist-data/fist-support-data/pom.xml @@ -86,7 +86,6 @@ com.fasterxml.jackson.core jackson-databind - 2.13.4 test diff --git a/fist-kit-app/fist-data/fist-support-data/src/main/java/com/power4j/fist/boot/common/op/OpTemplateBuilder.java b/fist-kit-app/fist-data/fist-support-data/src/main/java/com/power4j/fist/boot/common/op/OpTemplateBuilder.java index e341a424..7e6bb84d 100644 --- a/fist-kit-app/fist-data/fist-support-data/src/main/java/com/power4j/fist/boot/common/op/OpTemplateBuilder.java +++ b/fist-kit-app/fist-data/fist-support-data/src/main/java/com/power4j/fist/boot/common/op/OpTemplateBuilder.java @@ -149,7 +149,7 @@ private String checkoutCurrentId() { private List> prepareHandlerList(List> infoList) { return infoList.stream().map(info -> { OpHandler handler = Optional.ofNullable(info.getHandler()) - .orElseGet(() -> findHandler(info.getHandlerClass())); + .orElseGet(() -> findHandler(info.getHandlerClass())); if (null == handler) { throw new OpTemplateException("No handler of " + info.getHandlerClass()); } diff --git a/fist-kit-app/fist-data/fist-support-data/src/main/java/com/power4j/fist/data/crud/validate/ValidateUtil.java b/fist-kit-app/fist-data/fist-support-data/src/main/java/com/power4j/fist/data/crud/validate/ValidateUtil.java index 1d2aa356..0f3e62ac 100644 --- a/fist-kit-app/fist-data/fist-support-data/src/main/java/com/power4j/fist/data/crud/validate/ValidateUtil.java +++ b/fist-kit-app/fist-data/fist-support-data/src/main/java/com/power4j/fist/data/crud/validate/ValidateUtil.java @@ -54,10 +54,12 @@ private static ResourceBundleMessageSource getMessageSource() { */ public static Set> check(T object, Class... groups) { Locale.setDefault(LocaleContextHolder.getLocale()); - Validator validator = Validation.byDefaultProvider().configure() - .messageInterpolator(new ResourceBundleMessageInterpolator( - new MessageSourceResourceBundleLocator(getMessageSource()))) - .buildValidatorFactory().getValidator(); + Validator validator = Validation.byDefaultProvider() + .configure() + .messageInterpolator( + new ResourceBundleMessageInterpolator(new MessageSourceResourceBundleLocator(getMessageSource()))) + .buildValidatorFactory() + .getValidator(); return validator.validate(object, groups); } diff --git a/fist-kit-app/fist-data/fist-support-data/src/main/java/com/power4j/fist/data/tenant/TenantUtil.java b/fist-kit-app/fist-data/fist-support-data/src/main/java/com/power4j/fist/data/tenant/TenantUtil.java index 13b077eb..a6169707 100644 --- a/fist-kit-app/fist-data/fist-support-data/src/main/java/com/power4j/fist/data/tenant/TenantUtil.java +++ b/fist-kit-app/fist-data/fist-support-data/src/main/java/com/power4j/fist/data/tenant/TenantUtil.java @@ -16,7 +16,7 @@ package com.power4j.fist.data.tenant; -import com.power4j.fist.boot.web.servlet.util.HttpServletRequestUtil; +import com.power4j.fist.support.spring.web.servlet.util.HttpServletRequestUtil; import lombok.experimental.UtilityClass; import javax.servlet.http.HttpServletRequest; @@ -32,7 +32,7 @@ public class TenantUtil { public Optional resolveTenantId(HttpServletRequest request) { return Optional.ofNullable(HttpServletRequestUtil.getHeader(request, TenantConstant.TENANT_ID_HEADER) - .orElse(request.getParameter(TenantConstant.TENANT_ID_PARAMETER))); + .orElse(request.getParameter(TenantConstant.TENANT_ID_PARAMETER))); } } diff --git a/fist-kit-app/fist-data/fist-support-data/src/main/java/com/power4j/fist/data/tree/TreeMaker.java b/fist-kit-app/fist-data/fist-support-data/src/main/java/com/power4j/fist/data/tree/TreeMaker.java index 34de3f20..c3853542 100644 --- a/fist-kit-app/fist-data/fist-support-data/src/main/java/com/power4j/fist/data/tree/TreeMaker.java +++ b/fist-kit-app/fist-data/fist-support-data/src/main/java/com/power4j/fist/data/tree/TreeMaker.java @@ -57,7 +57,7 @@ public class TreeMaker> { */ public static > TreeMaker use(Collection data) { Map sourceData = data.stream() - .collect(Collectors.toMap(Node::getId, Function.identity(), (x, y) -> y, LinkedHashMap::new)); + .collect(Collectors.toMap(Node::getId, Function.identity(), (x, y) -> y, LinkedHashMap::new)); return new TreeMaker<>(sourceData); } @@ -69,11 +69,14 @@ public static > TreeMaker use(Collection dat */ public static TreeMaker> useIdx(Collection> nodes) { Function> treeMapper = id -> TreeNode.of(id, null); - Map parentMap = nodes.stream().filter(o -> (1 == o.getDistance())) - .collect(Collectors.toMap(NodeIdx::getDescendant, NodeIdx::getAncestor)); - Map> data = nodes.stream().filter(o -> (0 == o.getDistance())).map(NodeIdx::getAncestor) - .map(treeMapper) - .collect(Collectors.toMap(TreeNode::getId, Function.identity(), (x, y) -> y, LinkedHashMap::new)); + Map parentMap = nodes.stream() + .filter(o -> (1 == o.getDistance())) + .collect(Collectors.toMap(NodeIdx::getDescendant, NodeIdx::getAncestor)); + Map> data = nodes.stream() + .filter(o -> (0 == o.getDistance())) + .map(NodeIdx::getAncestor) + .map(treeMapper) + .collect(Collectors.toMap(TreeNode::getId, Function.identity(), (x, y) -> y, LinkedHashMap::new)); data.values().forEach(o -> o.setParentId(parentMap.get(o.getId()))); return new TreeMaker<>(data); } diff --git a/fist-kit-app/fist-data/fist-support-data/src/main/java/com/power4j/fist/data/tree/TreeUtil.java b/fist-kit-app/fist-data/fist-support-data/src/main/java/com/power4j/fist/data/tree/TreeUtil.java index 8015cb30..72a033f5 100644 --- a/fist-kit-app/fist-data/fist-support-data/src/main/java/com/power4j/fist/data/tree/TreeUtil.java +++ b/fist-kit-app/fist-data/fist-support-data/src/main/java/com/power4j/fist/data/tree/TreeUtil.java @@ -87,9 +87,9 @@ T findAncestor(Map source, T child, Set skipSet, Function void fetch(Collection source, Collection roots, NodeOp nodeOp) { Map sourceMap = source.stream() - .collect(Collectors.toMap(nodeOp.idGetter, Function.identity(), (x, y) -> y, LinkedHashMap::new)); + .collect(Collectors.toMap(nodeOp.idGetter, Function.identity(), (x, y) -> y, LinkedHashMap::new)); Map rootMap = roots.stream() - .collect(Collectors.toMap(nodeOp.idGetter, Function.identity(), (x, y) -> y, LinkedHashMap::new)); + .collect(Collectors.toMap(nodeOp.idGetter, Function.identity(), (x, y) -> y, LinkedHashMap::new)); fetch(sourceMap, rootMap, nodeOp); } diff --git a/fist-kit-app/fist-data/fist-support-data/src/test/java/com/power4j/fist/data/tree/TreeNodeUtilTest.java b/fist-kit-app/fist-data/fist-support-data/src/test/java/com/power4j/fist/data/tree/TreeNodeUtilTest.java index 91cbe278..c808edad 100644 --- a/fist-kit-app/fist-data/fist-support-data/src/test/java/com/power4j/fist/data/tree/TreeNodeUtilTest.java +++ b/fist-kit-app/fist-data/fist-support-data/src/test/java/com/power4j/fist/data/tree/TreeNodeUtilTest.java @@ -129,8 +129,10 @@ void convert() { lv2.get(0).appendChildren(lv3); TreeNodeUtil.ConvertOp, NodeView> op = TreeNodeUtil.ConvertOp - ., NodeView>builder().objectConvert(o -> new NodeView(o.getId().toString())) - .childSetter(NodeView::addSub).build(); + ., NodeView>builder() + .objectConvert(o -> new NodeView(o.getId().toString())) + .childSetter(NodeView::addSub) + .build(); List convertedLv0 = TreeNodeUtil.convertToList(lv1, op); Assertions.assertEquals(2, convertedLv0.size()); diff --git a/fist-kit-app/fist-security/fist-support-security/pom.xml b/fist-kit-app/fist-security/fist-support-security/pom.xml index 80e8775a..843c8dec 100644 --- a/fist-kit-app/fist-security/fist-support-security/pom.xml +++ b/fist-kit-app/fist-security/fist-support-security/pom.xml @@ -92,7 +92,7 @@ org.bouncycastle bcprov-jdk15to18 - 1.72 + 1.76 test diff --git a/fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/boot/security/context/UserContextHolder.java b/fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/boot/security/context/UserContextHolder.java index e4125170..2763a02c 100644 --- a/fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/boot/security/context/UserContextHolder.java +++ b/fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/boot/security/context/UserContextHolder.java @@ -46,7 +46,7 @@ public static Optional getUser() { public static UserInfo requireUser() { return getUser() - .orElseThrow(() -> new IllegalStateException("Can not offer " + UserInfo.class.getSimpleName())); + .orElseThrow(() -> new IllegalStateException("Can not offer " + UserInfo.class.getSimpleName())); } public static void setUser(@Nullable UserInfo val) { diff --git a/fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/boot/security/inner/DefaultUserCodec.java b/fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/boot/security/inner/DefaultUserCodec.java index 03c8d0d1..ad59ad98 100644 --- a/fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/boot/security/inner/DefaultUserCodec.java +++ b/fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/boot/security/inner/DefaultUserCodec.java @@ -61,8 +61,8 @@ public String encode(UserInfo user) { String json; try { json = objectMapper.writeValueAsString(user); - StrObscurer.EncoderSelector selector = (s, l) -> l.stream().filter(enc -> zipPredicate.test(s)) - .collect(Collectors.toList()); + StrObscurer.EncoderSelector selector = (s, + l) -> l.stream().filter(enc -> zipPredicate.test(s)).collect(Collectors.toList()); return obscurer.obscure(json, selector); } catch (JsonProcessingException | CodecException e) { diff --git a/fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/boot/security/oauth2/DefaultServerBearerTokenResolver.java b/fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/boot/security/oauth2/DefaultServerBearerTokenResolver.java index 274018a4..339fd7da 100644 --- a/fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/boot/security/oauth2/DefaultServerBearerTokenResolver.java +++ b/fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/boot/security/oauth2/DefaultServerBearerTokenResolver.java @@ -1,6 +1,6 @@ package com.power4j.fist.boot.security.oauth2; -import com.power4j.fist.boot.web.reactive.util.ServerHttpRequestUtil; +import com.power4j.fist.support.spring.web.reactive.util.ServerHttpRequestUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; diff --git a/fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/boot/security/oauth2/Oauth2GrantType.java b/fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/boot/security/oauth2/Oauth2GrantType.java index b6150b1b..3c1efb66 100644 --- a/fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/boot/security/oauth2/Oauth2GrantType.java +++ b/fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/boot/security/oauth2/Oauth2GrantType.java @@ -24,6 +24,7 @@ /** * 授权类型 see rfc6749 * section-1.3 + * * @author CJ (power4j@outlook.com) * @date 2021/11/24 * @since 1.0 diff --git a/fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/boot/security/oauth2/Oauth2UserInfoExtractor.java b/fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/boot/security/oauth2/Oauth2UserInfoExtractor.java index 0daf098a..c33e9970 100644 --- a/fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/boot/security/oauth2/Oauth2UserInfoExtractor.java +++ b/fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/boot/security/oauth2/Oauth2UserInfoExtractor.java @@ -47,7 +47,8 @@ public Optional extractAuthUser(@Nullable Map map) { } String clientId = MapUtils.getString(map, KEY_CLIENT_ID); Map userInfoMap = (Map) Optional.of(map) - .map(o -> o.get(SecurityConstant.Auth2.INFO_KEY_USER_INFO)).orElse(null); + .map(o -> o.get(SecurityConstant.Auth2.INFO_KEY_USER_INFO)) + .orElse(null); if (Objects.isNull(userInfoMap)) { log.debug("client authentication :{}", clientId); diff --git a/fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/boot/security/oauth2/server/resource/introspection/DefaultReactiveOpaqueTokenIntrospector.java b/fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/boot/security/oauth2/server/resource/introspection/DefaultReactiveOpaqueTokenIntrospector.java index e15d5c2d..feecf74d 100644 --- a/fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/boot/security/oauth2/server/resource/introspection/DefaultReactiveOpaqueTokenIntrospector.java +++ b/fist-kit-app/fist-security/fist-support-security/src/main/java/com/power4j/fist/boot/security/oauth2/server/resource/introspection/DefaultReactiveOpaqueTokenIntrospector.java @@ -102,15 +102,16 @@ private Mono> adaptToNimbusResponse(ClientResponse responseE // relying solely on the authorization server to validate this token (not checking // 'exp', for example) return responseEntity.bodyToMono(STRING_OBJECT_MAP) - .filter((body) -> (boolean) body.compute(Oauth2TokenIntrospectionClaimNames.ACTIVE, (k, v) -> { - if (v instanceof String) { - return Boolean.parseBoolean((String) v); - } - if (v instanceof Boolean) { - return v; - } - return false; - })).switchIfEmpty(Mono.error(() -> new BadOpaqueTokenException("Provided token isn't active"))); + .filter((body) -> (boolean) body.compute(Oauth2TokenIntrospectionClaimNames.ACTIVE, (k, v) -> { + if (v instanceof String) { + return Boolean.parseBoolean((String) v); + } + if (v instanceof Boolean) { + return v; + } + return false; + })) + .switchIfEmpty(Mono.error(() -> new BadOpaqueTokenException("Provided token isn't active"))); } private Oauth2AuthenticatedPrincipal convertClaimsSet(Map claims) { diff --git a/fist-kit-app/fist-security/fist-support-security/src/test/java/com/power4j/fist/boot/security/inner/DefaultUserCodecTest.groovy b/fist-kit-app/fist-security/fist-support-security/src/test/java/com/power4j/fist/boot/security/inner/DefaultUserCodecTest.groovy index c2346e9a..b4467f6b 100644 --- a/fist-kit-app/fist-security/fist-support-security/src/test/java/com/power4j/fist/boot/security/inner/DefaultUserCodecTest.groovy +++ b/fist-kit-app/fist-security/fist-support-security/src/test/java/com/power4j/fist/boot/security/inner/DefaultUserCodecTest.groovy @@ -85,4 +85,17 @@ class DefaultUserCodecTest extends Specification { then: userInfo.getUsername() == decoded.getUsername() } + + def "Decode"(){ + String value = "+gz H4sIAAAAAAAA/3VUy27bMBD8lYJnE0KvuqWADwGKFqibUxAEG3KtEuKrJGXDCPLvXVK2U4nUTZjZmZ1dUnxnU8TwKFn/dVc+LRhkPQvOJbZjVonxx4wcLjGh+fIgjbLEwAkShKegWW8nrXfMYALWvzOJPt0woRXalN3ZUcXEIYv5Gd/IwGMwKkblbGT9M/FgRBcvscsGXKKmmk8wOI0VaNBOFZiH4B4GrNF1KXjFlT26WzkRd1y7oXYp0U4Kz3WMqrYk1jR1I91Z8oARU22TW6+JjHnaZ20EUtYgStUyXpWWUZpgW1+hZb5CrfN+Ms1TbMYpTBO8NvYgvOlg7PJKb9ueQQNiRunM4ga1QJPs/k4YLndAOIlbFtSScnG6uC5w8QfFuKZAiJn+n6DRMWFbsOkSpzeznPZqUxNR2QEbgegwOIw8qsHiItDkJVSB8n5knnsDrvtebXKLJVdW7WrNHa9beKAL26qfiVoQcNhAGyb0h02m7VKIhmSy2omxIbkSKwndI0Gj4fIenY4X9jI/pgc3BZEfT1JD/hXyjS7P3a+f3/evh8ff+9dvD4c9e/n4+AehQWBLigUAAA=="; + + DefaultUserCodec codec = new DefaultUserCodec() + + when: + UserInfo decoded = codec.decode(value) + + then: + "root" == decoded.getUsername() + 1 == decoded.getUserId() + } } diff --git a/fist-kit-app/fist-security/fist-support-security/src/test/java/com/power4j/fist/boot/security/oauth2/server/resource/introspection/DefaultReactiveOpaqueTokenIntrospectorTest.java b/fist-kit-app/fist-security/fist-support-security/src/test/java/com/power4j/fist/boot/security/oauth2/server/resource/introspection/DefaultReactiveOpaqueTokenIntrospectorTest.java index b2644888..90e8321c 100644 --- a/fist-kit-app/fist-security/fist-support-security/src/test/java/com/power4j/fist/boot/security/oauth2/server/resource/introspection/DefaultReactiveOpaqueTokenIntrospectorTest.java +++ b/fist-kit-app/fist-security/fist-support-security/src/test/java/com/power4j/fist/boot/security/oauth2/server/resource/introspection/DefaultReactiveOpaqueTokenIntrospectorTest.java @@ -117,7 +117,7 @@ public void authenticateWhenBadClientCredentialsThenAuthenticationException() th DefaultReactiveOpaqueTokenIntrospector introspectionClient = new DefaultReactiveOpaqueTokenIntrospector( introspectUri, CLIENT_ID, "wrong"); assertThatExceptionOfType(Oauth2IntrospectionException.class) - .isThrownBy(() -> introspectionClient.introspect("token").block()); + .isThrownBy(() -> introspectionClient.introspect("token").block()); } } @@ -128,8 +128,8 @@ public void authenticateWhenInactiveTokenThenInvalidToken() { DefaultReactiveOpaqueTokenIntrospector introspectionClient = new DefaultReactiveOpaqueTokenIntrospector( INTROSPECTION_URL, webClient); assertThatExceptionOfType(BadOpaqueTokenException.class) - .isThrownBy(() -> introspectionClient.introspect("token").block()) - .withMessage("Provided token isn't active"); + .isThrownBy(() -> introspectionClient.introspect("token").block()) + .withMessage("Provided token isn't active"); } @Test @@ -180,25 +180,25 @@ public void authenticateWhenIntrospectionTokenReturnsInvalidResponseThenInvalidT @Test public void constructorWhenIntrospectionUriIsEmptyThenIllegalArgumentException() { assertThatIllegalArgumentException() - .isThrownBy(() -> new DefaultReactiveOpaqueTokenIntrospector("", CLIENT_ID, CLIENT_SECRET)); + .isThrownBy(() -> new DefaultReactiveOpaqueTokenIntrospector("", CLIENT_ID, CLIENT_SECRET)); } @Test public void constructorWhenClientIdIsEmptyThenIllegalArgumentException() { assertThatIllegalArgumentException() - .isThrownBy(() -> new DefaultReactiveOpaqueTokenIntrospector(INTROSPECTION_URL, "", CLIENT_SECRET)); + .isThrownBy(() -> new DefaultReactiveOpaqueTokenIntrospector(INTROSPECTION_URL, "", CLIENT_SECRET)); } @Test public void constructorWhenClientSecretIsNullThenIllegalArgumentException() { assertThatIllegalArgumentException() - .isThrownBy(() -> new DefaultReactiveOpaqueTokenIntrospector(INTROSPECTION_URL, CLIENT_ID, null)); + .isThrownBy(() -> new DefaultReactiveOpaqueTokenIntrospector(INTROSPECTION_URL, CLIENT_ID, null)); } @Test public void constructorWhenRestOperationsIsNullThenIllegalArgumentException() { assertThatIllegalArgumentException() - .isThrownBy(() -> new DefaultReactiveOpaqueTokenIntrospector(INTROSPECTION_URL, null)); + .isThrownBy(() -> new DefaultReactiveOpaqueTokenIntrospector(INTROSPECTION_URL, null)); } private WebClient mockResponse(String response) { diff --git a/fist-kit-app/fist-web/fist-boot-web-app/pom.xml b/fist-kit-app/fist-web/fist-boot-web-app/pom.xml index 07ae1f19..5002f2a0 100644 --- a/fist-kit-app/fist-web/fist-boot-web-app/pom.xml +++ b/fist-kit-app/fist-web/fist-boot-web-app/pom.xml @@ -68,7 +68,7 @@ org.bouncycastle bcprov-jdk15to18 - 1.72 + 1.76 test diff --git a/fist-kit-app/fist-web/fist-boot-web-app/src/main/java/com/power4j/fist/boot/autoconfigure/common/CommonConfiguration.java b/fist-kit-app/fist-web/fist-boot-web-app/src/main/java/com/power4j/fist/boot/autoconfigure/common/CommonConfiguration.java index c46ff58d..0a33e4e7 100644 --- a/fist-kit-app/fist-web/fist-boot-web-app/src/main/java/com/power4j/fist/boot/autoconfigure/common/CommonConfiguration.java +++ b/fist-kit-app/fist-web/fist-boot-web-app/src/main/java/com/power4j/fist/boot/autoconfigure/common/CommonConfiguration.java @@ -19,7 +19,7 @@ import com.power4j.fist.boot.autoconfigure.i18n.MessageConfiguration; import com.power4j.fist.boot.autoconfigure.mon.AppMonConfiguration; import com.power4j.fist.boot.common.jackson.JacksonConfig; -import com.power4j.fist.boot.util.ApplicationContextHolder; +import com.power4j.fist.support.spring.util.ApplicationContextHolder; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.context.annotation.Import; diff --git a/fist-kit-app/fist-web/fist-boot-web-app/src/main/java/com/power4j/fist/boot/autoconfigure/mon/AppMonConfiguration.java b/fist-kit-app/fist-web/fist-boot-web-app/src/main/java/com/power4j/fist/boot/autoconfigure/mon/AppMonConfiguration.java index 3ab0064f..d3191247 100644 --- a/fist-kit-app/fist-web/fist-boot-web-app/src/main/java/com/power4j/fist/boot/autoconfigure/mon/AppMonConfiguration.java +++ b/fist-kit-app/fist-web/fist-boot-web-app/src/main/java/com/power4j/fist/boot/autoconfigure/mon/AppMonConfiguration.java @@ -29,8 +29,10 @@ import com.power4j.fist.boot.security.core.UserInfoAccessor; import org.aspectj.lang.Aspects; import org.springframework.beans.factory.ObjectProvider; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.MessageSource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -69,12 +71,14 @@ public ExceptionTranslator defaultExceptionTranslator(ObjectProvider userInfoAccessor) { return new ApiLogAspect(new SmartApiDescriptionResolver(), translator, userInfoAccessor.getIfAvailable()); } @Bean + @ConditionalOnBean(ApiLogAspect.class) @ConditionalOnMissingBean(value = ApiLogEvent.class, parameterizedContainer = AbstractEventListener.class) public DefaultApiLogEventListener defaultApiLogEventListener() { return new DefaultApiLogEventListener(); diff --git a/fist-kit-app/fist-web/fist-boot-web-app/src/main/java/com/power4j/fist/boot/autoconfigure/web/FistWebAutoConfiguration.java b/fist-kit-app/fist-web/fist-boot-web-app/src/main/java/com/power4j/fist/boot/autoconfigure/web/FistWebAutoConfiguration.java index 61bdbbfd..938885fa 100644 --- a/fist-kit-app/fist-web/fist-boot-web-app/src/main/java/com/power4j/fist/boot/autoconfigure/web/FistWebAutoConfiguration.java +++ b/fist-kit-app/fist-web/fist-boot-web-app/src/main/java/com/power4j/fist/boot/autoconfigure/web/FistWebAutoConfiguration.java @@ -24,7 +24,7 @@ import com.power4j.fist.boot.web.servlet.mvc.formatter.LocalTimeFormatter; import com.power4j.fist.boot.web.servlet.mvc.formatter.MonthDayFormatter; import com.power4j.fist.boot.web.servlet.mvc.formatter.YearMonthFormatter; -import com.power4j.fist.boot.web.servlet.util.HttpServletRequestUtil; +import com.power4j.fist.support.spring.web.servlet.util.HttpServletRequestUtil; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; diff --git a/fist-kit-app/fist-web/fist-boot-web-app/src/main/java/com/power4j/fist/boot/common/jackson/JacksonConfig.java b/fist-kit-app/fist-web/fist-boot-web-app/src/main/java/com/power4j/fist/boot/common/jackson/JacksonConfig.java index dbae2873..43bfce1d 100644 --- a/fist-kit-app/fist-web/fist-boot-web-app/src/main/java/com/power4j/fist/boot/common/jackson/JacksonConfig.java +++ b/fist-kit-app/fist-web/fist-boot-web-app/src/main/java/com/power4j/fist/boot/common/jackson/JacksonConfig.java @@ -98,9 +98,12 @@ private void applySimpleDateFormat(Jackson2ObjectMapperBuilder builder) { private void applyModules(Jackson2ObjectMapperBuilder builder) { List excludeModules = ObjectUtils - .defaultIfNull(jacksonCustomizeProperties.getExcludeModules(), Collections.emptyList()); - List modules = MODULE_MAP.entrySet().stream().filter(kv -> !excludeModules.contains(kv.getKey())) - .map(Map.Entry::getValue).collect(Collectors.toList()); + .defaultIfNull(jacksonCustomizeProperties.getExcludeModules(), Collections.emptyList()); + List modules = MODULE_MAP.entrySet() + .stream() + .filter(kv -> !excludeModules.contains(kv.getKey())) + .map(Map.Entry::getValue) + .collect(Collectors.toList()); if (!modules.isEmpty()) { List names = modules.stream().map(Module::getModuleName).collect(Collectors.toList()); log.info("Install modules: {}", names); diff --git a/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/mon/EventUtils.java b/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/mon/EventUtils.java index 3ce898b5..8d2166a1 100644 --- a/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/mon/EventUtils.java +++ b/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/mon/EventUtils.java @@ -21,7 +21,7 @@ import com.power4j.fist.boot.mon.info.ExceptionInfo; import com.power4j.fist.boot.mon.info.InfoUtil; import com.power4j.fist.boot.mon.info.TraceInfo; -import com.power4j.fist.boot.util.ApplicationContextHolder; +import com.power4j.fist.support.spring.util.ApplicationContextHolder; import lombok.experimental.UtilityClass; import org.apache.commons.lang3.ObjectUtils; import org.springframework.lang.Nullable; diff --git a/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/mon/Mon.java b/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/mon/Mon.java index 7a6da700..1a921c6e 100644 --- a/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/mon/Mon.java +++ b/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/mon/Mon.java @@ -17,7 +17,7 @@ package com.power4j.fist.boot.mon; import com.power4j.coca.kit.common.exception.WrappedException; -import com.power4j.fist.boot.util.SpringEventUtil; +import com.power4j.fist.support.spring.util.SpringEventUtil; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.function.FailableRunnable; import org.apache.commons.lang3.function.FailableSupplier; diff --git a/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/mon/aspect/ApiLogAspect.java b/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/mon/aspect/ApiLogAspect.java index f4822f43..b3310766 100644 --- a/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/mon/aspect/ApiLogAspect.java +++ b/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/mon/aspect/ApiLogAspect.java @@ -19,7 +19,7 @@ import com.power4j.coca.kit.common.datetime.DateTimeKit; import com.power4j.coca.kit.common.lang.Result; import com.power4j.coca.kit.common.text.StringPool; -import com.power4j.fist.boot.common.aop.AopUtil; +import com.power4j.fist.support.spring.aop.AopUtil; import com.power4j.fist.boot.mon.ApiDescriptionResolver; import com.power4j.fist.boot.mon.EventUtils; import com.power4j.fist.boot.mon.annotation.ApiLog; @@ -30,8 +30,8 @@ import com.power4j.fist.boot.mon.info.ExceptionTranslator; import com.power4j.fist.boot.mon.info.HttpRequestInfo; import com.power4j.fist.boot.security.core.UserInfoAccessor; -import com.power4j.fist.boot.util.SpringEventUtil; -import com.power4j.fist.boot.web.servlet.util.HttpServletRequestUtil; +import com.power4j.fist.support.spring.util.SpringEventUtil; +import com.power4j.fist.support.spring.web.servlet.util.HttpServletRequestUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; @@ -108,8 +108,10 @@ public Object around(ProceedingJoinPoint point, ApiLog apiLog) throws Throwable } AuthInfo getAuthInfo() { - return Optional.ofNullable(userInfoAccessor).flatMap(UserInfoAccessor::getUserInfo).map(AuthInfo::from) - .orElseGet(AuthInfo::new); + return Optional.ofNullable(userInfoAccessor) + .flatMap(UserInfoAccessor::getUserInfo) + .map(AuthInfo::from) + .orElseGet(AuthInfo::new); } void fetchResultInfo(Object result, ApiLogEvent event) { @@ -123,8 +125,8 @@ void fetchResultInfo(Object result, ApiLogEvent event) { } void fetchErrorInfo(Throwable e, ApiLogEvent event) { - exceptionTranslator.translateException(e).ifPresentOrElse(event::setResponseInfo, - () -> event.setError(ExceptionInfo.from(e, 2000))); + exceptionTranslator.translateException(e) + .ifPresentOrElse(event::setResponseInfo, () -> event.setError(ExceptionInfo.from(e, 2000))); } String getDescription(ProceedingJoinPoint point) { diff --git a/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/mon/aspect/ReportErrorAspect.java b/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/mon/aspect/ReportErrorAspect.java index c0a37bb3..ff26f663 100644 --- a/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/mon/aspect/ReportErrorAspect.java +++ b/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/mon/aspect/ReportErrorAspect.java @@ -17,12 +17,12 @@ package com.power4j.fist.boot.mon.aspect; import com.power4j.coca.kit.common.text.StringPool; -import com.power4j.fist.boot.common.aop.AopUtil; -import com.power4j.fist.boot.common.spel.MethodParameterResolver; -import com.power4j.fist.boot.common.spel.SpringElUtil; +import com.power4j.fist.support.spring.aop.AopUtil; +import com.power4j.fist.support.spring.spel.MethodParameterResolver; +import com.power4j.fist.support.spring.spel.SpringElUtil; import com.power4j.fist.boot.mon.EventUtils; import com.power4j.fist.boot.mon.annotation.ReportError; -import com.power4j.fist.boot.util.SpringEventUtil; +import com.power4j.fist.support.spring.util.SpringEventUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.aspectj.lang.ProceedingJoinPoint; diff --git a/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/mon/info/HttpRequestInfo.java b/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/mon/info/HttpRequestInfo.java index 7d28d5a5..ac7ca5b3 100644 --- a/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/mon/info/HttpRequestInfo.java +++ b/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/mon/info/HttpRequestInfo.java @@ -16,7 +16,7 @@ package com.power4j.fist.boot.mon.info; -import com.power4j.fist.boot.web.servlet.util.HttpServletRequestUtil; +import com.power4j.fist.support.spring.web.servlet.util.HttpServletRequestUtil; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/web/servlet/error/AbstractExceptionHandler.java b/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/web/servlet/error/AbstractExceptionHandler.java index bf8f5815..1fc6c350 100644 --- a/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/web/servlet/error/AbstractExceptionHandler.java +++ b/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/web/servlet/error/AbstractExceptionHandler.java @@ -21,11 +21,11 @@ import com.power4j.fist.boot.mon.info.InfoUtil; import com.power4j.fist.boot.mon.info.TraceInfo; import com.power4j.fist.boot.mon.info.TraceInfoResolver; -import com.power4j.fist.boot.util.ApplicationContextHolder; -import com.power4j.fist.boot.util.SpringEventUtil; +import com.power4j.fist.support.spring.util.ApplicationContextHolder; +import com.power4j.fist.support.spring.util.SpringEventUtil; import com.power4j.fist.boot.web.event.error.HandlerErrorEvent; import com.power4j.fist.boot.web.event.error.RequestInfo; -import com.power4j.fist.boot.web.servlet.util.HttpServletRequestUtil; +import com.power4j.fist.support.spring.web.servlet.util.HttpServletRequestUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -58,10 +58,12 @@ protected void doNotify(Throwable e) { } protected HandlerErrorEvent createErrorEvent(Throwable e) { - String appName = ApplicationContextHolder.getContextOptional().map(ApplicationContext::getApplicationName) - .orElse("未知应用"); + String appName = ApplicationContextHolder.getContextOptional() + .map(ApplicationContext::getApplicationName) + .orElse("未知应用"); TraceInfo traceInfo = HttpServletRequestUtil.getCurrentRequestIfAvailable() - .flatMap(o -> traceInfoResolver.resolve(o)).orElse(new TraceInfo()); + .flatMap(o -> traceInfoResolver.resolve(o)) + .orElse(new TraceInfo()); HandlerErrorEvent handlerErrorEvent = new HandlerErrorEvent(); handlerErrorEvent.setAppName(appName); handlerErrorEvent.setTime(DateTimeKit.utcNow()); diff --git a/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/web/servlet/error/ServerErrorHandler.java b/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/web/servlet/error/ServerErrorHandler.java index 3585a870..e05f3292 100644 --- a/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/web/servlet/error/ServerErrorHandler.java +++ b/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/web/servlet/error/ServerErrorHandler.java @@ -66,8 +66,8 @@ public void setLocaleResolver(@Nullable LocaleResolver localeResolver) { protected Result makeResult(MsgBundleRejectedException e) { Locale locale = Optional.ofNullable(localeResolver).map(LocaleResolver::resolve).orElse(Locale.CHINA); - String msg = Objects.requireNonNull(messageSourceAccessor).getMessage(e.getMsgKey(), e.getMsgArg(), - e.getMsgKey(), locale); + String msg = Objects.requireNonNull(messageSourceAccessor) + .getMessage(e.getMsgKey(), e.getMsgArg(), e.getMsgKey(), locale); return Result.create(e.getCode(), msg, null); } diff --git a/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/web/servlet/mvc/formatter/DateTimeParser.java b/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/web/servlet/mvc/formatter/DateTimeParser.java index a24c23e9..b96a2afb 100644 --- a/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/web/servlet/mvc/formatter/DateTimeParser.java +++ b/fist-kit-app/fist-web/fist-support-web/src/main/java/com/power4j/fist/boot/web/servlet/mvc/formatter/DateTimeParser.java @@ -42,20 +42,20 @@ public class DateTimeParser { public final static DateTimeFormatter DEFAULT_YEAR_MONTH_FORMATTER = DateTimeFormatter - .ofPattern(DateTimePattern.YEAR_MONTH); + .ofPattern(DateTimePattern.YEAR_MONTH); public final static DateTimeFormatter DEFAULT_MONTH_DAY_FORMATTER = DateTimeFormatter - .ofPattern(DateTimePattern.MONTH_DAY); + .ofPattern(DateTimePattern.MONTH_DAY); public final static DateTimeFormatter DEFAULT_DATE_FORMATTER = DateTimeFormatter.ofPattern(DateTimePattern.DATE); public final static DateTimeFormatter DEFAULT_TIME_FORMATTER = DateTimeFormatter.ofPattern(DateTimePattern.TIME); public final static DateTimeFormatter DEFAULT_DATETIME_FORMATTER = DateTimeFormatter - .ofPattern(DateTimePattern.DATETIME); + .ofPattern(DateTimePattern.DATETIME); public final static DateTimeFormatter UTC_DATETIME_FORMATTER = DateTimeFormatter - .ofPattern(DateTimePattern.DATETIME_UTC); + .ofPattern(DateTimePattern.DATETIME_UTC); private final static List> YEAR_MONTH_FORMAT_REGISTRY = new ArrayList<>(3); diff --git a/fist-kit-app/fist-web/fist-support-web/src/test/java/com/power4j/fist/boot/mon/aspect/ApiLogAspectTest.java b/fist-kit-app/fist-web/fist-support-web/src/test/java/com/power4j/fist/boot/mon/aspect/ApiLogAspectTest.java index 328f6d79..2b97ac90 100644 --- a/fist-kit-app/fist-web/fist-support-web/src/test/java/com/power4j/fist/boot/mon/aspect/ApiLogAspectTest.java +++ b/fist-kit-app/fist-web/fist-support-web/src/test/java/com/power4j/fist/boot/mon/aspect/ApiLogAspectTest.java @@ -1,7 +1,7 @@ package com.power4j.fist.boot.mon.aspect; import com.power4j.fist.boot.mon.event.ApiLogEvent; -import com.power4j.fist.boot.util.ApplicationContextHolder; +import com.power4j.fist.support.spring.util.ApplicationContextHolder; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -82,4 +82,4 @@ void handleError() { Assertions.assertEquals(RuntimeException.class.getName(), unexpectedException.getError().getEx()); } -} \ No newline at end of file +} diff --git a/fist-kit-build/pom.xml b/fist-kit-build/pom.xml index 9c0076a3..f965e63a 100644 --- a/fist-kit-build/pom.xml +++ b/fist-kit-build/pom.xml @@ -277,6 +277,10 @@ ${skipTests} + + org.apache.maven.plugins + maven-dependency-plugin + diff --git a/fist-kit-cloud/fist-cloud-gateway/fist-cloud-gateway-acl/src/main/java/com/power4j/fist/autoconfigure/gateway/Oauth2Configuration.java b/fist-kit-cloud/fist-cloud-gateway/fist-cloud-gateway-acl/src/main/java/com/power4j/fist/autoconfigure/gateway/Oauth2Configuration.java index 2d80c00b..246e8383 100644 --- a/fist-kit-cloud/fist-cloud-gateway/fist-cloud-gateway-acl/src/main/java/com/power4j/fist/autoconfigure/gateway/Oauth2Configuration.java +++ b/fist-kit-cloud/fist-cloud-gateway/fist-cloud-gateway-acl/src/main/java/com/power4j/fist/autoconfigure/gateway/Oauth2Configuration.java @@ -49,11 +49,13 @@ public UserIntrospectClient userIntrospectClient() { if (StringUtils.startsWith(uri, LB_SCHEMA)) { log.info("Use load-balanced client for: {}", uri); client = lbWebClientBuilder() - .defaultHeaders((h) -> h.setBasicAuth(config.getClientId(), config.getClientSecret())).build(); + .defaultHeaders((h) -> h.setBasicAuth(config.getClientId(), config.getClientSecret())) + .build(); } else { client = WebClient.builder() - .defaultHeaders((h) -> h.setBasicAuth(config.getClientId(), config.getClientSecret())).build(); + .defaultHeaders((h) -> h.setBasicAuth(config.getClientId(), config.getClientSecret())) + .build(); } ReactiveOpaqueTokenIntrospector opaqueTokenIntrospector = new DefaultReactiveOpaqueTokenIntrospector(uri, client); diff --git a/fist-kit-cloud/fist-cloud-gateway/fist-cloud-gateway-acl/src/main/java/com/power4j/fist/autoconfigure/gateway/annotation/EnableRouteGuard.java b/fist-kit-cloud/fist-cloud-gateway/fist-cloud-gateway-acl/src/main/java/com/power4j/fist/autoconfigure/gateway/annotation/EnableRouteGuard.java index 69909cc2..eef9ce3b 100644 --- a/fist-kit-cloud/fist-cloud-gateway/fist-cloud-gateway-acl/src/main/java/com/power4j/fist/autoconfigure/gateway/annotation/EnableRouteGuard.java +++ b/fist-kit-cloud/fist-cloud-gateway/fist-cloud-gateway-acl/src/main/java/com/power4j/fist/autoconfigure/gateway/annotation/EnableRouteGuard.java @@ -11,6 +11,7 @@ /** * ] + * * @author CJ (power4j@outlook.com) * @since 1.0 */ diff --git a/fist-kit-cloud/fist-cloud-gateway/fist-cloud-gateway-acl/src/main/java/com/power4j/fist/cloud/security/DefaultAccessDeniedHandler.java b/fist-kit-cloud/fist-cloud-gateway/fist-cloud-gateway-acl/src/main/java/com/power4j/fist/cloud/security/DefaultAccessDeniedHandler.java index da2e276b..d1266f8a 100644 --- a/fist-kit-cloud/fist-cloud-gateway/fist-cloud-gateway-acl/src/main/java/com/power4j/fist/cloud/security/DefaultAccessDeniedHandler.java +++ b/fist-kit-cloud/fist-cloud-gateway/fist-cloud-gateway-acl/src/main/java/com/power4j/fist/cloud/security/DefaultAccessDeniedHandler.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.power4j.fist.boot.common.error.ErrorCode; -import com.power4j.fist.boot.web.reactive.util.ServerHttpResponseUtil; +import com.power4j.fist.support.spring.web.reactive.util.ServerHttpResponseUtil; import com.power4j.fist.cloud.gateway.authorization.domain.AuthProblem; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; @@ -32,14 +32,20 @@ public Mono handleAccessDenied(ServerWebExchange exchange, AuthProblem pro payload.put(KEY_CODE, ErrorCode.A0301); payload.put(KEY_MESSAGE, String.format("Access denied(%s)", problem.getCode())); return ServerHttpResponseUtil - .responseWithJsonObject(response, objectMapper, payload, translateHttpStatus(problem)) - .then(Mono.defer(() -> exchange.getResponse().setComplete())); + .responseWithJsonObject(response, objectMapper, payload, translateHttpStatus(problem)) + .then(Mono.defer(() -> exchange.getResponse().setComplete())); } static HttpStatus translateHttpStatus(AuthProblem problem) { + if (AuthProblem.Advise.AUTH.equals(problem.getAdvise())) { + return HttpStatus.UNAUTHORIZED; + } if (problem.codeEquals(AuthProblem.HTTP_PROTOCOL.getCode())) { return HttpStatus.NOT_IMPLEMENTED; } + else if (problem.codeEquals(AuthProblem.AUTH_EXCEPTION.getCode())) { + return HttpStatus.INTERNAL_SERVER_ERROR; + } return HttpStatus.FORBIDDEN; } diff --git a/fist-kit-cloud/fist-cloud-gateway/fist-cloud-gateway-acl/src/test/java/com/power4j/fist/cloud/gateway/ApiGuardFilterTest.java b/fist-kit-cloud/fist-cloud-gateway/fist-cloud-gateway-acl/src/test/java/com/power4j/fist/cloud/gateway/ApiGuardFilterTest.java index 0bb8213d..19383f59 100644 --- a/fist-kit-cloud/fist-cloud-gateway/fist-cloud-gateway-acl/src/test/java/com/power4j/fist/cloud/gateway/ApiGuardFilterTest.java +++ b/fist-kit-cloud/fist-cloud-gateway/fist-cloud-gateway-acl/src/test/java/com/power4j/fist/cloud/gateway/ApiGuardFilterTest.java @@ -46,7 +46,7 @@ public void shouldCallAccessDenied() { when(deniedHandler.handleAccessDenied(any(), any())).thenReturn(Mono.empty()); when(filter.makeAuthContext(any())) - .thenReturn(makeAuthContext(exchange, null, AuthProblem.PERMISSION_CHECK_DENIED)); + .thenReturn(makeAuthContext(exchange, null, AuthProblem.PERMISSION_CHECK_DENIED)); Mono result = filter.filter(exchange, gatewayFilterChain); StepVerifier.create(result).verifyComplete(); @@ -65,7 +65,7 @@ public void shouldCallAccessPermitted() { when(permittedHandler.handleAccessPermitted(any())).thenReturn(Mono.just(exchange)); when(filter.makeAuthContext(any())) - .thenReturn(makeAuthContext(exchange, new UserInfo(), AuthProblem.PUB_ACCESS)); + .thenReturn(makeAuthContext(exchange, new UserInfo(), AuthProblem.PUB_ACCESS)); when(gatewayFilterChain.filter(any())).thenReturn(Mono.empty()); Mono result = filter.filter(exchange, gatewayFilterChain); diff --git a/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/domain/AuthProblem.java b/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/domain/AuthProblem.java index 462bdb9a..f49ba5a0 100644 --- a/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/domain/AuthProblem.java +++ b/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/domain/AuthProblem.java @@ -38,6 +38,9 @@ public class AuthProblem { @Nullable private String moreInfo; + @Nullable + private Advise advise; + public AuthProblem(int code, String msg) { this.code = code; this.msg = msg; @@ -48,6 +51,11 @@ public AuthProblem moreInfo(String info) { return this; } + public AuthProblem advise(Advise advise) { + this.advise = advise; + return this; + } + public boolean codeEquals(int value) { return code == value; } @@ -157,7 +165,18 @@ public String description() { @Override public String toString() { return new StringJoiner(", ", AuthProblem.class.getSimpleName() + "[", "]").add("code=" + code) - .add("msgKey='" + msg + "'").toString(); + .add("advise=" + advise) + .add("msg='" + msg + "'") + .toString(); + } + + public enum Advise { + + /** need authentication */ + AUTH, + /** need permission */ + PERM + } } diff --git a/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/GatewayAuthFilter.java b/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/GatewayAuthFilter.java index 6702610e..9e2f295b 100644 --- a/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/GatewayAuthFilter.java +++ b/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/GatewayAuthFilter.java @@ -39,8 +39,10 @@ public interface GatewayAuthFilter extends ServerAuthFilter { * @return 返回状态调试信息 */ default String checkpointDescription(AuthContext context) { - String prob = Optional.ofNullable(context.getAuthState()).map(AuthState::getProblem).map(AuthProblem::getMsg) - .orElse("null"); + String prob = Optional.ofNullable(context.getAuthState()) + .map(AuthState::getProblem) + .map(AuthProblem::getMsg) + .orElse("null"); return String.format("[AuthProblem] %s , [%s]", prob, getClass().getName()); } diff --git a/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/LoginAccessFilter.java b/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/LoginAccessFilter.java index 1722e300..f8138855 100644 --- a/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/LoginAccessFilter.java +++ b/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/LoginAccessFilter.java @@ -47,9 +47,9 @@ public Mono filter(AuthContext ctx, ServerAuthFilterChain cha } else { if (log.isDebugEnabled()) { - log.debug("Login access required,but not user info. => {}", ctx.getInbound().shortDescription()); + log.debug("Login access required,but no user info. => {}", ctx.getInbound().shortDescription()); } - return exitChain(ctx, AuthProblem.USER_ACCESS_DENIED); + return exitChain(ctx, AuthProblem.USER_ACCESS_DENIED.advise(AuthProblem.Advise.AUTH)); } } return doNext(ctx, chain); diff --git a/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/SafeModeFilter.java b/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/SafeModeFilter.java index 01b43331..df94f292 100644 --- a/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/SafeModeFilter.java +++ b/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/SafeModeFilter.java @@ -51,7 +51,8 @@ static boolean matchAny(String input, Collection patterns) { @Override public Mono filter(AuthContext ctx, ServerAuthFilterChain chain) { Optional address = Optional.ofNullable(ctx.getExchange().getRequest().getRemoteAddress()) - .map(InetSocketAddress::getAddress).map(InetAddress::getHostAddress); + .map(InetSocketAddress::getAddress) + .map(InetAddress::getHostAddress); boolean isSafe = address.map(s -> matchAny(s, whitelist)).orElse(false); if (log.isDebugEnabled()) { diff --git a/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/TenantFilter.java b/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/TenantFilter.java index 6e46511e..7c8a90a0 100644 --- a/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/TenantFilter.java +++ b/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/TenantFilter.java @@ -47,7 +47,8 @@ public Mono filter(AuthContext ctx, ServerAuthFilterChain cha } final AuthenticatedUser userInfo = ctx.getUserInfo(); if (Objects.isNull(userInfo)) { - return exitChain(ctx, AuthProblem.PERMISSION_CHECK_DENIED.moreInfo("No user info")); + return exitChain(ctx, + AuthProblem.PERMISSION_CHECK_DENIED.advise(AuthProblem.Advise.AUTH).moreInfo("No user info")); } final String tenantId = resolveTenantId(ctx.getExchange().getRequest()).orElse(null); if (!validateTenant(tenantId, ctx)) { diff --git a/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/UpstreamLocateFilter.java b/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/UpstreamLocateFilter.java index 1c4b7861..b8f4e737 100644 --- a/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/UpstreamLocateFilter.java +++ b/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/UpstreamLocateFilter.java @@ -100,7 +100,7 @@ Mono resolveUpstream(AuthContext context, ServerAuthFilterChain makeDefaultApiProxy(context)); + .orElseGet(() -> makeDefaultApiProxy(context)); if (log.isTraceEnabled()) { log.trace("use upstream : {}", upstream.description()); } diff --git a/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/UserPermissionFilter.java b/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/UserPermissionFilter.java index 4051cd2c..3a37c37d 100644 --- a/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/UserPermissionFilter.java +++ b/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/UserPermissionFilter.java @@ -42,7 +42,8 @@ public Mono filter(AuthContext ctx, ServerAuthFilterChain cha } final AuthenticatedUser userInfo = ctx.getUserInfo(); if (Objects.isNull(userInfo)) { - return exitChain(ctx, AuthProblem.PERMISSION_CHECK_DENIED.moreInfo("No user info")); + return exitChain(ctx, + AuthProblem.PERMISSION_CHECK_DENIED.advise(AuthProblem.Advise.AUTH).moreInfo("No user info")); } return validatePermission(ctx); } diff --git a/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/proxy/DefaultProxyResolver.java b/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/proxy/DefaultProxyResolver.java index 8148e4a0..5226da17 100644 --- a/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/proxy/DefaultProxyResolver.java +++ b/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/main/java/com/power4j/fist/cloud/gateway/proxy/DefaultProxyResolver.java @@ -59,8 +59,9 @@ public Optional resolve(@Nullable RouteInfo routeInfo, ServerWebExchan } static String strip(String path, int parts) { - String newPath = "/" + Arrays.stream(StringUtils.tokenizeToStringArray(path, "/")).skip(parts) - .collect(Collectors.joining("/")); + String newPath = "/" + Arrays.stream(StringUtils.tokenizeToStringArray(path, "/")) + .skip(parts) + .collect(Collectors.joining("/")); newPath += (newPath.length() > 1 && path.endsWith("/") ? "/" : ""); return newPath; } diff --git a/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/test/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/LoadPermissionDefinitionFilterTest.java b/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/test/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/LoadPermissionDefinitionFilterTest.java index 0be04e68..4284b204 100644 --- a/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/test/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/LoadPermissionDefinitionFilterTest.java +++ b/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/test/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/LoadPermissionDefinitionFilterTest.java @@ -92,7 +92,7 @@ public void shouldCallChainIfMatched() { when(authFilterChain.filter(any())).thenReturn(Mono.empty()); when(matcher.bestMatch(any(), any(), any())).thenReturn(Optional.of(apiPermDefinition)); when(service.getPermissionDefinition(any(), any())) - .thenReturn(Mono.just(Collections.singletonList(apiPermDefinition))); + .thenReturn(Mono.just(Collections.singletonList(apiPermDefinition))); Mono result = filter.filter(authContext, authFilterChain); StepVerifier.create(result).verifyComplete(); verify(authFilterChain, only()).filter(any()); diff --git a/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/test/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/LoadUserPermissionFilterTest.java b/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/test/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/LoadUserPermissionFilterTest.java index eabbbb2b..26834a27 100644 --- a/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/test/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/LoadUserPermissionFilterTest.java +++ b/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/test/java/com/power4j/fist/cloud/gateway/authorization/filter/reactive/impl/LoadUserPermissionFilterTest.java @@ -20,7 +20,7 @@ class LoadUserPermissionFilterTest { UserService userService1 = user -> Mono - .just(new AnonymousUser(Collections.emptyMap())); + .just(new AnonymousUser(Collections.emptyMap())); UserService userService2 = user -> Mono.empty(); diff --git a/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/test/java/com/power4j/fist/cloud/oauth2/server/resource/reactive/BearTokenAuthenticationConverterFilterTest.java b/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/test/java/com/power4j/fist/cloud/oauth2/server/resource/reactive/BearTokenAuthenticationConverterFilterTest.java index c742e618..a88056f2 100644 --- a/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/test/java/com/power4j/fist/cloud/oauth2/server/resource/reactive/BearTokenAuthenticationConverterFilterTest.java +++ b/fist-kit-cloud/fist-cloud-gateway/fist-gateway-auth-core/src/test/java/com/power4j/fist/cloud/oauth2/server/resource/reactive/BearTokenAuthenticationConverterFilterTest.java @@ -55,7 +55,7 @@ public void authenticationProcessorNotCalled() { @Test public void authenticationProcessorCalled() { Context context = ReactiveSecurityContextHolder - .withSecurityContext(Mono.just(new SecurityContextImpl(bearerTokenAuthentication))); + .withSecurityContext(Mono.just(new SecurityContextImpl(bearerTokenAuthentication))); MockServerWebExchange serverWebExchange = MockServerWebExchange.from(MockServerHttpRequest.get("/").build()); given(authenticationProcessor.process(any(), any())).willReturn(Mono.just(serverWebExchange)); given(this.chain.filter(serverWebExchange)).willReturn(this.chainResult.mono()); diff --git a/fist-kit-cloud/fist-cloud-rpc-feign/src/main/java/com/power4j/fist/cloud/autoconfigure/rpc/feign/FeignClientAutoConfiguration.java b/fist-kit-cloud/fist-cloud-rpc-feign/src/main/java/com/power4j/fist/cloud/autoconfigure/rpc/feign/FeignClientAutoConfiguration.java index 79f3266d..041d6f90 100644 --- a/fist-kit-cloud/fist-cloud-rpc-feign/src/main/java/com/power4j/fist/cloud/autoconfigure/rpc/feign/FeignClientAutoConfiguration.java +++ b/fist-kit-cloud/fist-cloud-rpc-feign/src/main/java/com/power4j/fist/cloud/autoconfigure/rpc/feign/FeignClientAutoConfiguration.java @@ -19,7 +19,6 @@ import com.power4j.fist.cloud.rpc.feign.UserRelayInterceptor; import feign.RequestInterceptor; import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -29,7 +28,6 @@ * @since 1.0 */ @AutoConfiguration -@EnableFeignClients(basePackages = "com.power4j.fist") @ComponentScan(basePackages = { "com.power4j.fist.cloud.autoconfigure.rpc.feign.error" }) public class FeignClientAutoConfiguration { diff --git a/fist-kit-cloud/fist-cloud-rpc-feign/src/main/java/com/power4j/fist/cloud/rpc/feign/UserRelayInterceptor.java b/fist-kit-cloud/fist-cloud-rpc-feign/src/main/java/com/power4j/fist/cloud/rpc/feign/UserRelayInterceptor.java index 89848dce..6c291768 100644 --- a/fist-kit-cloud/fist-cloud-rpc-feign/src/main/java/com/power4j/fist/cloud/rpc/feign/UserRelayInterceptor.java +++ b/fist-kit-cloud/fist-cloud-rpc-feign/src/main/java/com/power4j/fist/cloud/rpc/feign/UserRelayInterceptor.java @@ -40,8 +40,8 @@ public class UserRelayInterceptor implements RequestInterceptor { @Override public void apply(RequestTemplate template) { List tokens = Optional.ofNullable(template.headers().get(SecurityConstant.HEADER_USER_TOKEN_INNER)) - .map(l -> l.stream().filter(StringUtils::isNotEmpty).collect(Collectors.toList())) - .orElse(Collections.emptyList()); + .map(l -> l.stream().filter(StringUtils::isNotEmpty).collect(Collectors.toList())) + .orElse(Collections.emptyList()); // @formatter:off if(!tokens.isEmpty()){ diff --git a/fist-kit-infra/fist-redisson/src/main/java/com/power4j/fist/message/queue/QueueConsumer.java b/fist-kit-infra/fist-redisson/src/main/java/com/power4j/fist/message/queue/QueueConsumer.java index c7e5335f..b3cdff5e 100644 --- a/fist-kit-infra/fist-redisson/src/main/java/com/power4j/fist/message/queue/QueueConsumer.java +++ b/fist-kit-infra/fist-redisson/src/main/java/com/power4j/fist/message/queue/QueueConsumer.java @@ -17,6 +17,7 @@ * } * } * + * * @author CJ (power4j@outlook.com) * @since 1.0 */ diff --git a/fist-kit-infra/fist-redisson/src/main/java/com/power4j/fist/message/topic/TopicListener.java b/fist-kit-infra/fist-redisson/src/main/java/com/power4j/fist/message/topic/TopicListener.java index f962628b..bd396c4f 100644 --- a/fist-kit-infra/fist-redisson/src/main/java/com/power4j/fist/message/topic/TopicListener.java +++ b/fist-kit-infra/fist-redisson/src/main/java/com/power4j/fist/message/topic/TopicListener.java @@ -25,6 +25,7 @@ * } * } * + * * @author CJ (power4j@outlook.com) * @since 1.0 */ diff --git a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/common/aop/AopUtil.java b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/aop/AopUtil.java similarity index 87% rename from fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/common/aop/AopUtil.java rename to fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/aop/AopUtil.java index 9ed166e9..3fcf581a 100644 --- a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/common/aop/AopUtil.java +++ b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/aop/AopUtil.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.power4j.fist.boot.common.aop; +package com.power4j.fist.support.spring.aop; import lombok.experimental.UtilityClass; import org.aspectj.lang.ProceedingJoinPoint; @@ -35,8 +35,9 @@ public Method getMethod(ProceedingJoinPoint joinPoint) { Method method = signature.getMethod(); if (method.getDeclaringClass().isInterface()) { try { - method = joinPoint.getTarget().getClass().getDeclaredMethod(joinPoint.getSignature().getName(), - method.getParameterTypes()); + method = joinPoint.getTarget() + .getClass() + .getDeclaredMethod(joinPoint.getSignature().getName(), method.getParameterTypes()); } catch (SecurityException | NoSuchMethodException e) { throw new IllegalStateException(e); diff --git a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/i18n/MsgUtil.java b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/i18n/MsgUtil.java new file mode 100644 index 00000000..b6b516bc --- /dev/null +++ b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/i18n/MsgUtil.java @@ -0,0 +1,59 @@ +package com.power4j.fist.support.spring.i18n; + +import com.power4j.fist.support.spring.util.ApplicationContextHolder; +import lombok.extern.slf4j.Slf4j; +import org.springframework.lang.Nullable; + +import java.util.Locale; +import java.util.Optional; + +/** + * @author CJ (power4j@outlook.com) + * @since 2022.1 + */ +@Slf4j +public class MsgUtil { + + /** + * 解析消息 + * @param msgKey 消息键 + * @param args 消息参数 + * @param locale 国际化区域 + * @return 解析失败返回empty + */ + public static Optional resolveMessage(String msgKey, @Nullable Object[] args, Locale locale) { + return ApplicationContextHolder.getContextOptional().map(m -> m.getMessage(msgKey, args, null, locale)); + } + + /** + * 解析消息,使用默认的国际化区域 + * @param msgKey 消息键 + * @param args 消息参数 + * @return 解析失败返回empty + */ + public static Optional resolveMessage(String msgKey, @Nullable Object[] args) { + return resolveMessage(msgKey, args, Locale.getDefault()); + } + + /** + * 获取消息文本 + * @param msgKey 消息键 + * @param args 消息参数 + * @param locale 国际化区域 + * @return 无消息文本返回msgKey + */ + public static String getMessage(String msgKey, @Nullable Object[] args, Locale locale) { + return resolveMessage(msgKey, args, locale).orElse(msgKey); + } + + /** + * 获取消息文本,使用默认的国际化区域 + * @param msgKey 消息键 + * @param args 消息参数 + * @return 无消息文本返回 msgKey + */ + public static String getMessage(String msgKey, @Nullable Object[] args) { + return resolveMessage(msgKey, args).orElse(msgKey); + } + +} diff --git a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/common/spel/package-info.java b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/i18n/package-info.java similarity index 89% rename from fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/common/spel/package-info.java rename to fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/i18n/package-info.java index f75c2a2e..1e92f89c 100644 --- a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/common/spel/package-info.java +++ b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/i18n/package-info.java @@ -21,7 +21,7 @@ */ @NonNullApi @NonNullFields -package com.power4j.fist.boot.common.spel; +package com.power4j.fist.support.spring.i18n; import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; \ No newline at end of file +import org.springframework.lang.NonNullFields; diff --git a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/common/spel/MethodParameterResolver.java b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/spel/MethodParameterResolver.java similarity index 97% rename from fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/common/spel/MethodParameterResolver.java rename to fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/spel/MethodParameterResolver.java index 508a2a0f..1c4fec49 100644 --- a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/common/spel/MethodParameterResolver.java +++ b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/spel/MethodParameterResolver.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.power4j.fist.boot.common.spel; +package com.power4j.fist.support.spring.spel; import org.springframework.core.DefaultParameterNameDiscoverer; diff --git a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/common/spel/SpringElUtil.java b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/spel/SpringElUtil.java similarity index 98% rename from fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/common/spel/SpringElUtil.java rename to fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/spel/SpringElUtil.java index c26e0d1d..bed161d7 100644 --- a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/common/spel/SpringElUtil.java +++ b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/spel/SpringElUtil.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.power4j.fist.boot.common.spel; +package com.power4j.fist.support.spring.spel; import lombok.experimental.UtilityClass; import lombok.extern.slf4j.Slf4j; diff --git a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/common/spel/VariableProvider.java b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/spel/VariableProvider.java similarity index 95% rename from fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/common/spel/VariableProvider.java rename to fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/spel/VariableProvider.java index 74ae2f8e..1368d8a1 100644 --- a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/common/spel/VariableProvider.java +++ b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/spel/VariableProvider.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.power4j.fist.boot.common.spel; +package com.power4j.fist.support.spring.spel; import java.util.Map; diff --git a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/util/package-info.java b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/spel/package-info.java similarity index 89% rename from fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/util/package-info.java rename to fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/spel/package-info.java index 77259285..01074ec4 100644 --- a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/util/package-info.java +++ b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/spel/package-info.java @@ -21,7 +21,7 @@ */ @NonNullApi @NonNullFields -package com.power4j.fist.boot.util; +package com.power4j.fist.support.spring.spel; import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; \ No newline at end of file +import org.springframework.lang.NonNullFields; diff --git a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/util/ApplicationContextHolder.java b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/util/ApplicationContextHolder.java similarity index 90% rename from fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/util/ApplicationContextHolder.java rename to fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/util/ApplicationContextHolder.java index 6bf11202..0e30f2a8 100644 --- a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/util/ApplicationContextHolder.java +++ b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/util/ApplicationContextHolder.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.power4j.fist.boot.util; +package com.power4j.fist.support.spring.util; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeansException; @@ -23,7 +23,6 @@ import org.springframework.context.ApplicationContextAware; import org.springframework.lang.Nullable; -import java.util.Objects; import java.util.Optional; import java.util.concurrent.atomic.AtomicReference; @@ -45,10 +44,6 @@ public void setApplicationContext(ApplicationContext applicationContext) throws } public static Optional getContextOptional() { - ApplicationContext context = CONTEXT_REF.get(); - if (Objects.isNull(context)) { - throw new IllegalStateException("ApplicationContext is null"); - } return Optional.ofNullable(CONTEXT_REF.get()); } diff --git a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/util/BeanFactoryUtil.java b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/util/BeanFactoryUtil.java new file mode 100644 index 00000000..e6b9edee --- /dev/null +++ b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/util/BeanFactoryUtil.java @@ -0,0 +1,49 @@ +package com.power4j.fist.support.spring.util; + +import lombok.experimental.UtilityClass; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.DefaultListableBeanFactory; + +import java.util.function.Supplier; + +/** + * @author CJ (power4j@outlook.com) + * @since 2022.1 + */ +@Slf4j +@UtilityClass +public class BeanFactoryUtil { + + /** + * 注册Bean + * @param beanFactory + * @param type + * @param beanName + * @param beanSupplier + * @param + * @throws BeansException + */ + public void registerPrimaryBean(DefaultListableBeanFactory beanFactory, Class type, String beanName, + Supplier beanSupplier) throws BeansException { + String[] names = beanFactory.getBeanNamesForType(type); + for (String name : names) { + BeanDefinition definition = beanFactory.getBeanDefinition(name); + if (definition.isPrimary()) { + log.debug("unset primary for bean {}, bean class :{}", name, definition.getBeanClassName()); + definition.setPrimary(false); + } + } + BeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(type, beanSupplier) + .getBeanDefinition(); + beanDefinition.setPrimary(true); + String name = beanName; + + log.debug("register bean :{}", name); + beanFactory.registerBeanDefinition(name, beanDefinition); + + } + +} diff --git a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/util/ReflectUtil.java b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/util/ReflectUtil.java similarity index 98% rename from fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/util/ReflectUtil.java rename to fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/util/ReflectUtil.java index 5cfbbe30..ade6fea8 100644 --- a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/util/ReflectUtil.java +++ b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/util/ReflectUtil.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.power4j.fist.boot.util; +package com.power4j.fist.support.spring.util; import lombok.experimental.UtilityClass; import lombok.extern.slf4j.Slf4j; diff --git a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/util/SpringBeanUtil.java b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/util/SpringBeanUtil.java similarity index 97% rename from fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/util/SpringBeanUtil.java rename to fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/util/SpringBeanUtil.java index 913013a3..0e35477b 100644 --- a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/util/SpringBeanUtil.java +++ b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/util/SpringBeanUtil.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.power4j.fist.boot.util; +package com.power4j.fist.support.spring.util; import lombok.experimental.UtilityClass; import lombok.extern.slf4j.Slf4j; diff --git a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/util/SpringEventUtil.java b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/util/SpringEventUtil.java similarity index 95% rename from fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/util/SpringEventUtil.java rename to fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/util/SpringEventUtil.java index d37a8e8a..9493d0aa 100644 --- a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/util/SpringEventUtil.java +++ b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/util/SpringEventUtil.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.power4j.fist.boot.util; +package com.power4j.fist.support.spring.util; import lombok.experimental.UtilityClass; import org.springframework.context.ApplicationEvent; diff --git a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/web/servlet/util/package-info.java b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/util/package-info.java similarity index 89% rename from fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/web/servlet/util/package-info.java rename to fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/util/package-info.java index cc8fcd80..14eaaec7 100644 --- a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/web/servlet/util/package-info.java +++ b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/util/package-info.java @@ -21,7 +21,7 @@ */ @NonNullApi @NonNullFields -package com.power4j.fist.boot.web.servlet.util; +package com.power4j.fist.support.spring.util; import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; \ No newline at end of file +import org.springframework.lang.NonNullFields; diff --git a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/web/reactive/util/ServerHttpRequestUtil.java b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/web/reactive/util/ServerHttpRequestUtil.java similarity index 90% rename from fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/web/reactive/util/ServerHttpRequestUtil.java rename to fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/web/reactive/util/ServerHttpRequestUtil.java index aab27a96..55f06d57 100644 --- a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/web/reactive/util/ServerHttpRequestUtil.java +++ b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/web/reactive/util/ServerHttpRequestUtil.java @@ -14,9 +14,9 @@ * limitations under the License. */ -package com.power4j.fist.boot.web.reactive.util; +package com.power4j.fist.support.spring.web.reactive.util; -import com.power4j.fist.boot.web.servlet.util.HttpServletRequestUtil; +import com.power4j.fist.support.spring.web.servlet.util.HttpServletRequestUtil; import lombok.experimental.UtilityClass; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -44,8 +44,9 @@ public class ServerHttpRequestUtil { public Optional getRemoteIp(ServerHttpRequest request) { Optional ip = HttpServletRequestUtil.getRemoteIp(request.getHeaders()); if (!ip.isPresent()) { - ip = Optional.ofNullable(request.getRemoteAddress()).map(InetSocketAddress::getAddress) - .map(InetAddress::getHostAddress); + ip = Optional.ofNullable(request.getRemoteAddress()) + .map(InetSocketAddress::getAddress) + .map(InetAddress::getHostAddress); } return ip; } diff --git a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/web/reactive/util/ServerHttpResponseUtil.java b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/web/reactive/util/ServerHttpResponseUtil.java similarity index 90% rename from fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/web/reactive/util/ServerHttpResponseUtil.java rename to fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/web/reactive/util/ServerHttpResponseUtil.java index 71682afc..f200d5b2 100644 --- a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/web/reactive/util/ServerHttpResponseUtil.java +++ b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/web/reactive/util/ServerHttpResponseUtil.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.power4j.fist.boot.web.reactive.util; +package com.power4j.fist.support.spring.web.reactive.util; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.experimental.UtilityClass; @@ -79,7 +79,7 @@ public Mono responseWithJsonObject(ServerHttpResponse response, ObjectMapp */ public Mono writeUtf8String(ServerHttpResponse response, Mono str) { return str.map(s -> s.getBytes(StandardCharsets.UTF_8)) - .flatMap(bytes -> writeBytes(response, Mono.just(bytes))); + .flatMap(bytes -> writeBytes(response, Mono.just(bytes))); } /** @@ -89,8 +89,8 @@ public Mono writeUtf8String(ServerHttpResponse response, Mono str) * @return Mono */ public Mono writeBytes(ServerHttpResponse response, Mono data) { - return data.map(bytes -> response.bufferFactory().wrap(bytes)).flatMap( - buffer -> response.writeWith(Mono.just(buffer)).doOnError(e -> DataBufferUtils.release(buffer))); + return data.map(bytes -> response.bufferFactory().wrap(bytes)) + .flatMap(buffer -> response.writeWith(Mono.just(buffer)).doOnError(e -> DataBufferUtils.release(buffer))); } /** @@ -100,8 +100,8 @@ public Mono writeBytes(ServerHttpResponse response, Mono data) { * @return Mono */ public Mono writeBuffer(ServerHttpResponse response, Mono data) { - return data.map(bytes -> response.bufferFactory().wrap(bytes)).flatMap( - buffer -> response.writeWith(Mono.just(buffer)).doOnError(e -> DataBufferUtils.release(buffer))); + return data.map(bytes -> response.bufferFactory().wrap(bytes)) + .flatMap(buffer -> response.writeWith(Mono.just(buffer)).doOnError(e -> DataBufferUtils.release(buffer))); } public ServerHttpResponse requireWriteable(ServerHttpResponse response) { diff --git a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/web/reactive/util/package-info.java b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/web/reactive/util/package-info.java new file mode 100644 index 00000000..d774d287 --- /dev/null +++ b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/web/reactive/util/package-info.java @@ -0,0 +1,27 @@ +/* + * Copyright 2021 ChenJun (power4j@outlook.com & https://github.com/John-Chan) + * + * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.gnu.org/licenses/lgpl.html + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author CJ (power4j@outlook.com) + * @date 2021/6/2 + * @since 1.0 + */ +@NonNullApi +@NonNullFields +package com.power4j.fist.support.spring.web.reactive.util; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; diff --git a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/web/servlet/util/HttpServletRequestUtil.java b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/web/servlet/util/HttpServletRequestUtil.java similarity index 95% rename from fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/web/servlet/util/HttpServletRequestUtil.java rename to fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/web/servlet/util/HttpServletRequestUtil.java index e2774b07..1436c475 100644 --- a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/web/servlet/util/HttpServletRequestUtil.java +++ b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/web/servlet/util/HttpServletRequestUtil.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.power4j.fist.boot.web.servlet.util; +package com.power4j.fist.support.spring.web.servlet.util; import lombok.experimental.UtilityClass; import lombok.extern.slf4j.Slf4j; @@ -79,8 +79,9 @@ public Optional getInputStreamIfAvailable(ServletRequest req * @return Optional */ public Optional getCurrentRequestIfAvailable() { - return Optional.ofNullable(RequestContextHolder.getRequestAttributes()).map(x -> (ServletRequestAttributes) x) - .map(ServletRequestAttributes::getRequest); + return Optional.ofNullable(RequestContextHolder.getRequestAttributes()) + .map(x -> (ServletRequestAttributes) x) + .map(ServletRequestAttributes::getRequest); } /** @@ -90,7 +91,7 @@ public Optional getCurrentRequestIfAvailable() { */ public HttpServletRequest getCurrentRequest() { return getCurrentRequestIfAvailable() - .orElseThrow(() -> new IllegalStateException("Can not offer HttpServletRequest")); + .orElseThrow(() -> new IllegalStateException("Can not offer HttpServletRequest")); } /** diff --git a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/web/servlet/util/HttpServletResponseUtil.java b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/web/servlet/util/HttpServletResponseUtil.java similarity index 95% rename from fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/web/servlet/util/HttpServletResponseUtil.java rename to fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/web/servlet/util/HttpServletResponseUtil.java index ce06e312..ff1f570e 100644 --- a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/web/servlet/util/HttpServletResponseUtil.java +++ b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/web/servlet/util/HttpServletResponseUtil.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.power4j.fist.boot.web.servlet.util; +package com.power4j.fist.support.spring.web.servlet.util; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.experimental.UtilityClass; @@ -54,8 +54,9 @@ public static void writeJson(HttpServletResponse response, Object payload, HttpS * @return */ public Optional getCurrentRequest() { - return Optional.ofNullable(RequestContextHolder.getRequestAttributes()).map(x -> (ServletRequestAttributes) x) - .map(ServletRequestAttributes::getResponse); + return Optional.ofNullable(RequestContextHolder.getRequestAttributes()) + .map(x -> (ServletRequestAttributes) x) + .map(ServletRequestAttributes::getResponse); } public static void writeJson(HttpServletResponse response, ObjectMapper objectMapper, Object payload, diff --git a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/web/reactive/util/package-info.java b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/web/servlet/util/package-info.java similarity index 88% rename from fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/web/reactive/util/package-info.java rename to fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/web/servlet/util/package-info.java index 24cd4da0..8b7363e4 100644 --- a/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/boot/web/reactive/util/package-info.java +++ b/fist-kit-infra/fist-support-spring/src/main/java/com/power4j/fist/support/spring/web/servlet/util/package-info.java @@ -21,7 +21,7 @@ */ @NonNullApi @NonNullFields -package com.power4j.fist.boot.web.reactive.util; +package com.power4j.fist.support.spring.web.servlet.util; import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; \ No newline at end of file +import org.springframework.lang.NonNullFields; diff --git a/fist-kit-infra/fist-support-spring/src/test/java/com/power4j/fist/boot/common/spel/MethodParameterResolverTest.java b/fist-kit-infra/fist-support-spring/src/test/java/com/power4j/fist/support/spring/spel/MethodParameterResolverTest.java similarity index 96% rename from fist-kit-infra/fist-support-spring/src/test/java/com/power4j/fist/boot/common/spel/MethodParameterResolverTest.java rename to fist-kit-infra/fist-support-spring/src/test/java/com/power4j/fist/support/spring/spel/MethodParameterResolverTest.java index 9cdb9790..55101e6a 100644 --- a/fist-kit-infra/fist-support-spring/src/test/java/com/power4j/fist/boot/common/spel/MethodParameterResolverTest.java +++ b/fist-kit-infra/fist-support-spring/src/test/java/com/power4j/fist/support/spring/spel/MethodParameterResolverTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.power4j.fist.boot.common.spel; +package com.power4j.fist.support.spring.spel; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/fist-kit-infra/fist-support-spring/src/test/java/com/power4j/fist/boot/common/spel/SpringElUtilTest.java b/fist-kit-infra/fist-support-spring/src/test/java/com/power4j/fist/support/spring/spel/SpringElUtilTest.java similarity index 97% rename from fist-kit-infra/fist-support-spring/src/test/java/com/power4j/fist/boot/common/spel/SpringElUtilTest.java rename to fist-kit-infra/fist-support-spring/src/test/java/com/power4j/fist/support/spring/spel/SpringElUtilTest.java index 52711d9b..5e8f192b 100644 --- a/fist-kit-infra/fist-support-spring/src/test/java/com/power4j/fist/boot/common/spel/SpringElUtilTest.java +++ b/fist-kit-infra/fist-support-spring/src/test/java/com/power4j/fist/support/spring/spel/SpringElUtilTest.java @@ -1,4 +1,4 @@ -package com.power4j.fist.boot.common.spel; +package com.power4j.fist.support.spring.spel; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/pom.xml b/pom.xml index e2bea762..2cef844a 100644 --- a/pom.xml +++ b/pom.xml @@ -44,15 +44,15 @@ - https://github.com/power4j/fist-cloud-kit - scm:git:git://github.com/power4j/fist-cloud-kit.git - scm:git:https://github.com/power4j/fist-cloud-kit.git + https://github.com/power4j/fckit + scm:git:git://github.com/power4j/fckit.git + scm:git:https://github.com/power4j/fckit.git HEAD false - 2022.1.4-SNAPSHOT + 2022.1.9 UTF-8 UTF-8 11 @@ -64,19 +64,20 @@ 1.5.3.Final 0.2.0 - 0.0.35 + 0.0.39 1.3.0 1.13.1 - 3.2.1 + 3.3.0 4.9.10 - 3.0.0-M8 - 3.10.1 + 3.1.2 + 3.11.0 + 3.6.0 - 2.11.0 - 0.1.4 + 2.13.0 + 0.1.7 31.1-jre - 5.8.12 - 3.19.3 + 5.8.21 + 3.23.2 0.1.1 0.1.3 1.1.0 @@ -213,7 +214,7 @@ org.codehaus.groovy groovy - 3.0.15 + 3.0.18 runtime @@ -253,6 +254,11 @@ maven-compiler-plugin ${maven-compiler-plugin.version} + + org.apache.maven.plugins + maven-dependency-plugin + ${maven-dependency-plugin.version} + @@ -285,7 +291,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.4.1 + 3.5.0 UTF-8 UTF-8 @@ -306,7 +312,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.0.1 + 3.1.0 sign-artifacts