File tree Expand file tree Collapse file tree 3 files changed +15
-3
lines changed
resources/jenkins/security/ApiTokenProperty Expand file tree Collapse file tree 3 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -257,13 +257,16 @@ public static class TokenInfoAndStats {
257257 public final Date lastUseDate ;
258258 public final long numDaysUse ;
259259 public final String expirationDate ;
260+ public final boolean expired ;
260261
261262 public TokenInfoAndStats (@ NonNull ApiTokenStore .HashedToken token , @ NonNull ApiTokenStats .SingleTokenStats stats ) {
262263 this .uuid = token .getUuid ();
263264 this .name = token .getName ();
264265 this .creationDate = token .getCreationDate ();
265266 this .numDaysCreation = token .getNumDaysCreation ();
266267 this .isLegacy = token .isLegacy ();
268+ this .expired = token .isExpired ();
269+
267270 LocalDate expirationDate = token .getExpirationDate ();
268271 if (expirationDate == null ) {
269272 this .expirationDate = "never" ;
Original file line number Diff line number Diff line change @@ -433,6 +433,12 @@ public void rename(String newName) {
433433 this .name = newName ;
434434 }
435435
436+ public boolean isExpired () {
437+ LocalDate now = LocalDate .now ();
438+ LocalDate expiration = Objects .requireNonNullElseGet (expirationDate , LocalDate ::now );
439+ return expiration .isBefore (now );
440+ }
441+
436442 public boolean match (byte [] hashedBytes ) {
437443 byte [] hashFromHex ;
438444 try {
@@ -442,9 +448,7 @@ public boolean match(byte[] hashedBytes) {
442448 return false ;
443449 }
444450
445- LocalDate now = LocalDate .now ();
446- LocalDate expiration = Objects .requireNonNullElseGet (expirationDate , LocalDate ::now );
447- boolean expired = expiration .isBefore (now );
451+ boolean expired = isExpired ();
448452 // String.equals() is not constant-time but this method is. No link between correctness and time spent
449453 return MessageDigest .isEqual (hashFromHex , hashedBytes ) && !expired ;
450454 }
Original file line number Diff line number Diff line change @@ -164,6 +164,11 @@ THE SOFTWARE.
164164 </div >
165165 <div >
166166 <j : choose >
167+ <j : when test =" ${token.expired}" >
168+ <span class =" error" >
169+ ${%This token has expired}
170+ </span >
171+ </j : when >
167172 <j : when test =" ${token.expirationDate == 'never'}" >
168173 <span class =" warning" >
169174 ${%This token does not expire}
You can’t perform that action at this time.
0 commit comments