ソースを参照

删除 dfs-gw, dfs-web 和 oss-common 模块

reghao 2 年 前
コミット
fc6e0d302d
26 ファイル変更0 行追加1707 行削除
  1. 0 157
      dfs-gw/pom.xml
  2. 0 13
      dfs-gw/src/main/java/cn/reghao/dfs/gw/DfsGwApplication.java
  3. 0 53
      dfs-gw/src/main/java/cn/reghao/dfs/gw/config/CorsConfig.java
  4. 0 59
      dfs-gw/src/main/java/cn/reghao/dfs/gw/config/RouterConfig.java
  5. 0 46
      dfs-gw/src/main/java/cn/reghao/dfs/gw/filter/CorsResponseHeaderFilter.java
  6. 0 87
      dfs-gw/src/main/java/cn/reghao/dfs/gw/filter/JwtGlobalFilter.java
  7. 0 36
      dfs-gw/src/main/java/cn/reghao/dfs/gw/filter/RateLimitByIpGatewayFilter.java
  8. 0 38
      dfs-gw/src/main/java/cn/reghao/dfs/gw/filter/RequestLogGlobalFilter.java
  9. 0 78
      dfs-gw/src/main/java/cn/reghao/dfs/gw/handler/DynamicRouteHandler.java
  10. 0 18
      dfs-gw/src/main/java/cn/reghao/dfs/gw/model/RequestLog.java
  11. 0 39
      dfs-gw/src/main/java/cn/reghao/dfs/gw/route/DynamicServiceRoute.java
  12. 0 20
      dfs-gw/src/main/java/cn/reghao/dfs/gw/route/StaticRoute.java
  13. 0 10
      dfs-gw/src/main/resources/application-dev.yml
  14. 0 10
      dfs-gw/src/main/resources/application-test.yml
  15. 0 7
      dfs-gw/src/main/resources/application.yml
  16. 0 68
      dfs-gw/src/main/resources/logback-spring.xml
  17. 0 217
      dfs-web/pom.xml
  18. 0 11
      dfs-web/src/main/java/cn/reghao/dfs/web/DfsWebApplication.java
  19. 0 8
      dfs-web/src/main/resources/application-dev.yml
  20. 0 8
      dfs-web/src/main/resources/application-test.yml
  21. 0 26
      dfs-web/src/main/resources/application.yml
  22. 0 68
      dfs-web/src/main/resources/logback-spring.xml
  23. 0 45
      dfs-web/src/main/resources/test.json
  24. 0 23
      oss-common/pom.xml
  25. 0 408
      oss-common/src/main/java/cn/reghao/oss/common/AWS4Signer.java
  26. 0 154
      oss-common/src/main/java/cn/reghao/oss/common/OssUtil.java

+ 0 - 157
dfs-gw/pom.xml

@@ -1,157 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-
-    <groupId>cn.reghao.dfs</groupId>
-    <artifactId>dfs-gw</artifactId>
-    <version>1.0.0</version>
-
-    <properties>
-        <maven.compiler.source>11</maven.compiler.source>
-        <maven.compiler.target>11</maven.compiler.target>
-    </properties>
-
-    <dependencyManagement>
-        <dependencies>
-            <dependency>
-                <groupId>org.springframework.boot</groupId>
-                <artifactId>spring-boot-dependencies</artifactId>
-                <version>2.3.9.RELEASE</version>
-                <type>pom</type>
-                <scope>import</scope>
-            </dependency>
-            <dependency>
-                <groupId>org.springframework.cloud</groupId>
-                <artifactId>spring-cloud-dependencies</artifactId>
-                <version>Hoxton.SR10</version>
-                <type>pom</type>
-                <scope>import</scope>
-            </dependency>
-        </dependencies>
-    </dependencyManagement>
-
-    <dependencies>
-        <dependency>
-            <groupId>cn.reghao.jutil</groupId>
-            <artifactId>tool</artifactId>
-            <version>1.0.0-SNAPSHOT</version>
-        </dependency>
-        <dependency>
-            <groupId>org.projectlombok</groupId>
-            <artifactId>lombok</artifactId>
-            <version>1.18.6</version>
-            <optional>true</optional>
-        </dependency>
-        <dependency>
-            <groupId>ch.qos.logback</groupId>
-            <artifactId>logback-core</artifactId>
-            <version>1.2.3</version>
-        </dependency>
-        <dependency>
-            <groupId>ch.qos.logback</groupId>
-            <artifactId>logback-classic</artifactId>
-            <version>1.2.3</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-webflux</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.springframework.cloud</groupId>
-            <artifactId>spring-cloud-starter-gateway</artifactId>
-        </dependency>
-
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-actuator</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>io.micrometer</groupId>
-            <artifactId>micrometer-registry-prometheus</artifactId>
-            <scope>runtime</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>io.jsonwebtoken</groupId>
-            <artifactId>jjwt</artifactId>
-            <version>0.9.1</version>
-        </dependency>
-        <dependency>
-            <groupId>javax.xml.bind</groupId>
-            <artifactId>jaxb-api</artifactId>
-            <version>2.3.0</version>
-        </dependency>
-        <dependency>
-            <groupId>com.sun.xml.bind</groupId>
-            <artifactId>jaxb-impl</artifactId>
-            <version>2.3.0</version>
-        </dependency>
-        <dependency>
-            <groupId>com.sun.xml.bind</groupId>
-            <artifactId>jaxb-core</artifactId>
-            <version>2.3.0</version>
-        </dependency>
-        <dependency>
-            <groupId>javax.activation</groupId>
-            <artifactId>activation</artifactId>
-            <version>1.1.1</version>
-        </dependency>
-    </dependencies>
-
-    <profiles>
-        <profile>
-            <id>dev</id>
-            <properties>
-                <profile.active>dev</profile.active>
-            </properties>
-            <activation>
-                <activeByDefault>true</activeByDefault>
-            </activation>
-        </profile>
-        <profile>
-            <id>test</id>
-            <properties>
-                <profile.active>test</profile.active>
-            </properties>
-        </profile>
-        <profile>
-            <id>prod</id>
-            <properties>
-                <profile.active>prod</profile.active>
-            </properties>
-        </profile>
-    </profiles>
-
-    <build>
-        <finalName>dfs-gw</finalName>
-        <resources>
-            <resource>
-                <directory>src/main/resources</directory>
-                <filtering>true</filtering>
-                <includes>
-                    <include>application.yml</include>
-                    <include>application-${profile.active}.yml</include>
-                    <include>*.xml</include>
-                </includes>
-            </resource>
-        </resources>
-
-        <plugins>
-            <plugin>
-                <groupId>org.springframework.boot</groupId>
-                <artifactId>spring-boot-maven-plugin</artifactId>
-                <version>2.3.9.RELEASE</version>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>repackage</goal>
-                        </goals>
-                    </execution>
-                </executions>
-            </plugin>
-        </plugins>
-    </build>
-</project>

+ 0 - 13
dfs-gw/src/main/java/cn/reghao/dfs/gw/DfsGwApplication.java

@@ -1,13 +0,0 @@
-package cn.reghao.dfs.gw;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
-
-@SpringBootApplication
-@EnableDiscoveryClient
-public class DfsGwApplication {
-    public static void main(String[] args) {
-        SpringApplication.run(DfsGwApplication.class, args);
-    }
-}

+ 0 - 53
dfs-gw/src/main/java/cn/reghao/dfs/gw/config/CorsConfig.java

@@ -1,53 +0,0 @@
-package cn.reghao.dfs.gw.config;
-
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.server.reactive.ServerHttpRequest;
-import org.springframework.http.server.reactive.ServerHttpResponse;
-import org.springframework.web.cors.reactive.CorsUtils;
-import org.springframework.web.server.ServerWebExchange;
-import org.springframework.web.server.WebFilter;
-import org.springframework.web.server.WebFilterChain;
-import reactor.core.publisher.Mono;
-
-/**
- * 处理跨域
- *
- * @author reghao
- * @date 2019-11-22 16:59:28
- */
-@Configuration
-public class CorsConfig {
-    private final String MAX_AGE = "18_000L";
-
-    @Bean
-    public WebFilter corsFilter() {
-        return (ServerWebExchange ctx, WebFilterChain chain) -> {
-            ServerHttpRequest request = ctx.getRequest();
-            if (CorsUtils.isCorsRequest(request)) {
-                HttpHeaders requestHeaders = request.getHeaders();
-                ServerHttpResponse response = ctx.getResponse();
-                HttpMethod requestMethod = requestHeaders.getAccessControlRequestMethod();
-                HttpHeaders headers = response.getHeaders();
-                headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, requestHeaders.getOrigin());
-                headers.addAll(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, requestHeaders
-                        .getAccessControlRequestHeaders());
-                if (requestMethod != null) {
-                    headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, requestMethod.name());
-                }
-                headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
-                headers.add(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, "*");
-                headers.add(HttpHeaders.ACCESS_CONTROL_MAX_AGE, MAX_AGE);
-                if (request.getMethod() == HttpMethod.OPTIONS) {
-                    response.setStatusCode(HttpStatus.OK);
-                    return Mono.empty();
-                }
-            }
-
-            return chain.filter(ctx);
-        };
-    }
-}

+ 0 - 59
dfs-gw/src/main/java/cn/reghao/dfs/gw/config/RouterConfig.java

@@ -1,59 +0,0 @@
-package cn.reghao.dfs.gw.config;
-
-import org.springframework.cloud.client.discovery.DiscoveryClient;
-import org.springframework.cloud.gateway.discovery.DiscoveryClientRouteDefinitionLocator;
-import org.springframework.cloud.gateway.route.RouteDefinitionLocator;
-import org.springframework.cloud.gateway.route.RouteLocator;
-import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.web.reactive.function.BodyInserters;
-import org.springframework.web.reactive.function.server.RequestPredicates;
-import org.springframework.web.reactive.function.server.RouterFunction;
-import org.springframework.web.reactive.function.server.RouterFunctions;
-import org.springframework.web.reactive.function.server.ServerResponse;
-
-/**
- * @author reghao
- * @date 2019-11-19 09:21:48
- */
-//@Configuration
-public class RouterConfig {
-    /**
-     * 路由过滤,向请求或响应添加首部,参数等
-     *
-     * @param
-     * @return
-     * @date 2019-11-19 上午9:30
-     */
-    @Bean
-    public RouteLocator routeLocator(RouteLocatorBuilder builder) {
-        return builder.routes()
-                .route("path_route", r -> r.path("/reghao")
-                        .filters(f -> f.addResponseHeader("X-Reghao", "reghao"))
-                        .uri("http://cnblogs.com"))
-                .build();
-    }
-
-    /**
-     * 路由断言,根据请求的时间,路径,host 等进行相应的处理
-     *
-     * @param
-     * @return
-     * @date 2019-11-19 上午9:29
-     */
-    @Bean
-    public RouterFunction<ServerResponse> routerFunction() {
-        RouterFunction<ServerResponse> route = RouterFunctions.route(
-                RequestPredicates.path("/test"),
-                req -> ServerResponse.ok().body(BodyInserters.fromObject("test"))
-        );
-
-        return route;
-    }
-
-    @Bean
-    public RouteDefinitionLocator routeDefinitionLocator(DiscoveryClient discoveryClient) {
-        return new DiscoveryClientRouteDefinitionLocator(discoveryClient, null);
-    }
-}

+ 0 - 46
dfs-gw/src/main/java/cn/reghao/dfs/gw/filter/CorsResponseHeaderFilter.java

@@ -1,46 +0,0 @@
-package cn.reghao.dfs.gw.filter;
-
-import org.springframework.cloud.gateway.filter.GatewayFilterChain;
-import org.springframework.cloud.gateway.filter.GlobalFilter;
-import org.springframework.cloud.gateway.filter.NettyWriteResponseFilter;
-import org.springframework.core.Ordered;
-import org.springframework.http.HttpHeaders;
-import org.springframework.stereotype.Component;
-import org.springframework.web.server.ServerWebExchange;
-import reactor.core.publisher.Mono;
-
-import java.util.ArrayList;
-
-/**
- * 处理响应中出现多个 Access-Control-Allow-Origin 的问题
- * TODO 启用 CorsResponseHeaderFilter 会出现重复执行 filter 的情况, 暂时禁用, 使用配置代替
- *
- * @author reghao
- * @date 2021-12-12 14:38:04
- */
-//@Component("corsResponseHeaderFilter")
-public class CorsResponseHeaderFilter implements GlobalFilter, Ordered {
-    @Override
-    public int getOrder() {
-        // 指定此过滤器位于NettyWriteResponseFilter之后
-        // 即待处理完响应体后接着处理响应头
-        return NettyWriteResponseFilter.WRITE_RESPONSE_FILTER_ORDER + 1;
-    }
-
-    @Override
-    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
-        return chain.filter(exchange).then(Mono.defer(() -> {
-            exchange.getResponse().getHeaders().entrySet().stream()
-                    .filter(kv -> (kv.getValue() != null && kv.getValue().size() > 1))
-                    .filter(kv -> (kv.getKey().equals(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)
-                            || kv.getKey().equals(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS)))
-                    .forEach(kv -> {
-                        kv.setValue(new ArrayList<String>() {{
-                            add(kv.getValue().get(0));
-                        }});
-                    });
-
-            return chain.filter(exchange);
-        }));
-    }
-}

+ 0 - 87
dfs-gw/src/main/java/cn/reghao/dfs/gw/filter/JwtGlobalFilter.java

@@ -1,87 +0,0 @@
-package cn.reghao.dfs.gw.filter;
-
-import cn.reghao.jutil.tool.jwt.Jwt;
-import cn.reghao.jutil.tool.jwt.JwtPayload;
-import io.jsonwebtoken.ExpiredJwtException;
-import io.jsonwebtoken.JwtException;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.cloud.gateway.filter.GatewayFilterChain;
-import org.springframework.cloud.gateway.filter.GlobalFilter;
-import org.springframework.core.Ordered;
-import org.springframework.core.io.buffer.DataBuffer;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.server.reactive.ServerHttpRequest;
-import org.springframework.stereotype.Component;
-import org.springframework.web.server.ServerWebExchange;
-import reactor.core.publisher.Flux;
-import reactor.core.publisher.Mono;
-
-import java.nio.charset.StandardCharsets;
-import java.util.*;
-import java.util.function.Consumer;
-
-/**
- * 检查 JWT token(若存在) 是否过期
- *
- * @author reghao
- * @date 2021-07-28 16:50:50
- */
-@Slf4j
-@Component
-public class JwtGlobalFilter implements GlobalFilter, Ordered {
-    @Override
-    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
-        ServerHttpRequest request = exchange.getRequest();
-        String jwt = getJwtToken(request);
-        if (jwt != null) {
-            // TODO 采用响应式编程的格式进行编码
-            /*try {
-                JwtPayload jwtPayload = Jwt.parse(jwt);
-                String userId = jwtPayload.getUserId();
-                Consumer<HttpHeaders> headers = header -> {
-                    header.set("x-user-id", userId);
-                };
-                exchange.getRequest().mutate().headers(headers).build();
-                exchange.mutate().request(exchange.getRequest()).build();
-            } catch (JwtException jwtException) {
-                DataBuffer buffer;
-                if (jwtException instanceof ExpiredJwtException) {
-                    // token 过期
-                    //throw new CredentialsExpiredException("token is expired");
-                    exchange.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED);
-                    String msg = "登录已过期, 请重新登录";
-                    byte[] bytes = msg.getBytes(StandardCharsets.UTF_8);
-                    buffer = exchange.getResponse().bufferFactory().wrap(bytes);
-                } else {
-                    // token 无效
-                    //throw new BadCredentialsException("token is invalid");
-                    exchange.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED);
-                    byte[] bytes = "token is invalid".getBytes(StandardCharsets.UTF_8);
-                    buffer = exchange.getResponse().bufferFactory().wrap(bytes);
-                }
-
-                // 前端无法处理 302,后端返回 401,由前端重定向到认证页面
-                return exchange.getResponse().writeWith(Flux.just(buffer));
-            }*/
-        }
-
-        return chain.filter(exchange);
-    }
-
-    private String getJwtToken(ServerHttpRequest request) {
-        List<String> headerValues = request.getHeaders().get(Jwt.AUTH_HEADER);
-        if (headerValues != null && headerValues.size() == 1) {
-            String headerValue = headerValues.get(0);
-            if (headerValue != null && headerValue.startsWith(Jwt.JWT_PREFIX)) {
-                return headerValue.replace(Jwt.JWT_PREFIX, "");
-            }
-        }
-        return null;
-    }
-
-    @Override
-    public int getOrder() {
-        return -1;
-    }
-}

+ 0 - 36
dfs-gw/src/main/java/cn/reghao/dfs/gw/filter/RateLimitByIpGatewayFilter.java

@@ -1,36 +0,0 @@
-package cn.reghao.dfs.gw.filter;
-
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.cloud.gateway.filter.GatewayFilter;
-import org.springframework.cloud.gateway.filter.GatewayFilterChain;
-import org.springframework.core.Ordered;
-import org.springframework.http.server.reactive.ServerHttpRequest;
-import org.springframework.http.server.reactive.ServerHttpResponse;
-import org.springframework.stereotype.Component;
-import org.springframework.web.server.ServerWebExchange;
-import reactor.core.publisher.Mono;
-
-/**
- * 限流
- *
- * @author reghao
- * @date 2019-11-21 15:34:14
- */
-//@Slf4j
-//@Component
-public class RateLimitByIpGatewayFilter implements GatewayFilter, Ordered {
-    public RateLimitByIpGatewayFilter() {
-    }
-
-    @Override
-    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
-        ServerHttpRequest request = exchange.getRequest();
-        ServerHttpResponse response = exchange.getResponse();
-        return chain.filter(exchange);
-    }
-
-    @Override
-    public int getOrder() {
-        return -1;
-    }
-}

+ 0 - 38
dfs-gw/src/main/java/cn/reghao/dfs/gw/filter/RequestLogGlobalFilter.java

@@ -1,38 +0,0 @@
-package cn.reghao.dfs.gw.filter;
-
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.cloud.gateway.filter.GatewayFilterChain;
-import org.springframework.cloud.gateway.filter.GlobalFilter;
-import org.springframework.core.Ordered;
-import org.springframework.http.server.reactive.ServerHttpRequest;
-import org.springframework.stereotype.Component;
-import org.springframework.web.server.ServerWebExchange;
-import reactor.core.publisher.Mono;
-
-/**
- * 记录请求/响应日志
- *
- * @author reghao
- * @date 2019-11-21 15:34:14
- */
-@Slf4j
-//@Component
-public class RequestLogGlobalFilter implements GlobalFilter, Ordered {
-    public RequestLogGlobalFilter() {
-    }
-
-    @Override
-    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
-        long start = System.currentTimeMillis();
-        ServerHttpRequest request = exchange.getRequest();
-        return chain.filter(exchange).then(Mono.fromRunnable(() -> {
-            long costTime = System.currentTimeMillis()-start;
-            log.info("request costs {}ms", costTime);
-        }));
-    }
-
-    @Override
-    public int getOrder() {
-        return -1;
-    }
-}

+ 0 - 78
dfs-gw/src/main/java/cn/reghao/dfs/gw/handler/DynamicRouteHandler.java

@@ -1,78 +0,0 @@
-package cn.reghao.dfs.gw.handler;
-
-import org.springframework.cloud.gateway.filter.FilterDefinition;
-import org.springframework.cloud.gateway.handler.predicate.PredicateDefinition;
-import org.springframework.cloud.gateway.route.RouteDefinition;
-import org.springframework.http.MediaType;
-import org.springframework.stereotype.Service;
-import org.springframework.web.reactive.function.server.ServerRequest;
-import org.springframework.web.reactive.function.server.ServerResponse;
-import reactor.core.publisher.Mono;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * 动态路由配置
- *
- * @author reghao
- * @date 2019-11-19 10:57:19
- */
-//@Service
-public class DynamicRouteHandler {
-    /**
-     * 注册服务
-     *
-     * @param
-     * @return
-     * @date 2019-11-19 上午10:58
-     */
-    public Mono<ServerResponse> registerService(ServerRequest request) {
-        String service = request.pathVariable("service");
-
-        List<PredicateDefinition> predDefs = new ArrayList<>();
-        PredicateDefinition predDef = new PredicateDefinition();
-        predDef.setName("Path");
-        predDef.addArg("pattern", "/api/");
-        predDefs.add(predDef);
-
-        List<FilterDefinition> filterDefs = new ArrayList<>();
-        FilterDefinition filterDef = new FilterDefinition();
-        filterDef.setName("StripPrefix");
-        filterDef.addArg("parts", "1");
-        filterDefs.add(filterDef);
-
-        URI uri = null;
-        try {
-            uri = new URI("lb://localhost");
-        } catch (URISyntaxException e) {
-            e.printStackTrace();
-        }
-
-        RouteDefinition routeDef = new RouteDefinition();
-        routeDef.setId("");
-        routeDef.setPredicates(predDefs);
-        routeDef.setFilters(filterDefs);
-        routeDef.setUri(uri);
-        routeDef.setOrder(0);
-
-        return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON_UTF8)
-                .body(Mono.just("register " + service), String.class);
-    }
-
-    /**
-     * 注销服务
-     *
-     * @param
-     * @return
-     * @date 2019-11-19 上午11:00
-     */
-    public Mono<ServerResponse> deregisterService(ServerRequest request) {
-        String service = request.pathVariable("service");
-
-        return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON_UTF8)
-                .body(Mono.just("deregister " + service), String.class);
-    }
-}

+ 0 - 18
dfs-gw/src/main/java/cn/reghao/dfs/gw/model/RequestLog.java

@@ -1,18 +0,0 @@
-package cn.reghao.dfs.gw.model;
-
-import lombok.Data;
-
-import java.net.InetSocketAddress;
-
-/**
- * @author reghao
- * @date 2020-04-26 13:47:16
- */
-@Data
-public class RequestLog {
-    private InetSocketAddress remote;
-    private String uri;
-    private String method;
-    private String query;
-    private String body;
-}

+ 0 - 39
dfs-gw/src/main/java/cn/reghao/dfs/gw/route/DynamicServiceRoute.java

@@ -1,39 +0,0 @@
-package cn.reghao.dfs.gw.route;
-
-import cn.reghao.dfs.gw.handler.DynamicRouteHandler;
-import org.springframework.context.annotation.Bean;
-import org.springframework.web.reactive.function.server.RouterFunction;
-import org.springframework.web.reactive.function.server.ServerResponse;
-
-import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
-import static org.springframework.web.reactive.function.server.RequestPredicates.POST;
-import static org.springframework.web.reactive.function.server.RouterFunctions.route;
-
-/**
- * 动态注册服务路由
- *
- * @author reghao
- * @date 2019-11-19 10:53:01
- */
-//@Configuration
-public class DynamicServiceRoute {
-    private final DynamicRouteHandler dynamicRouteHandler;
-
-    public DynamicServiceRoute(DynamicRouteHandler dynamicRouteHandler) {
-        this.dynamicRouteHandler = dynamicRouteHandler;
-    }
-
-    /**
-     * 注册和注销服务路由
-     *
-     * @param
-     * @return
-     * @date 2019-11-19 上午11:06
-     */
-    @Bean
-    public RouterFunction<ServerResponse> serviceRoute() {
-        return route(POST("/api/route/register/{service}"), req -> dynamicRouteHandler.registerService(req))
-                .andRoute(GET("/api/route/deregister/{service}"),
-                        req -> dynamicRouteHandler.deregisterService(req));
-    }
-}

+ 0 - 20
dfs-gw/src/main/java/cn/reghao/dfs/gw/route/StaticRoute.java

@@ -1,20 +0,0 @@
-package cn.reghao.dfs.gw.route;
-
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.web.reactive.function.server.RouterFunction;
-import org.springframework.web.reactive.function.server.RouterFunctions;
-import org.springframework.web.reactive.function.server.ServerResponse;
-
-/**
- * @author reghao
- * @date 2019-11-19 15:43:03
- */
-//@Configuration
-public class StaticRoute {
-    @Bean
-    public RouterFunction<ServerResponse> staticReoute() {
-        return RouterFunctions.resources("/**", new ClassPathResource("static"));
-    }
-}

+ 0 - 10
dfs-gw/src/main/resources/application-dev.yml

@@ -1,10 +0,0 @@
-spring:
-  cloud:
-    gateway:
-      routes:
-        - id: file-router
-          uri: http://127.0.0.1:8002
-          predicates:
-            - Path=/**
-          filters:
-            - StripPrefix=0

+ 0 - 10
dfs-gw/src/main/resources/application-test.yml

@@ -1,10 +0,0 @@
-spring:
-  cloud:
-    gateway:
-      routes:
-        - id: file-router
-          uri: http://127.0.0.1:8002
-          predicates:
-            - Path=/**
-          filters:
-            - StripPrefix=0

+ 0 - 7
dfs-gw/src/main/resources/application.yml

@@ -1,7 +0,0 @@
-server:
-  port: 8000
-spring:
-  application:
-    name: dfs-gw
-  profiles:
-    active: @profile.active@

+ 0 - 68
dfs-gw/src/main/resources/logback-spring.xml

@@ -1,68 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<configuration>
-    <appender name="consoleLog" class="ch.qos.logback.core.ConsoleAppender">
-        <layout class="ch.qos.logback.classic.PatternLayout">
-            <pattern>
-                %d{HH:mm:ss.SSS} [%thread] %-5level %c %M %L - %msg%n
-            </pattern>
-        </layout>
-    </appender>
-
-    <!-- info 日志文件 -->
-    <appender name="fileInfoLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
-        <filter class="ch.qos.logback.classic.filter.LevelFilter">
-            <level>ERROR</level>
-            <onMatch>DENY</onMatch>
-            <onMismatch>ACCEPT</onMismatch>
-        </filter>
-        <encoder>
-            <pattern>
-                %d{HH:mm:ss.SSS} %-5level %c %M %L - %msg%n
-            </pattern>
-            <charset>UTF-8</charset>
-        </encoder>
-        <!-- 滚动策略 -->
-        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
-            <fileNamePattern>
-                logs/info.%d.log
-            </fileNamePattern>
-        </rollingPolicy>
-    </appender>
-
-    <!-- error 日志文件 -->
-    <appender name="fileErrorLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
-        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
-            <level>ERROR</level>
-        </filter>
-        <encoder>
-            <pattern>
-                %d{HH:mm:ss.SSS} %-5level %c %M %L - %msg%n
-            </pattern>
-            <charset>UTF-8</charset>
-        </encoder>
-        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
-            <fileNamePattern>
-                logs/error.%d.log
-            </fileNamePattern>
-        </rollingPolicy>
-    </appender>
-
-    <springProfile name="dev">
-        <root level="info">
-            <appender-ref ref="consoleLog"></appender-ref>
-        </root>
-    </springProfile>
-    <springProfile name="test">
-        <root level="info">
-            <appender-ref ref="fileInfoLog"></appender-ref>
-            <appender-ref ref="fileErrorLog"></appender-ref>
-        </root>
-    </springProfile>
-    <springProfile name="prod">
-        <root level="info">
-            <appender-ref ref="fileInfoLog"></appender-ref>
-            <appender-ref ref="fileErrorLog"></appender-ref>
-        </root>
-    </springProfile>
-</configuration>

+ 0 - 217
dfs-web/pom.xml

@@ -1,217 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-
-    <groupId>cn.reghao.dfs</groupId>
-    <artifactId>dfs-web</artifactId>
-    <version>1.0.0</version>
-
-    <properties>
-        <maven.compiler.source>11</maven.compiler.source>
-        <maven.compiler.target>11</maven.compiler.target>
-    </properties>
-
-    <dependencyManagement>
-        <dependencies>
-            <dependency>
-                <groupId>org.springframework.boot</groupId>
-                <artifactId>spring-boot-dependencies</artifactId>
-                <version>2.3.9.RELEASE</version>
-                <type>pom</type>
-                <scope>import</scope>
-            </dependency>
-        </dependencies>
-    </dependencyManagement>
-
-    <dependencies>
-        <dependency>
-            <groupId>cn.reghao.jutil</groupId>
-            <artifactId>jdk</artifactId>
-            <version>1.0.0-SNAPSHOT</version>
-        </dependency>
-        <dependency>
-            <groupId>cn.reghao.jutil</groupId>
-            <artifactId>tool</artifactId>
-            <version>1.0.0-SNAPSHOT</version>
-        </dependency>
-        <dependency>
-            <groupId>cn.reghao.jutil</groupId>
-            <artifactId>web</artifactId>
-            <version>1.0.0-SNAPSHOT</version>
-        </dependency>
-        <dependency>
-            <groupId>cn.reghao.dfs</groupId>
-            <artifactId>dfs-api</artifactId>
-            <version>1.0.0-SNAPSHOT</version>
-        </dependency>
-        <dependency>
-            <groupId>cn.reghao.oss</groupId>
-            <artifactId>oss-common</artifactId>
-            <version>1.0.0-SNAPSHOT</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.projectlombok</groupId>
-            <artifactId>lombok</artifactId>
-            <version>1.18.6</version>
-            <optional>true</optional>
-        </dependency>
-        <dependency>
-            <groupId>ch.qos.logback</groupId>
-            <artifactId>logback-core</artifactId>
-            <version>1.2.3</version>
-        </dependency>
-        <dependency>
-            <groupId>ch.qos.logback</groupId>
-            <artifactId>logback-classic</artifactId>
-            <version>1.2.3</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-web</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-validation</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-test</artifactId>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.mybatis.spring.boot</groupId>
-            <artifactId>mybatis-spring-boot-starter</artifactId>
-            <version>1.3.2</version>
-        </dependency>
-        <dependency>
-            <groupId>mysql</groupId>
-            <artifactId>mysql-connector-java</artifactId>
-            <version>8.0.17</version>
-        </dependency>
-        <dependency>
-            <groupId>com.zaxxer</groupId>
-            <artifactId>HikariCP</artifactId>
-            <version>3.3.1</version>
-        </dependency>
-
-        <dependency>
-            <groupId>com.google.guava</groupId>
-            <artifactId>guava</artifactId>
-            <version>31.1-jre</version>
-        </dependency>
-
-        <dependency>
-            <groupId>org.apache.dubbo</groupId>
-            <artifactId>dubbo-spring-boot-starter</artifactId>
-            <version>2.7.8</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.curator</groupId>
-            <artifactId>curator-recipes</artifactId>
-            <version>2.12.0</version>
-        </dependency>
-
-        <dependency>
-            <groupId>io.springfox</groupId>
-            <artifactId>springfox-swagger2</artifactId>
-            <version>2.9.2</version>
-        </dependency>
-        <dependency>
-            <groupId>io.springfox</groupId>
-            <artifactId>springfox-swagger-ui</artifactId>
-            <version>2.9.2</version>
-        </dependency>
-
-        <dependency>
-            <groupId>io.jsonwebtoken</groupId>
-            <artifactId>jjwt</artifactId>
-            <version>0.9.1</version>
-        </dependency>
-        <dependency>
-            <groupId>javax.xml.bind</groupId>
-            <artifactId>jaxb-api</artifactId>
-            <version>2.3.0</version>
-        </dependency>
-        <dependency>
-            <groupId>com.sun.xml.bind</groupId>
-            <artifactId>jaxb-impl</artifactId>
-            <version>2.3.0</version>
-        </dependency>
-        <dependency>
-            <groupId>com.sun.xml.bind</groupId>
-            <artifactId>jaxb-core</artifactId>
-            <version>2.3.0</version>
-        </dependency>
-        <dependency>
-            <groupId>javax.activation</groupId>
-            <artifactId>activation</artifactId>
-            <version>1.1.1</version>
-        </dependency>
-
-        <dependency>
-            <groupId>com.drewnoakes</groupId>
-            <artifactId>metadata-extractor</artifactId>
-            <version>2.18.0</version>
-        </dependency>
-    </dependencies>
-
-    <profiles>
-        <profile>
-            <id>dev</id>
-            <properties>
-                <profile.active>dev</profile.active>
-            </properties>
-            <activation>
-                <activeByDefault>true</activeByDefault>
-            </activation>
-        </profile>
-        <profile>
-            <id>test</id>
-            <properties>
-                <profile.active>test</profile.active>
-            </properties>
-        </profile>
-        <profile>
-            <id>prod</id>
-            <properties>
-                <profile.active>prod</profile.active>
-            </properties>
-        </profile>
-    </profiles>
-
-    <build>
-        <finalName>dfs-web</finalName>
-        <resources>
-            <resource>
-                <directory>src/main/resources</directory>
-                <filtering>true</filtering>
-                <includes>
-                    <include>application.yml</include>
-                    <include>application-${profile.active}.yml</include>
-                    <include>mapper/**</include>
-                    <include>*.xml</include>
-                </includes>
-            </resource>
-        </resources>
-
-        <plugins>
-            <plugin>
-                <groupId>org.springframework.boot</groupId>
-                <artifactId>spring-boot-maven-plugin</artifactId>
-                <version>2.3.9.RELEASE</version>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>repackage</goal>
-                        </goals>
-                    </execution>
-                </executions>
-            </plugin>
-        </plugins>
-    </build>
-</project>

+ 0 - 11
dfs-web/src/main/java/cn/reghao/dfs/web/DfsWebApplication.java

@@ -1,11 +0,0 @@
-package cn.reghao.dfs.web;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-
-@SpringBootApplication
-public class DfsWebApplication {
-    public static void main(String[] args) {
-        SpringApplication.run(DfsWebApplication.class, args);
-    }
-}

+ 0 - 8
dfs-web/src/main/resources/application-dev.yml

@@ -1,8 +0,0 @@
-dubbo:
-  registry:
-    address: zookeeper://localhost:2181
-spring:
-  datasource:
-    url: jdbc:mysql://localhost:3306/reghao_oss_rdb?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2b8
-    username: dev
-    password: Dev@123456

+ 0 - 8
dfs-web/src/main/resources/application-test.yml

@@ -1,8 +0,0 @@
-dubbo:
-  registry:
-    address: zookeeper://192.168.0.110:2181
-spring:
-  datasource:
-    url: jdbc:mysql://192.168.0.110:3306/reghao_oss_tdb?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2b8
-    username: test
-    password: Test@123456

+ 0 - 26
dfs-web/src/main/resources/application.yml

@@ -1,26 +0,0 @@
-server:
-  port: 8020
-spring:
-  application:
-    name: dfs-web
-  profiles:
-    active: @profile.active@
-  datasource:
-    driver-class-name: com.mysql.cj.jdbc.Driver
-    type: com.zaxxer.hikari.HikariDataSource
-    hikari:
-      minimum-idle: 5
-      maximum-pool-size: 10
-      auto-commit: true
-      idle-timeout: 30000
-      pool-name: EvaluationHikariCP
-      max-lifetime: 1800000
-      connection-timeout: 30000
-      connection-test-query: SELECT 1
-mybatis:
-  configuration:
-    map-underscore-to-camel-case: true
-    # TODO mybatis sql 执行日志
-#    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
-  mapper-locations: classpath*:mapper/**/**.xml
-  type-aliases-package: cn.reghao.dfs.web.model.po

+ 0 - 68
dfs-web/src/main/resources/logback-spring.xml

@@ -1,68 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<configuration>
-    <appender name="consoleLog" class="ch.qos.logback.core.ConsoleAppender">
-        <layout class="ch.qos.logback.classic.PatternLayout">
-            <pattern>
-                %d{HH:mm:ss.SSS} [%thread] %-5level %c %M %L - %msg%n
-            </pattern>
-        </layout>
-    </appender>
-
-    <!-- info 日志文件 -->
-    <appender name="fileInfoLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
-        <filter class="ch.qos.logback.classic.filter.LevelFilter">
-            <level>ERROR</level>
-            <onMatch>DENY</onMatch>
-            <onMismatch>ACCEPT</onMismatch>
-        </filter>
-        <encoder>
-            <pattern>
-                %d{HH:mm:ss.SSS} %-5level %c %M %L - %msg%n
-            </pattern>
-            <charset>UTF-8</charset>
-        </encoder>
-        <!-- 滚动策略 -->
-        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
-            <fileNamePattern>
-                logs/info.%d.log
-            </fileNamePattern>
-        </rollingPolicy>
-    </appender>
-
-    <!-- error 日志文件 -->
-    <appender name="fileErrorLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
-        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
-            <level>ERROR</level>
-        </filter>
-        <encoder>
-            <pattern>
-                %d{HH:mm:ss.SSS} %-5level %c %M %L - %msg%n
-            </pattern>
-            <charset>UTF-8</charset>
-        </encoder>
-        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
-            <fileNamePattern>
-                logs/error.%d.log
-            </fileNamePattern>
-        </rollingPolicy>
-    </appender>
-
-    <springProfile name="dev">
-        <root level="info">
-            <appender-ref ref="consoleLog"></appender-ref>
-        </root>
-    </springProfile>
-    <springProfile name="test">
-        <root level="info">
-            <appender-ref ref="fileInfoLog"></appender-ref>
-            <appender-ref ref="fileErrorLog"></appender-ref>
-        </root>
-    </springProfile>
-    <springProfile name="prod">
-        <root level="info">
-            <appender-ref ref="fileInfoLog"></appender-ref>
-            <appender-ref ref="fileErrorLog"></appender-ref>
-        </root>
-    </springProfile>
-</configuration>

ファイルの差分が大きいため隠しています
+ 0 - 45
dfs-web/src/main/resources/test.json


+ 0 - 23
oss-common/pom.xml

@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0"
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-
-    <groupId>cn.reghao.oss</groupId>
-    <artifactId>oss-common</artifactId>
-    <version>1.0.0-SNAPSHOT</version>
-
-    <properties>
-        <maven.compiler.source>11</maven.compiler.source>
-        <maven.compiler.target>11</maven.compiler.target>
-    </properties>
-
-    <dependencies>
-        <dependency>
-            <groupId>cn.reghao.jutil</groupId>
-            <artifactId>web</artifactId>
-            <version>1.0.0-SNAPSHOT</version>
-        </dependency>
-    </dependencies>
-</project>

+ 0 - 408
oss-common/src/main/java/cn/reghao/oss/common/AWS4Signer.java

@@ -1,408 +0,0 @@
-package cn.reghao.oss.common;
-
-import javax.crypto.Mac;
-import javax.crypto.spec.SecretKeySpec;
-import java.net.URLEncoder;
-import java.nio.charset.StandardCharsets;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.*;
-
-/**
- * Example: Signing AWS Requests with Signature Version 4 in Java.
- *
- * @reference: http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html
- * @author javaQuery
- * @date 19th January, 2016
- * @Github: https://github.com/javaquery/Examples
- */
-public class AWS4Signer {
-    private AWS4Signer() {
-    }
-
-    public static class Builder {
-
-        private String accessKeyID;
-        private String secretAccessKey;
-        private String regionName;
-        private String serviceName;
-        private String xAmzDate;
-        private String httpMethodName;
-        private String canonicalURI;
-        private TreeMap<String, String> queryParametes;
-        private TreeMap<String, String> awsHeaders;
-        private byte[] payload;
-        private String sha256sum;
-
-        public Builder(String accessKeyID, String secretAccessKey) {
-            this.accessKeyID = accessKeyID;
-            this.secretAccessKey = secretAccessKey;
-        }
-
-        public Builder regionName(String regionName) {
-            this.regionName = regionName;
-            return this;
-        }
-
-        public Builder serviceName(String serviceName) {
-            this.serviceName = serviceName;
-            return this;
-        }
-
-        public Builder xAmzDate(String xAmzDate) {
-            this.xAmzDate = xAmzDate;
-            return this;
-        }
-
-        public Builder httpMethodName(String httpMethodName) {
-            this.httpMethodName = httpMethodName;
-            return this;
-        }
-
-        public Builder canonicalURI(String canonicalURI) {
-            this.canonicalURI = canonicalURI;
-            return this;
-        }
-
-        public Builder queryParametes(TreeMap<String, String> queryParametes) {
-            this.queryParametes = queryParametes;
-            return this;
-        }
-
-        public Builder awsHeaders(TreeMap<String, String> awsHeaders) {
-            this.awsHeaders = awsHeaders;
-            return this;
-        }
-
-        public Builder payload(byte[] payload) {
-            this.payload = payload;
-            return this;
-        }
-
-        public Builder sha256sum(String sha256sum) {
-            this.sha256sum = sha256sum;
-            return this;
-        }
-
-        public AWS4Signer build() {
-            return new AWS4Signer(this);
-        }
-    }
-
-    private String accessKeyID;
-    private String secretAccessKey;
-    private String regionName;
-    private String serviceName;
-    private String httpMethodName;
-    private String canonicalURI;
-    private TreeMap<String, String> queryParametes;
-    private TreeMap<String, String> awsHeaders;
-    private byte[] payload;
-    private String sha256sum;
-
-    /* Other variables */
-    private final String HMACAlgorithm = "AWS4-HMAC-SHA256";
-    private final String aws4Request = "aws4_request";
-    private String strSignedHeader;
-    private String xAmzDate;
-    private String currentDate;
-
-    private AWS4Signer(Builder builder) {
-        accessKeyID = builder.accessKeyID;
-        secretAccessKey = builder.secretAccessKey;
-        regionName = builder.regionName;
-        serviceName = builder.serviceName;
-        httpMethodName = builder.httpMethodName;
-        canonicalURI = builder.canonicalURI;
-        queryParametes = builder.queryParametes;
-        awsHeaders = builder.awsHeaders;
-        payload = builder.payload;
-        sha256sum = builder.sha256sum;
-
-        /* Get current timestamp value.(UTC) */
-        //xAmzDate = getTimeStamp();
-        xAmzDate = builder.xAmzDate;
-        currentDate = getDate();
-    }
-
-    /**
-     * Task 1: Create a Canonical Request for Signature Version 4.
-     *
-     * @return
-     */
-    private String prepareCanonicalRequest() {
-        StringBuilder canonicalURL = new StringBuilder("");
-
-        /* Step 1.1 Start with the HTTP request method (GET, PUT, POST, etc.), followed by a newline character. */
-        canonicalURL.append(httpMethodName).append("\n");
-
-        /* Step 1.2 Add the canonical URI parameter, followed by a newline character. */
-        canonicalURI = canonicalURI == null || canonicalURI.trim().isEmpty() ? "/" : canonicalURI;
-        canonicalURL.append(canonicalURI).append("\n");
-
-        /* Step 1.3 Add the canonical query string, followed by a newline character. */
-        StringBuilder queryString = new StringBuilder("");
-        if (queryParametes != null && !queryParametes.isEmpty()) {
-            for (Map.Entry<String, String> entrySet : queryParametes.entrySet()) {
-                String key = entrySet.getKey();
-                String value = entrySet.getValue();
-                queryString.append(key).append("=").append(encodeParameter(value)).append("&");
-            }
-
-            /* @co-author https://github.com/dotkebi @git #1 @date 16th March, 2017 */
-            queryString.deleteCharAt(queryString.lastIndexOf("&"));
-
-            queryString.append("\n");
-        } else {
-            queryString.append("\n");
-        }
-        canonicalURL.append(queryString);
-
-        /* Step 1.4 Add the canonical headers, followed by a newline character. */
-        StringBuilder signedHeaders = new StringBuilder("");
-        if (awsHeaders != null && !awsHeaders.isEmpty()) {
-            for (Map.Entry<String, String> entrySet : awsHeaders.entrySet()) {
-                String key = entrySet.getKey();
-                String value = entrySet.getValue();
-                signedHeaders.append(key).append(";");
-                canonicalURL.append(key).append(":").append(value).append("\n");
-            }
-
-            /* Note: Each individual header is followed by a newline character, meaning the complete list ends with a newline character. */
-            canonicalURL.append("\n");
-        } else {
-            canonicalURL.append("\n");
-        }
-
-        /* Step 1.5 Add the signed headers, followed by a newline character. */
-        strSignedHeader = signedHeaders.substring(0, signedHeaders.length() - 1); // Remove last ";"
-        canonicalURL.append(strSignedHeader).append("\n");
-
-        /* Step 1.6 Use a hash (digest) function like SHA256 to create a hashed value from the payload in the body of the HTTP or HTTPS. */
-        canonicalURL.append(sha256sum);
-        /*payload = payload == null ? "UNSIGNED-PAYLOAD".getBytes(StandardCharsets.UTF_8) : payload;
-        try {
-            String sha256Hex = DigestUtil.sha256sum(payload);
-            canonicalURL.append(sha256Hex);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }*/
-
-        return canonicalURL.toString();
-    }
-
-    /**
-     * Task 2: Create a String to Sign for Signature Version 4.
-     *
-     * @param canonicalURL
-     * @return
-     */
-    private String createStringToSign(String canonicalURL) {
-        String stringToSign = "";
-
-        /* Step 2.1 Start with the algorithm designation, followed by a newline character. */
-        stringToSign = HMACAlgorithm + "\n";
-
-        /* Step 2.2 Append the request date value, followed by a newline character. */
-        stringToSign += xAmzDate + "\n";
-
-        /* Step 2.3 Append the credential scope value, followed by a newline character. */
-        stringToSign += currentDate + "/" + regionName + "/" + serviceName + "/" + aws4Request + "\n";
-
-        /* Step 2.4 Append the hash of the canonical request that you created in Task 1: Create a Canonical Request for Signature Version 4. */
-        stringToSign += generateHex(canonicalURL);
-        return stringToSign;
-    }
-
-    /**
-     * Task 3: Calculate the AWS Signature Version 4.
-     *
-     * @param stringToSign
-     * @return
-     */
-    private String calculateSignature(String stringToSign) {
-        try {
-            /* Step 3.1 Derive your signing key */
-            byte[] signatureKey = getSignatureKey(secretAccessKey, currentDate, regionName, serviceName);
-
-            /* Step 3.2 Calculate the signature. */
-            byte[] signature = HmacSHA256(signatureKey, stringToSign);
-
-            /* Step 3.2.1 Encode signature (byte[]) to Hex */
-            String strHexSignature = bytesToHex(signature);
-            return strHexSignature;
-        } catch (Exception ex) {
-            ex.printStackTrace();
-        }
-        return null;
-    }
-
-    /**
-     * Task 4: Add the Signing Information to the Request. We'll return Map of
-     * all headers put this headers in your request.
-     *
-     * @return
-     */
-    public Map<String, String> getHeaders() {
-        awsHeaders.put("x-amz-date", xAmzDate);
-
-        /* Execute Task 1: Create a Canonical Request for Signature Version 4. */
-        String canonicalURL = prepareCanonicalRequest();
-
-        /* Execute Task 2: Create a String to Sign for Signature Version 4. */
-        String stringToSign = createStringToSign(canonicalURL);
-
-        /* Execute Task 3: Calculate the AWS Signature Version 4. */
-        String signature = calculateSignature(stringToSign);
-        if (signature != null) {
-            Map<String, String> header = new HashMap<>(0);
-            header.put("x-amz-date", xAmzDate);
-            header.put("Authorization", buildAuthorizationString(signature));
-            return header;
-        } else {
-            return null;
-        }
-    }
-
-    public String getSignature() {
-        /* Execute Task 1: Create a Canonical Request for Signature Version 4. */
-        String canonicalURL = prepareCanonicalRequest();
-
-        /* Execute Task 2: Create a String to Sign for Signature Version 4. */
-        String stringToSign = createStringToSign(canonicalURL);
-
-        /* Execute Task 3: Calculate the AWS Signature Version 4. */
-        String signature = calculateSignature(stringToSign);
-        return signature;
-    }
-
-    /**
-     * Build string for Authorization header.
-     *
-     * @param strSignature
-     * @return
-     */
-    private String buildAuthorizationString(String strSignature) {
-        return HMACAlgorithm + " "
-                + "Credential=" + accessKeyID + "/" + getDate() + "/" + regionName + "/" + serviceName + "/" + aws4Request + ","
-                + "SignedHeaders=" + strSignedHeader + ","
-                + "Signature=" + strSignature;
-    }
-
-    /**
-     * Generate Hex code of String.
-     *
-     * @param data
-     * @return
-     */
-    private String generateHex(String data) {
-        MessageDigest messageDigest;
-        try {
-            messageDigest = MessageDigest.getInstance("SHA-256");
-            messageDigest.update(data.getBytes(StandardCharsets.UTF_8));
-            byte[] digest = messageDigest.digest();
-            return String.format("%064x", new java.math.BigInteger(1, digest));
-        } catch (NoSuchAlgorithmException e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
-
-    /**
-     * Apply HmacSHA256 on data using given key.
-     *
-     * @param data
-     * @param key
-     * @return
-     * @throws Exception
-     * @reference:
-     * http://docs.aws.amazon.com/general/latest/gr/signature-v4-examples.html#signature-v4-examples-java
-     */
-    private byte[] HmacSHA256(byte[] key, String data) throws Exception {
-        String algorithm = "HmacSHA256";
-        Mac mac = Mac.getInstance(algorithm);
-        mac.init(new SecretKeySpec(key, algorithm));
-        return mac.doFinal(data.getBytes(StandardCharsets.UTF_8));
-    }
-
-    /**
-     * Generate AWS signature key.
-     *
-     * @param key
-     * @param date
-     * @param regionName
-     * @param serviceName
-     * @return
-     * @throws Exception
-     * @reference
-     * http://docs.aws.amazon.com/general/latest/gr/signature-v4-examples.html#signature-v4-examples-java
-     */
-    private byte[] getSignatureKey(String key, String date, String regionName, String serviceName) throws Exception {
-        byte[] kSecret = ("AWS4" + key).getBytes(StandardCharsets.UTF_8);
-        byte[] kDate = HmacSHA256(kSecret, date);
-        byte[] kRegion = HmacSHA256(kDate, regionName);
-        byte[] kService = HmacSHA256(kRegion, serviceName);
-        byte[] kSigning = HmacSHA256(kService, aws4Request);
-        return kSigning;
-    }
-
-    final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
-
-    /**
-     * Convert byte array to Hex
-     *
-     * @param bytes
-     * @return
-     */
-    private String bytesToHex(byte[] bytes) {
-        char[] hexChars = new char[bytes.length * 2];
-        for (int j = 0; j < bytes.length; j++) {
-            int v = bytes[j] & 0xFF;
-            hexChars[j * 2] = hexArray[v >>> 4];
-            hexChars[j * 2 + 1] = hexArray[v & 0x0F];
-        }
-        return new String(hexChars).toLowerCase();
-    }
-
-    /**
-     * Get timestamp. yyyyMMdd'T'HHmmss'Z'
-     *
-     * @return
-     */
-    private String getTimeStamp() {
-        DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
-        dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));//server timezone
-        return dateFormat.format(new Date());
-    }
-
-    /**
-     * Get date. yyyyMMdd
-     *
-     * @return
-     */
-    private String getDate() {
-        DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
-        dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));//server timezone
-        return dateFormat.format(new Date());
-    }
-
-    /**
-     * Using {@link URLEncoder#encode(String, String) } instead of
-     * {@link URLEncoder#encode(String) }
-     *
-     * @co-author https://github.com/dotkebi
-     * @date 16th March, 2017
-     * @git #1
-     * @param param
-     * @return
-     */
-    private String encodeParameter(String param){
-        try {
-            return URLEncoder.encode(param, StandardCharsets.UTF_8);
-        } catch (Exception e) {
-            return URLEncoder.encode(param, StandardCharsets.UTF_8);
-        }
-    }
-}

+ 0 - 154
oss-common/src/main/java/cn/reghao/oss/common/OssUtil.java

@@ -1,154 +0,0 @@
-package cn.reghao.oss.common;
-
-import cn.reghao.jutil.web.ServletUtil;
-
-import javax.crypto.Mac;
-import javax.crypto.spec.SecretKeySpec;
-import javax.servlet.http.HttpServletRequest;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.net.URLDecoder;
-import java.nio.charset.StandardCharsets;
-import java.util.TreeMap;
-
-/**
- * @author reghao
- * @date 2023-03-24 13:46:08
- */
-public class OssUtil {
-    public static String getObjectName() {
-        String uri = ServletUtil.getRequest().getRequestURI();
-        String decodedUri = URLDecoder.decode(uri, StandardCharsets.UTF_8);
-        return decodedUri.replaceFirst("/", "");
-    }
-
-    public static String getAccessKey() {
-        HttpServletRequest servletRequest = ServletUtil.getRequest();
-        String authorization = servletRequest.getHeader("authorization");
-        String[] auths = authorization.split(",");
-        String credential = auths[0].replace("AWS4-HMAC-SHA256 ", "").split("=")[1];
-        String[] strs = credential.split("/");
-        String accessKey = strs[0];
-        return accessKey;
-    }
-
-    public static boolean matchSignature(String secretKey, File file) throws IOException {
-        HttpServletRequest servletRequest = ServletUtil.getRequest();
-        String host = servletRequest.getHeader("host");
-        String contentType = servletRequest.getHeader("content-type");
-        String contentMd5 = servletRequest.getHeader("content-md5");
-        String sha256sum = servletRequest.getHeader("x-amz-content-sha256");
-        String date = servletRequest.getHeader("x-amz-date");
-
-        String authorization = servletRequest.getHeader("authorization");
-        String[] auths = authorization.split(",");
-        String credential = auths[0].replace("AWS4-HMAC-SHA256 ", "").split("=")[1];
-        String[] strs = credential.split("/");
-        String accessKey = strs[0];
-        String date1 = strs[1];
-        String region = strs[2];
-        String service = strs[3];
-        String version = strs[4];
-
-        String[] signedHeaders = auths[1].split("=")[1].split(";");
-        String signature = auths[2].split("=")[1];
-
-        String xAmzDate = servletRequest.getHeader("x-amz-date");
-        TreeMap<String, String> awsHeaders = new TreeMap<>();
-        for (String name : signedHeaders) {
-            servletRequest.getHeader(name);
-            awsHeaders.put(name, servletRequest.getHeader(name));
-        }
-
-        FileInputStream fis = new FileInputStream(file);
-        String method = servletRequest.getMethod();
-        String uri = servletRequest.getRequestURI();
-        AWS4Signer aWSV4Signer = new AWS4Signer.Builder(accessKey, secretKey)
-                .regionName(region)
-                .serviceName(service)
-                .xAmzDate(xAmzDate)
-                .httpMethodName(method)
-                .canonicalURI(uri)
-                .queryParametes(null)
-                .awsHeaders(awsHeaders)
-                .payload(fis.readAllBytes())
-                .build();
-
-        String signature1 = aWSV4Signer.getSignature();
-        return signature.equals(signature1);
-    }
-
-    public static boolean matchSignature(String secretKey, String sha256sum) throws IOException {
-        HttpServletRequest servletRequest = ServletUtil.getRequest();
-        String host = servletRequest.getHeader("host");
-        String contentType = servletRequest.getHeader("content-type");
-        String contentMd5 = servletRequest.getHeader("content-md5");
-        String date = servletRequest.getHeader("x-amz-date");
-
-        String authorization = servletRequest.getHeader("authorization");
-        String[] auths = authorization.split(",");
-        String credential = auths[0].replace("AWS4-HMAC-SHA256 ", "").split("=")[1];
-        String[] strs = credential.split("/");
-        String accessKey = strs[0];
-        String date1 = strs[1];
-        String region = strs[2];
-        String service = strs[3];
-        String version = strs[4];
-
-        String[] signedHeaders = auths[1].split("=")[1].split(";");
-        String signature = auths[2].split("=")[1];
-
-        String xAmzDate = servletRequest.getHeader("x-amz-date");
-        TreeMap<String, String> awsHeaders = new TreeMap<>();
-        for (String name : signedHeaders) {
-            servletRequest.getHeader(name);
-            awsHeaders.put(name, servletRequest.getHeader(name));
-        }
-
-        //FileInputStream fis = new FileInputStream(file);
-        String method = servletRequest.getMethod();
-        String uri = servletRequest.getRequestURI();
-        AWS4Signer aWSV4Signer = new AWS4Signer.Builder(accessKey, secretKey)
-                .regionName(region)
-                .serviceName(service)
-                .xAmzDate(xAmzDate)
-                .httpMethodName(method)
-                .canonicalURI(uri)
-                .queryParametes(null)
-                .awsHeaders(awsHeaders)
-                //.payload(fis.readAllBytes())
-                .sha256sum(sha256sum)
-                .build();
-
-        String signature1 = aWSV4Signer.getSignature();
-        return signature.equals(signature1);
-    }
-
-    public static byte[] getSigningKey(String secretAccessKey, String date, String regionName, String serviceName) throws Exception {
-        byte[] kSecret = ("AWS4" + secretAccessKey).getBytes(StandardCharsets.UTF_8);
-        byte[] kDate = hmacSha256(kSecret, date);
-        byte[] kRegion = hmacSha256(kDate, regionName);
-        byte[] kService = hmacSha256(kRegion, serviceName);
-        byte[] kSigning = hmacSha256(kService, "aws4_request");
-        return kSigning;
-    }
-
-    public static byte[] hmacSha256(byte[] key, String data) throws Exception {
-        String algorithm = "HmacSHA256";
-        Mac mac = Mac.getInstance(algorithm);
-        mac.init(new SecretKeySpec(key, algorithm));
-        return mac.doFinal(data.getBytes(StandardCharsets.UTF_8));
-    }
-
-    final static char[] hexArray = "0123456789ABCDEF".toCharArray();
-    public static String bytesToHex(byte[] bytes) {
-        char[] hexChars = new char[bytes.length * 2];
-        for (int j = 0; j < bytes.length; j++) {
-            int v = bytes[j] & 0xFF;
-            hexChars[j * 2] = hexArray[v >>> 4];
-            hexChars[j * 2 + 1] = hexArray[v & 0x0F];
-        }
-        return new String(hexChars).toLowerCase();
-    }
-}

この差分においてかなりの量のファイルが変更されているため、一部のファイルを表示していません