增加LoginUserContextHolder获取当前登录人对象

This commit is contained in:
zhult13
2022-06-26 23:14:54 +08:00
parent 6e27f055f4
commit 1c15c0ac63
9 changed files with 168 additions and 38 deletions
+9
View File
@@ -20,10 +20,19 @@ http://localhost:8093/test/notAuth
 
### 3.2. 测试接口二
通过 @LoginUser 获取当前登录人
http://localhost:8093/test/auth?access_token=xxx
> - xxx 需替换为正确的 access_token
> - 可以通过修改 `bootstrap.yml` 文件中的 `zlt.security.ignore.httpUrls` 参数添加排除校验的url。
 
### 3.3. 测试接口三
通过 LoginUserContextHolder 获取当前登录人
http://localhost:8093/test/auth2?access_token=xxx
> - xxx 需替换为正确的 access_token
 
## 四、获取access_token
可使用任意授权模式获取;
+4
View File
@@ -15,6 +15,10 @@
<groupId>com.zlt</groupId>
<artifactId>zlt-config</artifactId>
</dependency>
<dependency>
<groupId>com.zlt</groupId>
<artifactId>zlt-common-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.zlt</groupId>
<artifactId>zlt-auth-client-spring-boot-starter</artifactId>
@@ -1,6 +1,7 @@
package org.zlt.controller;
import com.central.common.annotation.LoginUser;
import com.central.common.context.LoginUserContextHolder;
import com.central.common.model.SysUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
@@ -16,11 +17,22 @@ import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
public class TestController {
/**
* 通过 @LoginUser 获取当前登录人
*/
@GetMapping("/test/auth")
public String auth(@LoginUser SysUser user) {
return "auth:" + user.getUsername();
}
/**
* 通过 LoginUserContextHolder 获取当前登录人
*/
@GetMapping("/test/auth2")
public String auth() {
return "auth2:" + LoginUserContextHolder.getUser().getUsername();
}
@GetMapping("/test/notAuth")
public String notAuth() {
return "notAuth:ok";