private void checkCertificateDateValidity(X509Certificate certificate){
  final String CERTIFICATE_EXPIRED_MESSAGE="ViPR's certificate has expired. Please set a new one, or post a regenerate request";
  final String CERTIFICATE_WILL_EXPIRE_MESSAGE_FORMAT="ViPR's certificate will expire within %d %s. Please make arrangements to set a new certificate or to post a regenerate request";
  Date lastCertificateAlert=null;
  try {
    lastCertificateAlert=coordConfigStoringHelper.readConfig(coordConfigStoringHelper.getSiteId(),KEY_CERTIFICATE_PAIR_CONFIG_KIND,LAST_CERTIFICATE_ALERT_ID,LAST_CERTIFICATE_ALERT_KEY);
  }
 catch (  Exception e) {
    log.warn(e.getMessage(),e);
  }
  Date notAfter=DateUtils.truncate(certificate.getNotAfter(),Calendar.DATE);
  Date today=DateUtils.truncate(new Date(),Calendar.DATE);
  Date nextWeek=DateUtils.addWeeks(today,1);
  Date nextMonth=DateUtils.addMonths(today,1);
  Date next3Months=DateUtils.addMonths(today,3);
  Date next6Months=DateUtils.addMonths(today,6);
  if (lastCertificateAlert == null || DateUtils.truncatedCompareTo(lastCertificateAlert,today,Calendar.DATE) < 0) {
    boolean logAlert=false;
    String messageToLog=CERTIFICATE_WILL_EXPIRE_MESSAGE_FORMAT;
    int timeAmount=0;
    String timeType=null;
    LogLevel logLevel=LogLevel.WARN;
    if (notAfter.before(today)) {
      logLevel=LogLevel.FATAL;
      messageToLog=CERTIFICATE_EXPIRED_MESSAGE;
      logAlert=true;
    }
 else     if (DateUtils.isSameDay(notAfter,today)) {
      timeType="days";
      logLevel=LogLevel.ERROR;
      logAlert=true;
    }
 else     if (notAfter.before(nextWeek)) {
      timeAmount=1;
      timeType="week";
      logAlert=true;
    }
 else     if (notAfter.before(nextMonth)) {
      timeAmount=1;
      timeType="month";
      logAlert=true;
    }
 else     if (notAfter.before(next3Months)) {
      timeAmount=3;
      timeType="months";
      logAlert=true;
    }
 else     if (notAfter.before(next6Months)) {
      timeAmount=6;
      timeType="months";
      logAlert=true;
    }
    if (logAlert) {
      logAlert(messageToLog,timeAmount,timeType,logLevel);
      try {
        coordConfigStoringHelper.createOrUpdateConfig(today,KEY_CERTIFICATE_PAIR_LOCK,coordConfigStoringHelper.getSiteId(),KEY_CERTIFICATE_PAIR_CONFIG_KIND,LAST_CERTIFICATE_ALERT_ID,LAST_CERTIFICATE_ALERT_KEY);
      }
 catch (      Exception e) {
        log.error("Could not set the time of last alert about certificate expiry",e);
      }
    }
  }
}

private void checkCertificateDateValidity ( X509Certificate certificate ) { final String CERTIFICATE_EXPIRED_MESSAGE = "ViPR's certificate has expired. Please set a new one, or post a regenerate request" ; final String CERTIFICATE_WILL_EXPIRE_MESSAGE_FORMAT = "ViPR's certificate will expire within %d %s. Please make arrangements to set a new certificate or to post a regenerate request" ; Date lastCertificateAlert = null ; try { lastCertificateAlert = coordConfigStoringHelper . readConfig ( coordConfigStoringHelper . getSiteId ( ) , KEY_CERTIFICATE_PAIR_CONFIG_KIND , LAST_CERTIFICATE_ALERT_ID , LAST_CERTIFICATE_ALERT_KEY ) ; } catch ( Exception e ) { log . warn ( e . getMessage ( ) , e ) ; } Date notAfter = DateUtils . truncate ( certificate . getNotAfter ( ) , Calendar . DATE ) ; Date today = DateUtils . truncate ( new Date ( ) , Calendar . DATE ) ; Date nextWeek = DateUtils . addWeeks ( today , 1 ) ; Date nextMonth = DateUtils . addMonths ( today , 1 ) ; Date next3Months = DateUtils . addMonths ( today , 3 ) ; Date next6Months = DateUtils . addMonths ( today , 6 ) ; if ( lastCertificateAlert == null || DateUtils . truncatedCompareTo ( lastCertificateAlert , today , Calendar . DATE ) < 0 ) { boolean logAlert = false ; String messageToLog = CERTIFICATE_WILL_EXPIRE_MESSAGE_FORMAT ; int timeAmount = 0 ; String timeType = null ; LogLevel logLevel = LogLevel . WARN ; if ( notAfter . before ( today ) ) { logLevel = LogLevel . FATAL ; messageToLog = CERTIFICATE_EXPIRED_MESSAGE ; logAlert = true ; } else if ( DateUtils . isSameDay ( notAfter , today ) ) { timeType = "days" ; logLevel = LogLevel . ERROR ; logAlert = true ; } else if ( notAfter . before ( nextWeek ) ) { timeAmount = 1 ; timeType = "week" ; logAlert = true ; } else if ( notAfter . before ( nextMonth ) ) { timeAmount = 1 ; timeType = "month" ; logAlert = true ; } else if ( notAfter . before ( next3Months ) ) { timeAmount = 3 ; timeType = "months" ; logAlert = true ; } else if ( notAfter . before ( next6Months ) ) { timeAmount = 6 ; timeType = "months" ; logAlert = true ; } if ( logAlert ) { logAlert ( messageToLog , timeAmount , timeType , logLevel ) ; try { coordConfigStoringHelper . createOrUpdateConfig ( today , KEY_CERTIFICATE_PAIR_LOCK , coordConfigStoringHelper . getSiteId ( ) , KEY_CERTIFICATE_PAIR_CONFIG_KIND , LAST_CERTIFICATE_ALERT_ID , LAST_CERTIFICATE_ALERT_KEY ) ; } catch ( Exception e ) { log . error ( "Could not set the time of last alert about certificate expiry" , e ) ; } } } }
checks if the certificate is about to expire , and alerts in case it is
