Adding validations to certificate deletion operation

4.x.x
prabathabey 9 years ago
parent fe22bfc125
commit 92cf44380e

@ -121,9 +121,13 @@ public class CertificateManagementAdminServiceImpl implements CertificateManagem
CertificateManagementService certificateService = DeviceMgtAPIUtils.getCertificateManagementService(); CertificateManagementService certificateService = DeviceMgtAPIUtils.getCertificateManagementService();
try { try {
certificateService.removeCertificate(serialNumber); boolean status = certificateService.removeCertificate(serialNumber);
if (!status) {
Response.status(Response.Status.NOT_FOUND).entity("No certificate is found with the given " +
"serial number '" + serialNumber + "'");
}
return Response.status(Response.Status.OK).entity("Certificate that carries the serial number '" + return Response.status(Response.Status.OK).entity("Certificate that carries the serial number '" +
serialNumber + " has been removed").build(); serialNumber + "' has been removed").build();
} catch (CertificateManagementDAOException e) { } catch (CertificateManagementDAOException e) {
String msg = "Error occurred while converting PEM file to X509Certificate"; String msg = "Error occurred while converting PEM file to X509Certificate";
log.error(msg, e); log.error(msg, e);

@ -252,10 +252,7 @@ public class GenericCertificateDAOImpl implements CertificateDAO {
stmt.setString(1, serialNumber); stmt.setString(1, serialNumber);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
if(stmt.executeUpdate() > 0) { return stmt.executeUpdate() > 0;
return true;
}
return false;
} catch (SQLException e) { } catch (SQLException e) {
String errorMsg = String errorMsg =
"Unable to get the read the certificate with serial" + serialNumber; "Unable to get the read the certificate with serial" + serialNumber;

@ -173,7 +173,7 @@ public class CertificateManagementServiceImpl implements CertificateManagementSe
try { try {
CertificateManagementDAOFactory.beginTransaction(); CertificateManagementDAOFactory.beginTransaction();
CertificateDAO certificateDAO = CertificateManagementDAOFactory.getCertificateDAO(); CertificateDAO certificateDAO = CertificateManagementDAOFactory.getCertificateDAO();
Boolean status = certificateDAO.removeCertificate(serialNumber); boolean status = certificateDAO.removeCertificate(serialNumber);
CertificateManagementDAOFactory.commitTransaction(); CertificateManagementDAOFactory.commitTransaction();
return status; return status;
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {

Loading…
Cancel
Save