去掉shiro框架
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
package com.label.controller;
|
||||
|
||||
import com.label.annotation.RequireAuth;
|
||||
import com.label.common.auth.TokenPrincipal;
|
||||
import com.label.common.result.Result;
|
||||
import com.label.common.shiro.TokenPrincipal;
|
||||
import com.label.dto.LoginRequest;
|
||||
import com.label.dto.LoginResponse;
|
||||
import com.label.dto.UserInfoResponse;
|
||||
@@ -16,9 +17,9 @@ import org.springframework.web.bind.annotation.*;
|
||||
* 认证接口:登录、退出、获取当前用户。
|
||||
*
|
||||
* 路由设计:
|
||||
* - POST /api/auth/login → 匿名(TokenFilter.shouldNotFilter 跳过)
|
||||
* - POST /api/auth/logout → 需要有效 Token(TokenFilter 校验)
|
||||
* - GET /api/auth/me → 需要有效 Token(TokenFilter 校验)
|
||||
* - POST /api/auth/login → 匿名(AuthInterceptor 跳过)
|
||||
* - POST /api/auth/logout → 需要有效 Token(AuthInterceptor 校验)
|
||||
* - GET /api/auth/me → 需要有效 Token(AuthInterceptor 校验)
|
||||
*/
|
||||
@Tag(name = "认证管理", description = "登录、退出和当前用户信息")
|
||||
@RestController
|
||||
@@ -42,6 +43,7 @@ public class AuthController {
|
||||
*/
|
||||
@Operation(summary = "退出登录并立即失效当前 Token")
|
||||
@PostMapping("/logout")
|
||||
@RequireAuth
|
||||
public Result<Void> logout(HttpServletRequest request) {
|
||||
String token = extractToken(request);
|
||||
authService.logout(token);
|
||||
@@ -50,10 +52,11 @@ public class AuthController {
|
||||
|
||||
/**
|
||||
* 获取当前登录用户信息。
|
||||
* TokenPrincipal 由 TokenFilter 写入请求属性 "__token_principal__"。
|
||||
* TokenPrincipal 由 AuthInterceptor 写入请求属性 "__token_principal__"。
|
||||
*/
|
||||
@Operation(summary = "获取当前登录用户信息")
|
||||
@GetMapping("/me")
|
||||
@RequireAuth
|
||||
public Result<UserInfoResponse> me(HttpServletRequest request) {
|
||||
TokenPrincipal principal = (TokenPrincipal) request.getAttribute("__token_principal__");
|
||||
return Result.success(authService.me(principal));
|
||||
|
||||
Reference in New Issue
Block a user