This is an automated email from the ASF dual-hosted git repository.

nicholasjiang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/paimon-webui.git


The following commit(s) were added to refs/heads/main by this push:
     new 593864dc [Improvement] Get the logged in user's id from the so-token 
context (#367)
593864dc is described below

commit 593864dcc965f192c7c98346950dc9fe5190df64
Author: s7monk <[email protected]>
AuthorDate: Thu Jun 13 19:20:56 2024 +0800

    [Improvement] Get the logged in user's id from the so-token context (#367)
---
 .../web/server/controller/SessionController.java       | 18 ++++++++++++++----
 .../web/server/controller/SessionControllerTest.java   |  2 --
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git 
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/SessionController.java
 
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/SessionController.java
index ff2f6412..cee6f61a 100644
--- 
a/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/SessionController.java
+++ 
b/paimon-web-server/src/main/java/org/apache/paimon/web/server/controller/SessionController.java
@@ -21,9 +21,11 @@ package org.apache.paimon.web.server.controller;
 import org.apache.paimon.web.server.data.dto.SessionDTO;
 import org.apache.paimon.web.server.data.model.ClusterInfo;
 import org.apache.paimon.web.server.data.result.R;
+import org.apache.paimon.web.server.data.result.enums.Status;
 import org.apache.paimon.web.server.service.ClusterService;
 import org.apache.paimon.web.server.service.SessionService;
 
+import cn.dev33.satoken.stp.StpUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -51,7 +53,11 @@ public class SessionController {
             value = {Exception.class},
             maxAttempts = 3,
             backoff = @Backoff(delay = 3000))
-    public R<Void> createSession(Integer uid) {
+    public R<Void> createSession() {
+        if (!StpUtil.isLogin()) {
+            return R.failed(Status.UNAUTHORIZED, "User must be logged in to 
access this resource");
+        }
+        int uid = StpUtil.getLoginIdAsInt();
         QueryWrapper<ClusterInfo> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq("type", "Flink");
         List<ClusterInfo> clusterInfos = clusterService.list(queryWrapper);
@@ -67,13 +73,17 @@ public class SessionController {
     }
 
     @Recover
-    public R<Void> recover(Exception e, Integer uid) {
-        log.error("After retries failed to create session for UID: {}", uid, 
e);
+    public R<Void> recover(Exception e) {
+        log.error("After retries failed to create session", e);
         return R.failed();
     }
 
     @PostMapping("/drop")
-    public R<Void> dropSession(Integer uid) {
+    public R<Void> dropSession() {
+        if (!StpUtil.isLogin()) {
+            return R.failed(Status.UNAUTHORIZED, "User must be logged in to 
access this resource");
+        }
+        int uid = StpUtil.getLoginIdAsInt();
         QueryWrapper<ClusterInfo> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq("type", "Flink");
         List<ClusterInfo> clusterInfos = clusterService.list(queryWrapper);
diff --git 
a/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/SessionControllerTest.java
 
b/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/SessionControllerTest.java
index c2bcda4b..e49c0e6f 100644
--- 
a/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/SessionControllerTest.java
+++ 
b/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/SessionControllerTest.java
@@ -134,7 +134,6 @@ public class SessionControllerTest extends 
FlinkSQLGatewayTestBase {
                 mockMvc.perform(
                                 MockMvcRequestBuilders.post(sessionPath + 
"/create")
                                         .cookie(cookie)
-                                        .param("uid", "1")
                                         
.contentType(MediaType.APPLICATION_JSON_VALUE)
                                         
.accept(MediaType.APPLICATION_JSON_VALUE))
                         .andExpect(MockMvcResultMatchers.status().isOk())
@@ -159,7 +158,6 @@ public class SessionControllerTest extends 
FlinkSQLGatewayTestBase {
                 mockMvc.perform(
                                 MockMvcRequestBuilders.post(sessionPath + 
"/drop")
                                         .cookie(cookie)
-                                        .param("uid", "1")
                                         
.contentType(MediaType.APPLICATION_JSON_VALUE)
                                         
.accept(MediaType.APPLICATION_JSON_VALUE))
                         .andExpect(MockMvcResultMatchers.status().isOk())

Reply via email to