mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-04 22:41:24 +08:00
Add WebUtil.getLoginUser()
This commit is contained in:
@@ -4,9 +4,8 @@ import com.cfive.pinnacle.entity.User;
|
|||||||
import com.cfive.pinnacle.entity.common.ResponseCode;
|
import com.cfive.pinnacle.entity.common.ResponseCode;
|
||||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||||
import com.cfive.pinnacle.service.permission.ILoginService;
|
import com.cfive.pinnacle.service.permission.ILoginService;
|
||||||
|
import com.cfive.pinnacle.utils.WebUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.core.Authentication;
|
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -40,8 +39,6 @@ public class LoginController {
|
|||||||
|
|
||||||
@GetMapping("/userInfo")
|
@GetMapping("/userInfo")
|
||||||
public ResponseResult getUserInfo() {
|
public ResponseResult getUserInfo() {
|
||||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
return ResponseResult.success(WebUtil.getLoginUser());
|
||||||
Object principal = authentication.getPrincipal();
|
|
||||||
return ResponseResult.success(principal);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
package com.cfive.pinnacle.utils;
|
package com.cfive.pinnacle.utils;
|
||||||
|
|
||||||
|
import com.cfive.pinnacle.entity.User;
|
||||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||||
|
import com.cfive.pinnacle.entity.permission.LoginUser;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@@ -23,4 +27,10 @@ public class WebUtil {
|
|||||||
response.setCharacterEncoding("utf-8");
|
response.setCharacterEncoding("utf-8");
|
||||||
response.getWriter().print(string);
|
response.getWriter().print(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static LoginUser getLoginUser() {
|
||||||
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
|
Object principal = authentication.getPrincipal();
|
||||||
|
return (LoginUser) principal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user