Skip to content

Commit

Permalink
[Fix][Server] Fix token expire error (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
zixi0825 authored Oct 27, 2024
1 parent d74c56b commit ede9640
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,18 @@ public String generateToken(TokenInfo tokenInfo) {

public String generateToken(String token, Long timeOutMillis) {
Map<String, Object> 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) {
Expand All @@ -87,11 +88,12 @@ public String refreshToken(String token) {

public String generateToken(TokenInfo tokenInfo, Long timeOutMillis) {
Map<String, Object> 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) {
Expand All @@ -109,11 +111,12 @@ public String generateContinuousToken(TokenInfo tokenInfo) {
}

private String generate(Map<String, Object> 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<String, Object> claims) {
long expiration = Long.parseLong(claims.get(DataVinesConstants.TOKEN_CREATE_TIME) + DataVinesConstants.EMPTY) + timeOutMillis;
public String toTokenString(Long createTime, Long timeOutMillis, Map<String, Object> claims) {

long expiration = createTime + timeOutMillis*1000;

SignatureAlgorithm.valueOf(algorithm);

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public enum JobCheckState {
@Getter
private final String zhDescription;

@JsonValue
public String getDescription() {
return description;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,7 +41,7 @@ public interface JobExecutionResultService extends IService<JobExecutionResult>

JobExecutionResultVO getResultVOByJobExecutionId(long jobExecutionId);

int getCheckResultByJobExecutionId(long jobExecutionId);
JobCheckState getCheckResultByJobExecutionId(long jobExecutionId);

List<JobExecutionResultVO> getResultVOListByJobExecutionId(long jobExecutionId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -102,9 +101,9 @@ public List<JobExecutionResult> listByErrorJobExecutionId(long jobExecutionId) {
}

@Override
public int getCheckResultByJobExecutionId(long jobExecutionId) {
public JobCheckState getCheckResultByJobExecutionId(long jobExecutionId) {

int result = JobCheckState.NONE.getCode();
JobCheckState result = JobCheckState.NONE;
List<JobExecutionResult> jobExecutionResultList = listByJobExecutionId(jobExecutionId);
if (CollectionUtils.isEmpty(jobExecutionResultList)) {
return result;
Expand All @@ -117,7 +116,7 @@ public int getCheckResultByJobExecutionId(long jobExecutionId) {
}
}

return JobCheckState.of(resultState).getCode();
return JobCheckState.of(resultState);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ public static void validVerificationCode(String verificationCode, String verific

private static String buildJwtVerification(String verificationCode) {
Map<String, Object> 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) {
Expand Down
2 changes: 1 addition & 1 deletion datavines-ui/src/view/Main/HomeDetail/Jobs/JobsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ const Jobs = ({ datasourceId }: TJobs) => {
// @ts-ignore
const columns: ColumnsType<TJobsTableItem> = [
{
title: intl.formatMessage({ id: 'jobs_name' }),
title: intl.formatMessage({ id: 'jobs_id' }),
dataIndex: 'id',
key: 'id',
width: 160,
Expand Down
1 change: 1 addition & 0 deletions datavines-ui/src/view/Main/TokenManager/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const Index = () => {
title: intl.formatMessage({ id: 'token_token' }),
dataIndex: 'token',
key: 'token',
width: 300,
render: (text: string) => <div>{text || '--'}</div>,
},
{
Expand Down

0 comments on commit ede9640

Please sign in to comment.