Skip to content

Commit

Permalink
🎉 4.0.0.RELEASE 升级 SpringBoot3 SpringCloud2023 JDK17
Browse files Browse the repository at this point in the history
  • Loading branch information
smallchill committed Apr 21, 2024
1 parent 15359e5 commit 31b94c2
Show file tree
Hide file tree
Showing 155 changed files with 1,073 additions and 1,203 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<p align="center">
<img src="https://img.shields.io/badge/Release-V3.7.1-green.svg" alt="Downloads">
<img src="https://img.shields.io/badge/JDK-1.8+-green.svg" alt="Build Status">
<img src="https://img.shields.io/badge/Release-V4.0.0-green.svg" alt="Downloads">
<img src="https://img.shields.io/badge/JDK-17+-green.svg" alt="Build Status">
<img src="https://img.shields.io/badge/license-Apache%202-blue.svg" alt="Build Status">
<img src="https://img.shields.io/badge/Spring%20Cloud-2021-blue.svg" alt="Coverage Status">
<img src="https://img.shields.io/badge/Spring%20Boot-2.7.18-blue.svg" alt="Downloads">
<img src="https://img.shields.io/badge/Spring%20Cloud-2023-blue.svg" alt="Coverage Status">
<img src="https://img.shields.io/badge/Spring%20Boot-3.2-blue.svg" alt="Downloads">
<a target="_blank" href="https://bladex.cn">
<img src="https://img.shields.io/badge/Author-Small%20Chill-ff69b4.svg" alt="Downloads">
</a>
Expand Down
6 changes: 3 additions & 3 deletions blade-auth/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM anapsix/alpine-java:8_server-jre_unlimited
FROM bladex/alpine-java:openjdk17_cn_slim

MAINTAINER smallchill@163.com
MAINTAINER bladejava@qq.com

RUN mkdir -p /blade/auth

Expand All @@ -10,6 +10,6 @@ EXPOSE 8010

ADD ./target/blade-auth.jar ./app.jar

ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "app.jar"]
ENTRYPOINT ["java", "--add-opens java.base/java.lang.reflect=ALL-UNNAMED", "-Djava.security.egd=file:/dev/./urandom", "-jar", "app.jar"]

CMD ["--spring.profiles.active=test"]
23 changes: 3 additions & 20 deletions blade-auth/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<artifactId>SpringBlade</artifactId>
<groupId>org.springblade</groupId>
<version>3.7.1</version>
<version>4.0.0</version>
</parent>

<artifactId>blade-auth</artifactId>
Expand Down Expand Up @@ -61,9 +61,8 @@
</dependency>
<!-- MySQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.connector.version}</version>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -93,22 +92,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<!--suppress UnresolvedMavenProperty -->
<copy overwrite="true"
tofile="${session.executionRootDirectory}/target/${artifactId}.jar"
file="${project.build.directory}/${artifactId}.jar" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
package org.springblade.auth.controller;

import com.wf.captcha.SpecCaptcha;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.AllArgsConstructor;
import org.springblade.auth.granter.ITokenGranter;
import org.springblade.auth.granter.TokenGranterBuilder;
Expand Down Expand Up @@ -47,18 +47,18 @@
*/
@RestController
@AllArgsConstructor
@Api(value = "用户授权认证", tags = "授权接口")
@Tag(name = "用户授权认证", description = "授权接口")
public class AuthController {

private RedisUtil redisUtil;

@PostMapping("token")
@ApiOperation(value = "获取认证token", notes = "传入租户ID:tenantId,账号:account,密码:password")
public R<AuthInfo> token(@ApiParam(value = "授权类型", required = true) @RequestParam(defaultValue = "password", required = false) String grantType,
@ApiParam(value = "刷新令牌") @RequestParam(required = false) String refreshToken,
@ApiParam(value = "租户ID", required = true) @RequestParam(defaultValue = "000000", required = false) String tenantId,
@ApiParam(value = "账号") @RequestParam(required = false) String account,
@ApiParam(value = "密码") @RequestParam(required = false) String password) {
@Operation(summary = "获取认证token", description = "传入租户ID:tenantId,账号:account,密码:password")
public R<AuthInfo> token(@Parameter(name = "授权类型", required = true) @RequestParam(defaultValue = "password", required = false) String grantType,
@Parameter(name = "刷新令牌") @RequestParam(required = false) String refreshToken,
@Parameter(name = "租户ID", required = true) @RequestParam(defaultValue = "000000", required = false) String tenantId,
@Parameter(name = "账号") @RequestParam(required = false) String account,
@Parameter(name = "密码") @RequestParam(required = false) String password) {

String userType = Func.toStr(WebUtil.getRequest().getHeader(TokenUtil.USER_TYPE_HEADER_KEY), TokenUtil.DEFAULT_USER_TYPE);

Expand All @@ -81,7 +81,7 @@ public R<AuthInfo> token(@ApiParam(value = "授权类型", required = true) @Req
}

@GetMapping("/captcha")
@ApiOperation(value = "获取验证码")
@Operation(summary = "获取验证码")
public R<Kv> captcha() {
SpecCaptcha specCaptcha = new SpecCaptcha(130, 48, 5);
String verCode = specCaptcha.text().toLowerCase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package org.springblade.auth.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.zhyd.oauth.model.AuthCallback;
Expand All @@ -30,7 +30,7 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
Expand All @@ -42,15 +42,15 @@
@RestController
@AllArgsConstructor
@ConditionalOnProperty(value = "social.enabled", havingValue = "true")
@Api(value = "第三方登陆", tags = "第三方登陆端点")
@Tag(name = "第三方登陆", description = "第三方登陆端点")
public class SocialController {

private final SocialProperties socialProperties;

/**
* 授权完毕跳转
*/
@ApiOperation(value = "授权完毕跳转")
@Operation(summary = "授权完毕跳转")
@RequestMapping("/oauth/render/{source}")
public void renderAuth(@PathVariable("source") String source, HttpServletResponse response) throws IOException {
AuthRequest authRequest = SocialUtil.getAuthRequest(source, socialProperties);
Expand All @@ -61,7 +61,7 @@ public void renderAuth(@PathVariable("source") String source, HttpServletRespons
/**
* 获取认证信息
*/
@ApiOperation(value = "获取认证信息")
@Operation(summary = "获取认证信息")
@RequestMapping("/oauth/callback/{source}")
public Object login(@PathVariable("source") String source, AuthCallback callback) {
AuthRequest authRequest = SocialUtil.getAuthRequest(source, socialProperties);
Expand All @@ -71,7 +71,7 @@ public Object login(@PathVariable("source") String source, AuthCallback callback
/**
* 撤销授权
*/
@ApiOperation(value = "撤销授权")
@Operation(summary = "撤销授权")
@RequestMapping("/oauth/revoke/{source}/{token}")
public Object revokeAuth(@PathVariable("source") String source, @PathVariable("token") String token) {
AuthRequest authRequest = SocialUtil.getAuthRequest(source, socialProperties);
Expand All @@ -81,7 +81,7 @@ public Object revokeAuth(@PathVariable("source") String source, @PathVariable("t
/**
* 续期accessToken
*/
@ApiOperation(value = "续期令牌")
@Operation(summary = "续期令牌")
@RequestMapping("/oauth/refresh/{source}")
public Object refreshAuth(@PathVariable("source") String source, String token) {
AuthRequest authRequest = SocialUtil.getAuthRequest(source, socialProperties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.springblade.system.user.feign.IUserClient;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;

/**
* 验证码TokenGranter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.springblade.system.user.feign.IUserClient;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequest;
import java.util.Objects;

/**
Expand Down Expand Up @@ -79,7 +79,7 @@ public UserInfo grant(TokenParameter tokenParameter) {
}

// 组装数据
UserOauth userOauth = Objects.requireNonNull(BeanUtil.copy(authUser, UserOauth.class));
UserOauth userOauth = Objects.requireNonNull(BeanUtil.copyProperties(authUser, UserOauth.class));
userOauth.setSource(authUser.getSource());
userOauth.setTenantId(tenantId);
userOauth.setUuid(authUser.getUuid());
Expand Down
2 changes: 1 addition & 1 deletion blade-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>SpringBlade</artifactId>
<groupId>org.springblade</groupId>
<version>3.7.1</version>
<version>4.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
*/
public interface LauncherConstant {

/**
* nacos 用户名
*/
String NACOS_USERNAME = "nacos";

/**
* nacos 密码
*/
String NACOS_PASSWORD = "nacos";

/**
* nacos namespace id
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class LauncherServiceImpl implements LauncherService {
@Override
public void launcher(SpringApplicationBuilder builder, String appName, String profile) {
Properties props = System.getProperties();
PropsUtil.setProperty(props, "spring.cloud.nacos.username", LauncherConstant.NACOS_USERNAME);
PropsUtil.setProperty(props, "spring.cloud.nacos.password", LauncherConstant.NACOS_PASSWORD);
PropsUtil.setProperty(props, "spring.cloud.nacos.discovery.server-addr", LauncherConstant.nacosAddr(profile));
PropsUtil.setProperty(props, "spring.cloud.nacos.config.server-addr", LauncherConstant.nacosAddr(profile));
PropsUtil.setProperty(props, "spring.cloud.sentinel.transport.dashboard", LauncherConstant.sentinelAddr(profile));
Expand Down
6 changes: 3 additions & 3 deletions blade-gateway/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM anapsix/alpine-java:8_server-jre_unlimited
FROM bladex/alpine-java:openjdk17_cn_slim

MAINTAINER smallchill@163.com
MAINTAINER bladejava@qq.com

RUN mkdir -p /blade/gateway

Expand All @@ -10,6 +10,6 @@ EXPOSE 80

ADD ./target/blade-gateway.jar ./app.jar

ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "app.jar"]
ENTRYPOINT ["java", "--add-opens java.base/java.lang.reflect=ALL-UNNAMED", "-Djava.security.egd=file:/dev/./urandom", "-jar", "app.jar"]

CMD ["--spring.profiles.active=test"]
23 changes: 6 additions & 17 deletions blade-gateway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>SpringBlade</artifactId>
<groupId>org.springblade</groupId>
<version>3.7.1</version>
<version>4.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -69,6 +69,11 @@
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!-- 开启knife4j -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-gateway-spring-boot-starter</artifactId>
</dependency>
<!-- JWT -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
Expand Down Expand Up @@ -107,22 +112,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<!--suppress UnresolvedMavenProperty -->
<copy overwrite="true"
tofile="${session.executionRootDirectory}/target/${artifactId}.jar"
file="${project.build.directory}/${artifactId}.jar" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.lang.NonNull;
import org.springframework.web.server.ResponseStatusException;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.Map;

/**
* 异常处理
*
Expand All @@ -45,43 +45,42 @@ public class ErrorExceptionHandler implements ErrorWebExceptionHandler {

private final ObjectMapper objectMapper;

@NonNull
@Override
public Mono<Void> handle(ServerWebExchange exchange, @NonNull Throwable ex) {
public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) {
ServerHttpRequest request = exchange.getRequest();
ServerHttpResponse response = exchange.getResponse();

if (response.isCommitted()) {
return Mono.error(ex);
}

response.getHeaders().setContentType(MediaType.APPLICATION_JSON);
if (ex instanceof ResponseStatusException) {
response.setStatusCode(((ResponseStatusException) ex).getStatus());
response.setStatusCode(((ResponseStatusException) ex).getStatusCode());
}

return response.writeWith(Mono.fromSupplier(() -> {
DataBufferFactory bufferFactory = response.bufferFactory();
try {
HttpStatus status = HttpStatus.BAD_GATEWAY;
if (ex instanceof ResponseStatusException) {
status = ((ResponseStatusException) ex).getStatus();
int status = 500;
if (response.getStatusCode() != null) {
status = response.getStatusCode().value();
}
return bufferFactory.wrap(objectMapper.writeValueAsBytes(ResponseProvider.response(status.value(), buildMessage(request, ex))));
Map<String, Object> result = ResponseProvider.response(status, this.buildMessage(request, ex));
return bufferFactory.wrap(objectMapper.writeValueAsBytes(result));
} catch (JsonProcessingException e) {
e.printStackTrace();
return bufferFactory.wrap(new byte[0]);
}
}));
}


/**
* 构建异常信息
*/
private String buildMessage(ServerHttpRequest request, Throwable ex) {
String uri = request.getURI().toString();
if (uri.endsWith("doc.html")) {
return "[Swagger聚合网关] 已迁移至 [blade-swagger] 服务,请开启 [blade-swagger] 服务并访问 [http://127.0.0.1:18000/doc.html]";
}
StringBuilder message = new StringBuilder("Failed to handle request [");
message.append(request.getMethodValue());
message.append(request.getMethod().name());
message.append(" ");
message.append(request.getURI());
message.append("]");
Expand All @@ -92,4 +91,5 @@ private String buildMessage(ServerHttpRequest request, Throwable ex) {
return message.toString();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class AuthProvider {
DEFAULT_SKIP_URL.add("/token/**");
DEFAULT_SKIP_URL.add("/captcha/**");
DEFAULT_SKIP_URL.add("/actuator/health/**");
DEFAULT_SKIP_URL.add("/v2/api-docs/**");
DEFAULT_SKIP_URL.add("/v3/api-docs/**");
DEFAULT_SKIP_URL.add("/auth/**");
DEFAULT_SKIP_URL.add("/oauth/**");
DEFAULT_SKIP_URL.add("/log/**");
Expand Down
Loading

0 comments on commit 31b94c2

Please sign in to comment.