diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/controller/LoginController.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/controller/LoginController.java index 5a2bf7f0c4..e1c4708742 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/controller/LoginController.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/controller/LoginController.java @@ -39,7 +39,6 @@ public class LoginController { @GetMapping(value = "/is-login") @Operation(summary = "是否登录") public ResultHolder isLogin(HttpServletResponse response) throws Exception { - RsaKey rsaKey = RsaUtil.getRsaKey(); SessionUser user = SessionUtils.getUser(); if (user != null) { UserDTO userDTO = baseUserService.getUserDTO(user.getId()); @@ -57,7 +56,14 @@ public class LoginController { return ResultHolder.success(sessionUser); } response.setStatus(HttpStatus.UNAUTHORIZED.value()); - return ResultHolder.error(MsHttpResultCode.UNAUTHORIZED.getCode(), rsaKey.getPublicKey()); + return ResultHolder.error(MsHttpResultCode.UNAUTHORIZED.getCode(), null); + } + + @GetMapping(value = "/get-key") + @Operation(summary = "获取公钥") + public ResultHolder getKey(HttpServletResponse response) throws Exception { + RsaKey rsaKey = RsaUtil.getRsaKey(); + return ResultHolder.success(rsaKey.getPublicKey()); } @PostMapping(value = "/login") diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/user/UserControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/user/UserControllerTests.java index 01691d179c..a3be8028d2 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/user/UserControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/user/UserControllerTests.java @@ -986,6 +986,12 @@ public class UserControllerTests extends BaseTest { this.testUserRegisterError(); } + @Test + @Order(14) + public void testGetKey() throws Exception { + this.requestGetWithOk("/get-key"); + } + //本测试类中会用到很多次用户数据。所以测试删除的方法放于最后 @Test @Order(99)