提交错误修正,判断jwt是否过期,应该是过期时间在当前时间之前才是过期

用户时间 > 当前时间  没有过期 after
用户时间 < 当前时间  过期 before
This commit is contained in:
shimingxy
2025-01-03 17:29:45 +08:00
parent c44715c6ee
commit 48bc66d735
2 changed files with 44 additions and 1 deletions

View File

@@ -122,7 +122,7 @@ public class AuthJwtService {
if(StringUtils.isNotBlank(authToken) && authToken.length() > 20) {
try {
JWTClaimsSet claims = resolve(authToken);
boolean isExpiration = claims.getExpirationTime().before(DateTime.now().toDate());
boolean isExpiration = claims.getExpirationTime().after(DateTime.now().toDate());
boolean isVerify = hmac512Service.verify(authToken);
_logger.debug("JWT Validate {} " , isVerify && isExpiration);

View File

@@ -0,0 +1,43 @@
/*
* Copyright [2024] [MaxKey of copyright http://www.maxkey.top]
*
* Licensed 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 org.maxkey;
import java.util.Date;
import org.dromara.maxkey.util.DateUtils;
import org.joda.time.DateTime;
public class DateExpirationTest {
public static void main(String[] args) {
// 当前时间
Date now = DateTime.now().toDate();
// 用户时间
Date uDate = DateUtils.parse("2025-01-04 16:59:53",DateUtils.FORMAT_DATE_YYYY_MM_DD_HH_MM_SS);
System.out.println("user time " + DateUtils.formatDateTime(uDate));
System.out.println("now time " + DateUtils.formatDateTime(now));
//用户时间 > 当前时间
System.out.println("after "+uDate.after(now));
//用户时间 < 当前时间
System.out.println("before "+uDate.before(now));
}
}