|
|
|
@ -10,7 +10,11 @@ import com.yau.digitalrmb.shared.api.ApiResponse;
|
|
|
|
import com.yau.digitalrmb.shared.api.ErrorCode;
|
|
|
|
import com.yau.digitalrmb.shared.api.ErrorCode;
|
|
|
|
import com.yau.digitalrmb.shared.exception.BusinessException;
|
|
|
|
import com.yau.digitalrmb.shared.exception.BusinessException;
|
|
|
|
import com.yau.digitalrmb.shared.web.TraceIdFilter;
|
|
|
|
import com.yau.digitalrmb.shared.web.TraceIdFilter;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
|
import javax.validation.Valid;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
import org.slf4j.MDC;
|
|
|
|
import org.slf4j.MDC;
|
|
|
|
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
|
|
|
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
|
|
|
import org.springframework.security.oauth2.jwt.Jwt;
|
|
|
|
import org.springframework.security.oauth2.jwt.Jwt;
|
|
|
|
@ -26,6 +30,7 @@ import java.util.Collections;
|
|
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("/api/v1/auth")
|
|
|
|
@RequestMapping("/api/v1/auth")
|
|
|
|
|
|
|
|
@Tag(name = "用户登录及权限认证")
|
|
|
|
public class AuthController {
|
|
|
|
public class AuthController {
|
|
|
|
private final JwtTokenService tokenService;
|
|
|
|
private final JwtTokenService tokenService;
|
|
|
|
private final LoginExchangeCodeService exchangeCodeService;
|
|
|
|
private final LoginExchangeCodeService exchangeCodeService;
|
|
|
|
@ -44,6 +49,7 @@ public class AuthController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/login")
|
|
|
|
@PostMapping("/login")
|
|
|
|
|
|
|
|
@Operation(description = "用户登录")
|
|
|
|
public ApiResponse<LoginResponse> login(@Valid @RequestBody LoginRequest request) {
|
|
|
|
public ApiResponse<LoginResponse> login(@Valid @RequestBody LoginRequest request) {
|
|
|
|
JwtTokenService.Token token = localAccountAuthenticationService.login(request.username(), request.password());
|
|
|
|
JwtTokenService.Token token = localAccountAuthenticationService.login(request.username(), request.password());
|
|
|
|
return ApiResponse.success(new LoginResponse(token.accessToken(), "Bearer", token.expiresIn()),
|
|
|
|
return ApiResponse.success(new LoginResponse(token.accessToken(), "Bearer", token.expiresIn()),
|
|
|
|
@ -65,7 +71,9 @@ public class AuthController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/me")
|
|
|
|
@GetMapping("/me")
|
|
|
|
|
|
|
|
@Operation(description = "获取当前登录用户信息")
|
|
|
|
public ApiResponse<CurrentUserResponse> currentUser(@AuthenticationPrincipal Jwt jwt) {
|
|
|
|
public ApiResponse<CurrentUserResponse> currentUser(@AuthenticationPrincipal Jwt jwt) {
|
|
|
|
|
|
|
|
//todo 需要调整用户返回信息,具体返回数据参考旧系统
|
|
|
|
long platformUserId = platformUserId(jwt);
|
|
|
|
long platformUserId = platformUserId(jwt);
|
|
|
|
PlatformUserSnapshotEntity snapshot = snapshotMapper.selectById(platformUserId);
|
|
|
|
PlatformUserSnapshotEntity snapshot = snapshotMapper.selectById(platformUserId);
|
|
|
|
if (snapshot == null) {
|
|
|
|
if (snapshot == null) {
|
|
|
|
@ -76,6 +84,7 @@ public class AuthController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/logout")
|
|
|
|
@PostMapping("/logout")
|
|
|
|
|
|
|
|
@Operation(description = "登出")
|
|
|
|
public ApiResponse<Void> logout(@AuthenticationPrincipal Jwt jwt, @Valid @RequestBody LogoutRequest request) {
|
|
|
|
public ApiResponse<Void> logout(@AuthenticationPrincipal Jwt jwt, @Valid @RequestBody LogoutRequest request) {
|
|
|
|
refreshTokenService.revokeForUser(request.refreshToken(), platformUserId(jwt));
|
|
|
|
refreshTokenService.revokeForUser(request.refreshToken(), platformUserId(jwt));
|
|
|
|
return ApiResponse.success(null, MDC.get(TraceIdFilter.MDC_KEY));
|
|
|
|
return ApiResponse.success(null, MDC.get(TraceIdFilter.MDC_KEY));
|
|
|
|
|