소스 검색

fix: 日期修正

fanyanpeng 2 년 전
부모
커밋
d9b1ce1d43
1개의 변경된 파일11개의 추가작업 그리고 1개의 파일을 삭제
  1. 11 1
      seecoder-gitlab-server/src/main/java/com/nju/edu/gitlab/service/impl/UserServiceImpl.java

+ 11 - 1
seecoder-gitlab-server/src/main/java/com/nju/edu/gitlab/service/impl/UserServiceImpl.java

@@ -16,9 +16,11 @@ import org.gitlab4j.api.models.ImpersonationToken;
 import org.gitlab4j.api.models.ImpersonationToken.Scope;
 import org.gitlab4j.api.models.Namespace;
 import org.gitlab4j.api.models.User;
+import org.gitlab4j.api.utils.ISO8601;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.text.ParseException;
 import java.time.Instant;
 import java.util.Calendar;
 import java.util.Date;
@@ -138,8 +140,16 @@ public class UserServiceImpl implements UserService {
         Scope[] scopes = new Scope[]{Scope.API};
         ImpersonationToken token;
         log.info(String.format("createToken, userId = %d",userId));
+        Date expiresAt;
+
+        try {
+            expiresAt = ISO8601.toDate("2024-10-01T00:00:00Z");
+        } catch (ParseException e) {
+            throw new RuntimeException(e);
+        }
+
         // 最长为一年之后
-        token = gitlabApi.getUserApi().createImpersonationToken(userId.toString(), "AES-" + Tools.randomUUID(), new Date(2024, Calendar.NOVEMBER,4), scopes);
+        token = gitlabApi.getUserApi().createImpersonationToken(userId.toString(), "AES-" + Tools.randomUUID(), expiresAt, scopes);
         return token.getToken();
     }