From ede96408ab86eedf9b087c9a49bd50ebc82d3df8 Mon Sep 17 00:00:00 2001 From: zixi0825 Date: Sun, 27 Oct 2024 14:01:45 +0800 Subject: [PATCH] [Fix][Server] Fix token expire error (#472) --- .../io/datavines/core/utils/TokenManager.java | 19 +++++++++++-------- .../api/constants/NotificationConstants.java | 16 ++++++++++++++++ .../api/controller/OpenApiController.java | 2 +- .../datavines/server/enums/JobCheckState.java | 1 - .../service/JobExecutionResultService.java | 4 ++-- .../impl/JobExecutionResultServiceImpl.java | 7 +++---- .../server/utils/VerificationUtil.java | 5 +++-- .../view/Main/HomeDetail/Jobs/JobsList.tsx | 2 +- .../src/view/Main/TokenManager/index.tsx | 1 + 9 files changed, 38 insertions(+), 19 deletions(-) diff --git a/datavines-core/src/main/java/io/datavines/core/utils/TokenManager.java b/datavines-core/src/main/java/io/datavines/core/utils/TokenManager.java index 39c0e4474..2e2f51332 100644 --- a/datavines-core/src/main/java/io/datavines/core/utils/TokenManager.java +++ b/datavines-core/src/main/java/io/datavines/core/utils/TokenManager.java @@ -66,17 +66,18 @@ public String generateToken(TokenInfo tokenInfo) { public String generateToken(String token, Long timeOutMillis) { Map claims = new HashMap<>(); + String username = getUsername(token); String password = getPassword(token); if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) { throw new DataVinesServerException("can not get the user info from token"); } - + Long createTime = System.currentTimeMillis(); claims.put(DataVinesConstants.TOKEN_USER_NAME, username); claims.put(DataVinesConstants.TOKEN_USER_PASSWORD, password); - claims.put(DataVinesConstants.TOKEN_CREATE_TIME, System.currentTimeMillis()); + claims.put(DataVinesConstants.TOKEN_CREATE_TIME,createTime); - return toTokenString(timeOutMillis, claims); + return toTokenString(createTime, timeOutMillis, claims); } public String refreshToken(String token) { @@ -87,11 +88,12 @@ public String refreshToken(String token) { public String generateToken(TokenInfo tokenInfo, Long timeOutMillis) { Map claims = new HashMap<>(); + Long createTime = System.currentTimeMillis(); claims.put(DataVinesConstants.TOKEN_USER_NAME, StringUtils.isEmpty(tokenInfo.getUsername()) ? DataVinesConstants.EMPTY : tokenInfo.getUsername()); claims.put(DataVinesConstants.TOKEN_USER_PASSWORD, StringUtils.isEmpty(tokenInfo.getPassword()) ? DataVinesConstants.EMPTY : tokenInfo.getPassword()); - claims.put(DataVinesConstants.TOKEN_CREATE_TIME, System.currentTimeMillis()); + claims.put(DataVinesConstants.TOKEN_CREATE_TIME, createTime); - return toTokenString(timeOutMillis, claims); + return toTokenString(createTime, timeOutMillis, claims); } public String generateContinuousToken(TokenInfo tokenInfo) { @@ -109,11 +111,12 @@ public String generateContinuousToken(TokenInfo tokenInfo) { } private String generate(Map claims) { - return toTokenString(timeout, claims); + return toTokenString(Long.parseLong(claims.get(DataVinesConstants.TOKEN_CREATE_TIME) + DataVinesConstants.EMPTY), timeout, claims); } - public String toTokenString(Long timeOutMillis, Map claims) { - long expiration = Long.parseLong(claims.get(DataVinesConstants.TOKEN_CREATE_TIME) + DataVinesConstants.EMPTY) + timeOutMillis; + public String toTokenString(Long createTime, Long timeOutMillis, Map claims) { + + long expiration = createTime + timeOutMillis*1000; SignatureAlgorithm.valueOf(algorithm); diff --git a/datavines-notification/datavines-notification-api/src/main/java/io/datavines/notification/api/constants/NotificationConstants.java b/datavines-notification/datavines-notification-api/src/main/java/io/datavines/notification/api/constants/NotificationConstants.java index 824a6ef39..9b4d4bb9f 100644 --- a/datavines-notification/datavines-notification-api/src/main/java/io/datavines/notification/api/constants/NotificationConstants.java +++ b/datavines-notification/datavines-notification-api/src/main/java/io/datavines/notification/api/constants/NotificationConstants.java @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package io.datavines.notification.api.constants; public class NotificationConstants { diff --git a/datavines-server/src/main/java/io/datavines/server/api/controller/OpenApiController.java b/datavines-server/src/main/java/io/datavines/server/api/controller/OpenApiController.java index 3ba081f12..0d88319f0 100644 --- a/datavines-server/src/main/java/io/datavines/server/api/controller/OpenApiController.java +++ b/datavines-server/src/main/java/io/datavines/server/api/controller/OpenApiController.java @@ -65,7 +65,7 @@ public Object kill(@PathVariable("executionId") Long executionId) { @ApiOperation(value = "get job execution status", response = String.class) @GetMapping(value = "/job/execution/status/{executionId}") public Object getTaskStatus(@PathVariable("executionId") Long executionId) { - return jobExecutionService.getById(executionId).getStatus().getCode(); + return jobExecutionService.getById(executionId).getStatus(); } @CheckTokenExist diff --git a/datavines-server/src/main/java/io/datavines/server/enums/JobCheckState.java b/datavines-server/src/main/java/io/datavines/server/enums/JobCheckState.java index 17a16820a..09290a6bc 100644 --- a/datavines-server/src/main/java/io/datavines/server/enums/JobCheckState.java +++ b/datavines-server/src/main/java/io/datavines/server/enums/JobCheckState.java @@ -49,7 +49,6 @@ public enum JobCheckState { @Getter private final String zhDescription; - @JsonValue public String getDescription() { return description; } diff --git a/datavines-server/src/main/java/io/datavines/server/repository/service/JobExecutionResultService.java b/datavines-server/src/main/java/io/datavines/server/repository/service/JobExecutionResultService.java index 7f4e2c9d5..ce2d01019 100644 --- a/datavines-server/src/main/java/io/datavines/server/repository/service/JobExecutionResultService.java +++ b/datavines-server/src/main/java/io/datavines/server/repository/service/JobExecutionResultService.java @@ -17,8 +17,8 @@ package io.datavines.server.repository.service; import com.baomidou.mybatisplus.extension.service.IService; -import io.datavines.server.api.dto.vo.JobExecutionCheckResultVO; import io.datavines.server.api.dto.vo.JobExecutionResultVO; +import io.datavines.server.enums.JobCheckState; import io.datavines.server.repository.entity.JobExecutionResult; import java.util.List; @@ -41,7 +41,7 @@ public interface JobExecutionResultService extends IService JobExecutionResultVO getResultVOByJobExecutionId(long jobExecutionId); - int getCheckResultByJobExecutionId(long jobExecutionId); + JobCheckState getCheckResultByJobExecutionId(long jobExecutionId); List getResultVOListByJobExecutionId(long jobExecutionId); diff --git a/datavines-server/src/main/java/io/datavines/server/repository/service/impl/JobExecutionResultServiceImpl.java b/datavines-server/src/main/java/io/datavines/server/repository/service/impl/JobExecutionResultServiceImpl.java index ad92af4a7..c0e2133e6 100644 --- a/datavines-server/src/main/java/io/datavines/server/repository/service/impl/JobExecutionResultServiceImpl.java +++ b/datavines-server/src/main/java/io/datavines/server/repository/service/impl/JobExecutionResultServiceImpl.java @@ -25,7 +25,6 @@ import io.datavines.metric.api.ExpectedValue; import io.datavines.metric.api.ResultFormula; import io.datavines.metric.api.SqlMetric; -import io.datavines.server.api.dto.vo.JobExecutionCheckResultVO; import io.datavines.server.api.dto.vo.JobExecutionResultVO; import io.datavines.server.repository.entity.Job; import io.datavines.server.repository.entity.JobExecution; @@ -102,9 +101,9 @@ public List listByErrorJobExecutionId(long jobExecutionId) { } @Override - public int getCheckResultByJobExecutionId(long jobExecutionId) { + public JobCheckState getCheckResultByJobExecutionId(long jobExecutionId) { - int result = JobCheckState.NONE.getCode(); + JobCheckState result = JobCheckState.NONE; List jobExecutionResultList = listByJobExecutionId(jobExecutionId); if (CollectionUtils.isEmpty(jobExecutionResultList)) { return result; @@ -117,7 +116,7 @@ public int getCheckResultByJobExecutionId(long jobExecutionId) { } } - return JobCheckState.of(resultState).getCode(); + return JobCheckState.of(resultState); } @Override diff --git a/datavines-server/src/main/java/io/datavines/server/utils/VerificationUtil.java b/datavines-server/src/main/java/io/datavines/server/utils/VerificationUtil.java index 8c76cc016..4dd38b82d 100644 --- a/datavines-server/src/main/java/io/datavines/server/utils/VerificationUtil.java +++ b/datavines-server/src/main/java/io/datavines/server/utils/VerificationUtil.java @@ -76,9 +76,10 @@ public static void validVerificationCode(String verificationCode, String verific private static String buildJwtVerification(String verificationCode) { Map claims = new HashMap<>(); + Long createTime = System.currentTimeMillis(); claims.put(DataVinesConstants.TOKEN_VERIFICATION_CODE, verificationCode); - claims.put(DataVinesConstants.TOKEN_CREATE_TIME, System.currentTimeMillis()); - return tokenManager.toTokenString(timeOutMillis, claims); + claims.put(DataVinesConstants.TOKEN_CREATE_TIME, createTime); + return tokenManager.toTokenString(createTime, timeOutMillis, claims); } private static String buildImageByte64(String verificationCode) { diff --git a/datavines-ui/src/view/Main/HomeDetail/Jobs/JobsList.tsx b/datavines-ui/src/view/Main/HomeDetail/Jobs/JobsList.tsx index a31b11ce2..65ec443e8 100644 --- a/datavines-ui/src/view/Main/HomeDetail/Jobs/JobsList.tsx +++ b/datavines-ui/src/view/Main/HomeDetail/Jobs/JobsList.tsx @@ -187,7 +187,7 @@ const Jobs = ({ datasourceId }: TJobs) => { // @ts-ignore const columns: ColumnsType = [ { - title: intl.formatMessage({ id: 'jobs_name' }), + title: intl.formatMessage({ id: 'jobs_id' }), dataIndex: 'id', key: 'id', width: 160, diff --git a/datavines-ui/src/view/Main/TokenManager/index.tsx b/datavines-ui/src/view/Main/TokenManager/index.tsx index 14941a4d7..9e149026e 100644 --- a/datavines-ui/src/view/Main/TokenManager/index.tsx +++ b/datavines-ui/src/view/Main/TokenManager/index.tsx @@ -92,6 +92,7 @@ const Index = () => { title: intl.formatMessage({ id: 'token_token' }), dataIndex: 'token', key: 'token', + width: 300, render: (text: string) =>
{text || '--'}
, }, {