Skip to content

Commit

Permalink
Merge pull request #21 from JavaCoDED78/#20
Browse files Browse the repository at this point in the history
  • Loading branch information
JavaCoDED78 authored Jun 18, 2024
2 parents 2125831 + 4b4440b commit 8214aeb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ public String create(final TokenParameters params) {

@Override
public boolean isExpired(final String token) {
return isExpired(
token,
new Date()
);
}

@Override
public boolean isExpired(final String token,
final Date date) {
try {
Jws<Claims> claims = Jwts
.parser()
Expand All @@ -87,7 +96,7 @@ public boolean isExpired(final String token) {
.parseSignedClaims(token);
return claims.getPayload()
.getExpiration()
.before(new Date());
.before(date);
} catch (ExpiredJwtException e) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.github.javacoded78.jwthumble.config.TokenParameters;

import java.util.Date;
import java.util.Map;

/**
Expand Down Expand Up @@ -46,6 +47,16 @@ boolean has(String token,
*/
String getSubject(String token);

/**
* Checks whether JWT token is expired by provided time.
*
* @param token JWT token to be checked
* @param date date to check expiration of JWT token
* @return true - if JWT token expired, false - otherwise
*/
boolean isExpired(String token,
Date date);

/**
* Returns type of JWT token.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ public String create(final TokenParameters params) {

@Override
public boolean isExpired(final String token) {
return isExpired(
token,
new Date()
);
}

@Override
public boolean isExpired(final String token,
final Date date) {
try {
Jws<Claims> claims = Jwts
.parser()
Expand All @@ -61,7 +70,7 @@ public boolean isExpired(final String token) {
.parseSignedClaims(token);
return claims.getPayload()
.getExpiration()
.before(new Date());
.before(date);
} catch (ExpiredJwtException e) {
return true;
}
Expand Down

0 comments on commit 8214aeb

Please sign in to comment.