EMM-1298: Extracting serial number from the certificate itself when adding a certificate

4.x.x
Madawa Soysa 8 years ago
parent a6203845c9
commit 774eaadb71

@ -17,6 +17,7 @@ import org.wso2.carbon.context.PrivilegedCarbonContext;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.security.cert.X509Certificate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -42,8 +43,10 @@ public class CertificateManagementAdminServiceImpl implements CertificateManagem
for (EnrollmentCertificate enrollmentCertificate : enrollmentCertificates) { for (EnrollmentCertificate enrollmentCertificate : enrollmentCertificates) {
certificate = new org.wso2.carbon.certificate.mgt.core.bean.Certificate(); certificate = new org.wso2.carbon.certificate.mgt.core.bean.Certificate();
certificate.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); certificate.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
certificate.setSerial(enrollmentCertificate.getSerial()); X509Certificate x509Certificate = certificateService
certificate.setCertificate(certificateService.pemToX509Certificate(enrollmentCertificate.getPem())); .pemToX509Certificate(enrollmentCertificate.getPem());
certificate.setSerial(x509Certificate.getSerialNumber().toString());
certificate.setCertificate(x509Certificate);
certificates.add(certificate); certificates.add(certificate);
} }
certificateService.saveCertificate(certificates); certificateService.saveCertificate(certificates);

@ -51,14 +51,6 @@
<div id="certificate-create-error-msg" class="alert alert-danger hidden" role="alert"> <div id="certificate-create-error-msg" class="alert alert-danger hidden" role="alert">
<i class="icon fw fw-error"></i><span></span> <i class="icon fw fw-error"></i><span></span>
</div> </div>
<label class="wr-input-label ">
Serial Number *
</label>
<br>
<div id="serialNoInputField" class="form-group wr-input-control">
<input type="text" id="serialNo" class="form-control"/>
</div>
<label class="wr-input-label">Certificate *</label> <label class="wr-input-label">Certificate *</label>
<div id="certificateField" class="form-group wr-input-control"> <div id="certificateField" class="form-group wr-input-control">
<input type="file" id="certificate" class="form-control"/> <input type="file" id="certificate" class="form-control"/>

@ -92,17 +92,11 @@ $(document).ready(function () {
* when a user clicks on "Add Certificate" button. * when a user clicks on "Add Certificate" button.
*/ */
$("button#add-certificate-btn").click(function () { $("button#add-certificate-btn").click(function () {
var serialNoInput = $("input#serialNo"); if (!pemContent) {
var serialNo = serialNoInput.val();
if (!serialNo) {
$(errorMsg).text("Serial Number is a required field. It cannot be empty.");
$(errorMsgWrapper).removeClass("hidden");
} else if (!pemContent) {
$(errorMsg).text(" .pem file must contains certificate information."); $(errorMsg).text(" .pem file must contains certificate information.");
$(errorMsgWrapper).removeClass("hidden"); $(errorMsgWrapper).removeClass("hidden");
} else { } else {
var addCertificateFormData = {}; var addCertificateFormData = {};
addCertificateFormData.serial = serialNo;
addCertificateFormData.pem = pemContent; addCertificateFormData.pem = pemContent;
var certificateList = []; var certificateList = [];
certificateList.push(addCertificateFormData); certificateList.push(addCertificateFormData);

Loading…
Cancel
Save