Skip to content

Commit

Permalink
feat : added signing-cert-expiry
Browse files Browse the repository at this point in the history
  • Loading branch information
KrutikaPhirangi committed Aug 18, 2023
1 parent 6ccae60 commit 7f5516d
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,32 @@ public class ParticipantValidationScheduler extends BaseScheduler {
private int notificationExpiry;
@Value("${certificate.expiry-days}")
private List<Integer> beforeExpiryDaysList;


@Scheduled(fixedDelayString = "${fixedDelay.in.milliseconds.participantVerify}")
public void process() throws Exception {
logger.info("Participant validation scheduler started");
certExpiry(Constants.ENCRYPTION_CERT_EXPIRY);
certExpiry(Constants.SIGNING_CERT_PATH_EXPIRY);
}

public void certExpiry(String participantCert) throws Exception {
String expiryMessage = "";
String beforeExpiryMessage = "";
List<Map<String, Object>> participants = new ArrayList<>();
List<String> expiredParticipantCodes = new ArrayList<>();
List<String> aboutToExpireParticipantCodes = new ArrayList<>();
List<Map<String, Object>> participants = new ArrayList<>();
for (int beforeExpiryDay : beforeExpiryDaysList) {
long expiryTime = System.currentTimeMillis() + (1 + beforeExpiryDay) * 24L * 60 * 60 * 1000;
participants = registryService.getDetails("{ \"filters\": { \"encryption_cert_expiry\": { \"<\": " + expiryTime + " } } }");
participants = registryService.getDetails("{ \"filters\": { " + participantCert + ": { \"<\": " + expiryTime + " } } }");
for (Map<String, Object> participant : participants) {
long certExpiry = (long) participant.get(Constants.ENCRYPTION_CERT_EXPIRY);
long certExpiry = (long) participant.get(participantCert);
String participantCode = (String) participant.get(Constants.PARTICIPANT_CODE);
long earlierDayTime = expiryTime - (24L * 60 * 60 * 1000) ;
long earlierDayTime = expiryTime - (24L * 60 * 60 * 1000);
if (certExpiry <= System.currentTimeMillis()) {
expiredParticipantCodes.add(participantCode);
expiryMessage = getTemplateMessage(expiryTopicCode);
} else if (certExpiry > earlierDayTime && certExpiry < expiryTime){
} else if (certExpiry > earlierDayTime && certExpiry < expiryTime) {
aboutToExpireParticipantCodes.add(participantCode);
beforeExpiryMessage = getTemplateMessage(beforeExpiryTopicCode).replace("${days}", String.valueOf(beforeExpiryDay));
}
Expand All @@ -71,7 +77,6 @@ public void process() throws Exception {
generateEvent(expiredParticipantCodes, expiryMessage, expiryTopicCode);
logger.info("Total number of participants with expired or expiring encryption certificate in {}", participants.size());
logger.info("Participant validation scheduler ended");

}

private void generateEvent(List<String> participantCodes, String message, String topiCode) throws Exception {
Expand All @@ -81,6 +86,7 @@ private void generateEvent(List<String> participantCodes, String message, String
kafkaClient.send(notifyTopic, Constants.NOTIFICATION, event);
logger.info("Notify event is pushed to kafka: {}", event);
}

private String getTemplateMessage(String topicCode) throws Exception {
return (String) JSONUtils.deserialize((String) (NotificationUtils.getNotification(topicCode).get(Constants.TEMPLATE)), Map.class).get(Constants.MESSAGE);
}
Expand Down

0 comments on commit 7f5516d

Please sign in to comment.