* @param c Consumer whose certificate needs to be generated.
* @param regen if true, forces a regen of the certificate.
* @return an IdentityCertificate object
*/
private IdentityCertificate generateIdCert(Consumer c, boolean regen) {
IdentityCertificate idCert = null;
boolean errored = false;
try {
if (regen) {
idCert = identityCertService.regenerateIdentityCert(c);
}
else {
idCert = identityCertService.generateIdentityCert(c);
}
if (idCert == null) {
errored = true;
}
}
catch (GeneralSecurityException e) {
log.error("Problem regenerating ID cert for unit:", e);
errored = true;
}
catch (IOException e) {
log.error("Problem regenerating ID cert for unit:", e);
errored = true;
}
if (errored) {
throw new BadRequestException(i18n.tr(
"Problem regenerating ID cert for unit {0}", c));
}
log.debug("Generated identity cert: {}", idCert.getSerial());
return idCert;
}