@Action("save-certificate") public String saveCertificate() throws Exception { if (certificateFile != null) { X509Certificate cert = CertUtil.parseCertficate(new FileInputStream(certificateFile)); AddUserCertificateOperation.instance(getModel(), cert).execute(); } else { // Fix for bug https://savannah.cern.ch/bugs/?88019 AddUserCertificateOperation.instance(getModel(), subject.trim(), caSubject.trim(), null) .execute(); } return SUCCESS; }
public void validateSaveCertificate() { CertificateDAO dao = CertificateDAO.instance(); if (certificateFile != null) { X509Certificate cert = null; try { cert = CertUtil.parseCertficate(new FileInputStream(certificateFile)); } catch (Throwable e) { addFieldError( "certificateFile", "Error parsing certificate passed as argument: " + e.getMessage() + ". Please upload a valid X509, PEM encoded certificate."); return; } if (cert == null) { addFieldError("certificateFile", "Error parsing certificate passed as argument!"); return; } if (dao.find(cert) != null) addFieldError("certificateFile", "Certificate already bound!"); } else if (subject != null && !"".equals(subject)) { if (dao.findByDNCA(subject, caSubject) != null) { addFieldError("subject", "Certificate already bound!"); addFieldError("caSubject", "Certificate already bound!"); } } else { addActionError( "Please specify a Subject, CA couple or choose a certificate file that will be uploaded to the server!"); } }