|
|
|
|
@ -9,7 +9,8 @@ import com.yau.digitalrmb.shared.api.ApiResponse;
|
|
|
|
|
import com.yau.digitalrmb.shared.api.ErrorCode;
|
|
|
|
|
import com.yau.digitalrmb.shared.exception.BusinessException;
|
|
|
|
|
import com.yau.digitalrmb.shared.web.TraceIdFilter;
|
|
|
|
|
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.springframework.security.core.annotation.AuthenticationPrincipal;
|
|
|
|
|
import org.springframework.security.oauth2.jwt.Jwt;
|
|
|
|
|
@ -19,8 +20,11 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/api/v1/auth")
|
|
|
|
|
@Tag(name = "用户登录及权限认证")
|
|
|
|
|
public class AuthController {
|
|
|
|
|
private final RefreshTokenService refreshTokenService;
|
|
|
|
|
private final CurrentUserService currentUserService;
|
|
|
|
|
@ -34,6 +38,7 @@ public class AuthController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/login")
|
|
|
|
|
@Operation(description = "用户登录")
|
|
|
|
|
public ApiResponse<LoginResponse> login(@Valid @RequestBody LoginRequest request) {
|
|
|
|
|
JwtTokenService.Token token = localAccountAuthenticationService.login(request.username(), request.password());
|
|
|
|
|
return ApiResponse.success(new LoginResponse(token.accessToken(), "Bearer", token.expiresIn()),
|
|
|
|
|
@ -41,6 +46,7 @@ public class AuthController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/me")
|
|
|
|
|
@Operation(description = "获取当前登录用户信息")
|
|
|
|
|
public ApiResponse<CurrentUserResponse> currentUser() {
|
|
|
|
|
CurrentUser user = currentUserService.getCurrentUser();
|
|
|
|
|
return ApiResponse.success(new CurrentUserResponse(user.getSchoolId(), user.getSchoolName(),
|
|
|
|
|
@ -50,6 +56,7 @@ public class AuthController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/logout")
|
|
|
|
|
@Operation(description = "登出")
|
|
|
|
|
public ApiResponse<Void> logout(@AuthenticationPrincipal Jwt jwt, @Valid @RequestBody LogoutRequest request) {
|
|
|
|
|
refreshTokenService.revokeForUser(request.refreshToken(), userId(jwt));
|
|
|
|
|
return ApiResponse.success(null, MDC.get(TraceIdFilter.MDC_KEY));
|
|
|
|
|
|