From 92cf44380e447205f8e834e39f1e69f020d4dc2a Mon Sep 17 00:00:00 2001 From: prabathabey Date: Thu, 2 Jun 2016 00:48:44 +0530 Subject: [PATCH] Adding validations to certificate deletion operation --- .../api/impl/CertificateManagementAdminServiceImpl.java | 8 ++++++-- .../mgt/core/dao/impl/GenericCertificateDAOImpl.java | 5 +---- .../core/service/CertificateManagementServiceImpl.java | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/impl/CertificateManagementAdminServiceImpl.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/impl/CertificateManagementAdminServiceImpl.java index ebe9953f8b..15b0a548c7 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/impl/CertificateManagementAdminServiceImpl.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/impl/CertificateManagementAdminServiceImpl.java @@ -121,9 +121,13 @@ public class CertificateManagementAdminServiceImpl implements CertificateManagem CertificateManagementService certificateService = DeviceMgtAPIUtils.getCertificateManagementService(); 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 '" + - serialNumber + " has been removed").build(); + serialNumber + "' has been removed").build(); } catch (CertificateManagementDAOException e) { String msg = "Error occurred while converting PEM file to X509Certificate"; log.error(msg, e); diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dao/impl/GenericCertificateDAOImpl.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dao/impl/GenericCertificateDAOImpl.java index 73f6ee7b79..5109f55e03 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dao/impl/GenericCertificateDAOImpl.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/dao/impl/GenericCertificateDAOImpl.java @@ -252,10 +252,7 @@ public class GenericCertificateDAOImpl implements CertificateDAO { stmt.setString(1, serialNumber); stmt.setInt(2, tenantId); - if(stmt.executeUpdate() > 0) { - return true; - } - return false; + return stmt.executeUpdate() > 0; } catch (SQLException e) { String errorMsg = "Unable to get the read the certificate with serial" + serialNumber; diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java index 89fd9b4827..83505cf04a 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/src/main/java/org/wso2/carbon/certificate/mgt/core/service/CertificateManagementServiceImpl.java @@ -173,7 +173,7 @@ public class CertificateManagementServiceImpl implements CertificateManagementSe try { CertificateManagementDAOFactory.beginTransaction(); CertificateDAO certificateDAO = CertificateManagementDAOFactory.getCertificateDAO(); - Boolean status = certificateDAO.removeCertificate(serialNumber); + boolean status = certificateDAO.removeCertificate(serialNumber); CertificateManagementDAOFactory.commitTransaction(); return status; } catch (TransactionManagementException e) {