Validates that this JWT was issued in the past and hasn't expired yet. @param leeway the time leeway in seconds in which the token should still be considered valid. @return if this JWT has already expired or not.
(long leeway)
| 159 | * @return if this JWT has already expired or not. |
| 160 | */ |
| 161 | public boolean isExpired(long leeway) { |
| 162 | if (leeway < 0) { |
| 163 | throw new IllegalArgumentException("The leeway must be a positive value."); |
| 164 | } |
| 165 | long todayTime = (long) (Math.floor(new Date().getTime() / 1000) * 1000); //truncate millis |
| 166 | Date futureToday = new Date(todayTime + leeway * 1000); |
| 167 | Date pastToday = new Date(todayTime - leeway * 1000); |
| 168 | boolean expValid = payload.exp == null || !pastToday.after(payload.exp); |
| 169 | boolean iatValid = payload.iat == null || !futureToday.before(payload.iat); |
| 170 | return !expValid || !iatValid; |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * Returns the String representation of this JWT. |
no outgoing calls