List of usage examples for javax.ejb CreateException setStackTrace
public void setStackTrace(StackTraceElement[] stackTrace)
From source file:org.ejbca.core.ejb.ca.store.CertificateStoreSessionBean.java
@TransactionAttribute(TransactionAttributeType.REQUIRED) @Override/*w w w. j a va 2 s . co m*/ public boolean storeCertificate(Admin admin, Certificate incert, String username, String cafp, int status, int type, int certificateProfileId, String tag, long updateTime) throws CreateException { if (log.isTraceEnabled()) { log.trace(">storeCertificate(" + username + ", " + cafp + ", " + status + ", " + type + ")"); } // Strip dangerous chars username = StringTools.strip(username); // We need special handling here of CVC certificate with EC keys, because they lack EC parameters in all certs except the Root certificate (CVCA) PublicKey pubk = incert.getPublicKey(); if ((pubk instanceof PublicKeyEC)) { PublicKeyEC pkec = (PublicKeyEC) pubk; // The public key of IS and DV certificate (CVC) do not have any parameters so we have to do some magic to get a complete EC public key ECParameterSpec spec = pkec.getParams(); if (spec == null) { // We need to enrich this public key with parameters try { if (cafp != null) { String cafingerp = cafp; CertificateData cacert = CertificateData.findByFingerprint(entityManager, cafp); if (cacert == null) { throw new FinderException(); } String nextcafp = cacert.getCaFingerprint(); int bar = 0; // never go more than 5 rounds, who knows what strange things can exist in the CAFingerprint column, make sure we never get stuck here while ((!StringUtils.equals(cafingerp, nextcafp)) && (bar++ < 5)) { cacert = CertificateData.findByFingerprint(entityManager, cafp); if (cacert == null) { throw new FinderException(); } cafingerp = nextcafp; nextcafp = cacert.getCaFingerprint(); } // We found a root CA certificate, hopefully ? PublicKey pkwithparams = cacert.getCertificate().getPublicKey(); pubk = KeyTools.getECPublicKeyWithParams(pubk, pkwithparams); } } catch (FinderException e) { log.info("Can not find CA certificate with fingerprint: " + cafp); } catch (Exception e) { // This catches NoSuchAlgorithmException, NoSuchProviderException and InvalidKeySpecException and possibly something else (NPE?) // because we want to continue anyway if (log.isDebugEnabled()) { log.debug("Can not enrich EC public key with missing parameters: ", e); } } } } // finished with ECC key special handling // Create the certificate in one go with all parameters at once. This used to be important in EJB2.1 so the persistence layer only creates *one* single // insert statement. If we do a home.create and the some setXX, it will create one insert and one update statement to the database. // Probably not important in EJB3 anymore final CertificateData data1 = new CertificateData(incert, pubk, username, cafp, status, type, certificateProfileId, tag, updateTime); final String issuerDN = data1.getIssuerDN(); try { entityManager.persist(data1); } catch (Exception e) { // For backward compatibility. We should drop the throw entirely and rely on the return value. CreateException ce = new CreateException(); ce.setStackTrace(e.getStackTrace()); throw ce; } final String msg = intres.getLocalizedMessage("store.storecert"); logSession.log(admin, issuerDN.hashCode(), LogConstants.MODULE_CA, new Date(), username, incert, LogConstants.EVENT_INFO_STORECERTIFICATE, msg); log.trace("<storeCertificate()"); return true; }