error( "Error storing certificate in LDAP: ", e);
error( "Error storing certificate ("+attribute+") in LDAP ("+objectclass+"): ", e);
    public boolean storeCertificate(Certificate incert, String cafp, int status, int type) {        int ldapVersion  = LDAPConnection.LDAP_V3;        LDAPConnection lc = new LDAPConnection();        // Extract the users DN from the cert.        String dn = CertTools.stringToBCDNString(((X509Certificate)incert).getSubjectDN().toString());        // 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());                DERConstructedSequence san = (DERConstructedSequence)new DERInputStream(bIn1).readObject();                for (int i=0;i<san.getSize();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) {                error("IOException when getting subjectAltNames extension.");            }        }        if (checkContainerName(dn) == false)            return false;        // 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( ldapHost, ldapPort );            // authenticate to the server            lc.bind( ldapVersion, loginDN, loginPassword );            // 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) {                debug("No old entry exist for '"+dn+"'.");            } else {                error( "Error binding to and reading from LDAP server: ", e);                return false;            }        }        LDAPEntry newEntry = null;        LDAPModificationSet modSet = null;        if ( ((type & SecConst.USER_ENDUSER) != 0) || ((type & SecConst.USER_CAADMIN) != 0) ||        ((type & SecConst.USER_RAADMIN) != 0) || ((type & SecConst.USER_RA) != 0) ) {            LDAPAttributeSet attributeSet = null;            if (oldEntry != null) {                // TODO: Are we the correct type objectclass?                modSet = getModificationSet(oldEntry, dn, true);            } else                attributeSet = getAttributeSet(userObjectclass, dn, true);            if (email != null) {                LDAPAttribute mailAttr = new LDAPAttribute( "mail", email );                if (oldEntry != null)                    modSet.add(LDAPModification.REPLACE, mailAttr);                else                    attributeSet.add( mailAttr );            }            try {                LDAPAttribute certAttr = new LDAPAttribute( userCertAttribute, incert.getEncoded() );                if (oldEntry != null)                    modSet.add(LDAPModification.REPLACE, certAttr);                else                    attributeSet.add( certAttr );            } catch (CertificateEncodingException e) {                error("Error encoding certificate when storing in LDAP: ",e);                return false;            }            if (oldEntry == null)                newEntry = new LDAPEntry( dn, attributeSet );        } else if ( ((type & SecConst.USER_CA) != 0) || ((type & SecConst.USER_ROOTCA) != 0) ) {            LDAPAttributeSet attributeSet = null;            if (oldEntry != null)                modSet = getModificationSet(oldEntry, dn, false);            else                attributeSet = getAttributeSet(cAObjectclass, dn, false);            try {                LDAPAttribute certAttr = new LDAPAttribute( cACertAttribute, incert.getEncoded() );                if (oldEntry != null)                    modSet.add(LDAPModification.REPLACE, certAttr);                else                    attributeSet.add( certAttr );            } catch (CertificateEncodingException e) {                error("Error encoding certificate when storing in LDAP: ",e);                return false;            }            if (oldEntry == null)                newEntry = new LDAPEntry( dn, attributeSet );        } else {            info("Certificate of type '"+type+"' will not be published.");            return false;        }        try {            // connect to the server            lc.connect( ldapHost, ldapPort );            // authenticate to the server            lc.bind( ldapVersion, loginDN, loginPassword );            // Add or modify the entry            if (oldEntry != null) {                lc.modify(dn, modSet);                info( "\nModified object: " + dn + " successfully." );            } else {                lc.add( newEntry );                info( "\nAdded object: " + dn + " successfully." );            }            // disconnect with the server            lc.disconnect();        }        catch( LDAPException e ) {            error( "Error storing certificate in LDAP: ", e);            return false;        }        return true;    } // storeCertificate