/** * Tests the key to see if it is expired or not. * * <p>If the key is expired, a call to {@link #removeExpiredKey(AuthenticationKey)} is issued, and * a {@link KeyNotFoundException} is thrown. * * @param authkey the key to test. * @throws KeyNotFoundException if the key is expired. * @throws KeyManagerException if there was a problem removing the key. */ protected void assertNotExpired(AuthenticationKey authkey) throws KeyNotFoundException, KeyManagerException { if (authkey.getDateExpires() == null) { // No expiration means a permanent entry. return; } // Test for expiration. Calendar now = getNowGMT(); Calendar expiration = getNowGMT(); expiration.setTime(authkey.getDateExpires()); if (now.after(expiration)) { deleteKey(authkey); throw new KeyNotFoundException("Key [" + authkey.getKey() + "] has expired."); } }
public void removeExpiredKeys() throws KeyManagerException { List<AuthenticationKey> allKeys = getAllKeys(); Calendar now = getNowGMT(); Calendar expiration = getNowGMT(); log.info("Removing expired keys."); for (AuthenticationKey authkey : allKeys) { if (authkey.getDateExpires() != null) { expiration.setTime(authkey.getDateExpires()); if (now.after(expiration)) { deleteKey(authkey); } } } log.info("Expired keys removed."); }