log.debug("Added new certificate to user entry:" + username+": "+dn);
log.debug("Added new certificate to user entry; " + username+": "+dn);
	public boolean storeCertificate(Admin admin, Certificate incert, String username, String password, String cafp, int status, int type, long revocationDate, int revocationReason, ExtendedInformation extendedinformation) throws PublisherException{        log.debug(">storeCertificate(username="+username+")");        // Don't publish non-active certificates        if (status != CertificateDataBean.CERT_ACTIVE) {        	log.info("Not publishing revoked certificate, status="+status);        	return true;        }        int ldapVersion = LDAPConnection.LDAP_V3;        LDAPConnection lc = createLdapConnection();        String dn = null;        String certdn = null;        try {            // Extract the users DN from the cert.        	certdn = CertTools.getSubjectDN((X509Certificate) incert);            log.debug( "Constructing DN for: " + username);            dn = constructLDAPDN(certdn);            log.debug("LDAP DN for user " +username +" is " + dn);        } catch (Exception e) {            log.error("LDAP ERROR: Error decoding input certificate: ", e);                        throw new PublisherException("Error decoding input certificate.");                    }        // Extract the users email from the cert.        String email = CertTools.getEMailAddress((X509Certificate)incert);        // Check if the entry is already present, we will update it with the new certificate.        LDAPEntry oldEntry = searchOldEntity(username, ldapVersion, lc, dn);        // PART 2: Create LDAP entry        LDAPEntry newEntry = null;        ArrayList modSet = new ArrayList();        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, certdn, true, true);            } else {                objectclass = getUserObjectClass(); // just used for logging                attributeSet = getAttributeSet(incert, getUserObjectClass(), certdn, true, true, password, extendedinformation);            }            if (email != null) {            	//log.debug("Adding email attribute: "+email);                LDAPAttribute mailAttr = new LDAPAttribute("mail", email);                if (oldEntry != null) {                    modSet.add(new LDAPModification(LDAPModification.REPLACE, mailAttr));                } else {                    attributeSet.add(mailAttr);                }            }            try {            	attribute = getUserCertAttribute();                LDAPAttribute certAttr = new LDAPAttribute(getUserCertAttribute(), incert.getEncoded());                if (oldEntry != null) {                    if (getAddMultipleCertificates()) {                        modSet.add(new LDAPModification(LDAPModification.ADD, certAttr));                                                log.debug("Appended new certificate in user entry:" + username+": "+dn);                    } else {                        modSet.add(new LDAPModification(LDAPModification.REPLACE, certAttr));                                                                    log.debug("Replaced certificate in user entry:" + username+": "+dn);                    }                } else {                    attributeSet.add(certAttr);                    log.debug("Added new certificate to user entry:" + username+": "+dn);                }            } catch (CertificateEncodingException e) {                log.error("LDAP 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, certdn, false, false);            } else {                objectclass = getCAObjectClass(); // just used for logging                attributeSet = getAttributeSet(incert, getCAObjectClass(), certdn, true, false, password, extendedinformation);            }            try {                attribute = getCACertAttribute();                LDAPAttribute certAttr = new LDAPAttribute(getCACertAttribute(), incert.getEncoded());                if (oldEntry != null) {                    modSet.add(new LDAPModification(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("LDAP 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.");                              }        // PART 3: MODIFICATION AND ADDITION OF NEW USERS        try {            lc.connect(getHostname(), Integer.parseInt(getPort()));            // authenticate to the server            lc.bind(ldapVersion, getLoginDN(), getLoginPassword().getBytes("UTF8"));                        // Add or modify the entry            if (oldEntry != null && getModifyExistingUsers()) {                LDAPModification[] mods = new LDAPModification[modSet.size()];                 mods = (LDAPModification[])modSet.toArray(mods);                lc.modify(dn, mods);                log.info("LDAP CERT: Modified object: " + dn + " successfully.");              } else {                if(this.getCreateNonExisingUsers()){                       if (oldEntry == null) {                  	                    newEntry = new LDAPEntry(dn, attributeSet);                    lc.add(newEntry);                    log.info("LDAP CERT: Added object: " + dn + " successfully.");                  }                }              }        } catch (LDAPException e) {            log.error("LDAP ERROR: Error storing certificate (" + attribute + ") in LDAP (" + objectclass + ") for DN (" + dn + "): ", e);              throw new PublisherException("Error storing certificate (" + attribute + ") in LDAP (" + objectclass + ") for DN (" + dn + ").");                    } catch (UnsupportedEncodingException e) {            log.error("LDAP ERROR: Can't decode password for LDAP login: "+getLoginPassword(), e);            throw new PublisherException("Can't decode password when storing (" + attribute + ") in LDAP (" + objectclass + ") for DN (" + dn + ").");                    } finally {			// disconnect with the server			try {				lc.disconnect();			} catch (LDAPException e) {				log.error("LDAP ERROR: LdapPublisher: LDAP disconnection failed: ", e);			}		}        log.debug("<storeCertificate()");        return true;			}