log.debug("\nAdded object: " + dn + " successfully.");
log.info("\nAdded object: " + dn + " successfully.");
	public boolean storeCertificate(Admin admin, Certificate incert, String username, String password, String cafp, int status, int type, ExtendedInformation extendedinformation) throws PublisherException{        log.debug(">storeCertificate(username="+username+")");        int ldapVersion = LDAPConnection.LDAP_V3;        LDAPConnection lc = null;        if(getUseSSL()){          lc = new LDAPConnection(new LDAPJSSESecureSocketFactory());        }else{          lc = new LDAPConnection();                }        String dn = null;        try {            // Extract the users DN from the cert.            dn = constructLDAPDN(CertTools.getSubjectDN((X509Certificate) incert));        } catch (Exception e) {            log.error("Error decoding input certificate: ", e);                        throw new PublisherException("Error decoding input certificate.");                    }        // Extract the users email from the cert.        // First see if we have subjectAltNames extension        String email = null;        byte[] subjAltNameValue = ((X509Certificate) incert).getExtensionValue("2.5.29.17");        // If not, see if we have old styld email-in-DN        if (subjAltNameValue == null) {            email = CertTools.getPartFromDN(dn, "EmailAddress");        } else {            try {                // Get extension value                ByteArrayInputStream bIn = new ByteArrayInputStream(subjAltNameValue);                DEROctetString asn1 = (DEROctetString) new DERInputStream(bIn).readObject();                ByteArrayInputStream bIn1 = new ByteArrayInputStream(asn1.getOctets());                ASN1Sequence san = (ASN1Sequence) new DERInputStream(bIn1).readObject();                for (int i = 0; i < san.size(); i++) {                    DERTaggedObject gn = (DERTaggedObject) san.getObjectAt(i);                    if (gn.getTagNo() == 1) {                        // This is rfc822Name!                        DERIA5String str;                        if (gn.getObject() instanceof DERIA5String) {                            str = (DERIA5String) gn.getObject();                        } else {                            str = new DERIA5String(((DEROctetString) gn.getObject()).getOctets());                        }                        email = str.getString();                    }                }            } catch (IOException e) {                log.error("IOException when getting subjectAltNames extension.");                throw new PublisherException("IOException when getting subjectAltNames extension.");            }        }        // Check if the entry is already present, we will update it with the new certificate.        LDAPEntry oldEntry = null;        try {            // connect to the server            lc.connect(getHostname(), Integer.parseInt(getPort()));            // authenticate to the server            lc.bind(ldapVersion, getLoginDN(), getLoginPassword());            // try to read the old object            oldEntry = lc.read(dn);            // disconnect with the server            lc.disconnect();        } catch (LDAPException e) {            if (e.getLDAPResultCode() == LDAPException.NO_SUCH_OBJECT) {                log.debug("No old entry exist for '" + dn + "'.");                            } else {                log.error("Error binding to and reading from LDAP server: ", e);                throw new PublisherException("Error binding to and reading from LDAP server.");                                            }        }        LDAPEntry newEntry = null;        LDAPModificationSet modSet = null;        LDAPAttributeSet attributeSet = null;        String attribute = null;        String objectclass = null;        if (type == CertificateDataBean.CERTTYPE_ENDENTITY) {            log.debug("Publishing end user certificate to " + getHostname());            if (oldEntry != null) {                // TODO: Are we the correct type objectclass?                modSet = getModificationSet(oldEntry, dn, false, true);            } else {                objectclass = getUserObjectClass();            }            attributeSet = getAttributeSet((X509Certificate) incert, getUserObjectClass(), dn, true, true);            if (email != null) {                LDAPAttribute mailAttr = new LDAPAttribute("mail", email);                if (oldEntry != null) {                    modSet.add(LDAPModification.REPLACE, mailAttr);                } else {                    attributeSet.add(mailAttr);                }            }            try {                attribute = getUserCertAttribute();                LDAPAttribute certAttr = new LDAPAttribute(getUserCertAttribute(), incert.getEncoded());                if (oldEntry != null) {                    modSet.add(LDAPModification.REPLACE, certAttr);                                    } else {                    attributeSet.add(certAttr);                }            } catch (CertificateEncodingException e) {                log.error("Error encoding certificate when storing in LDAP: ", e);                throw new PublisherException("Error encoding certificate when storing in LDAP.");                            }        } else if ((type == CertificateDataBean.CERTTYPE_SUBCA) || (type == CertificateDataBean.CERTTYPE_ROOTCA)) {            log.debug("Publishing CA certificate to " + getHostname());            if (oldEntry != null) {                modSet = getModificationSet(oldEntry, dn, false, false);            } else {                objectclass = getCAObjectClass();            }            attributeSet = getAttributeSet((X509Certificate) incert, getCAObjectClass(), dn, true, false);            try {                attribute = getCACertAttribute();                LDAPAttribute certAttr = new LDAPAttribute(getCACertAttribute(), incert.getEncoded());                if (oldEntry != null) {                    modSet.add(LDAPModification.REPLACE, certAttr);                } else {                    attributeSet.add(certAttr);                    // Also create using the crlattribute, it may be required                    LDAPAttribute crlAttr = new LDAPAttribute(getCRLAttribute(), fakecrl);                    attributeSet.add(crlAttr);                    // Also create using the arlattribute, it may be required                    LDAPAttribute arlAttr = new LDAPAttribute(getARLAttribute(), fakecrl);                    attributeSet.add(arlAttr);                    log.debug("Added (fake) attribute for CRL and ARL.");                }            } catch (CertificateEncodingException e) {                log.error("Error encoding certificate when storing in LDAP: ", e);                throw new PublisherException("Error encoding certificate when storing in LDAP.");                        }        } else {            log.info("Certificate of type '" + type + "' will not be published.");            throw new PublisherException("Certificate of type '" + type + "' will not be published.");                              }        try {                    lc.connect(getHostname(), Integer.parseInt(getPort()));            // authenticate to the server            lc.bind(ldapVersion, getLoginDN(), getLoginPassword());                        // Add or modify the entry            if (oldEntry != null && getModifyExistingUsers()) {                lc.modify(dn, modSet);                log.debug("\nModified object: " + dn + " successfully.");              } else {                if(this.getCreateNonExisingUsers()){                       if (oldEntry == null) {                    newEntry = new LDAPEntry(dn, attributeSet);                  }                  lc.add(newEntry);                  log.debug("\nAdded object: " + dn + " successfully.");                }              }            // disconnect with the server            lc.disconnect();        } catch (LDAPException e) {            log.error("Error storing certificate (" + attribute + ") in LDAP (" + objectclass + "): ", e);              throw new PublisherException("Error storing certificate (" + attribute + ") in LDAP (" + objectclass + ").");                    }        log.debug("<storeCertificate()");        return true;			}