private void addTrustedCertChainsIfAbsent(ILdapMessage certChainsOld,List<ArrayList<String>> certChainsNew) throws CertificateEncodingException, NoSuchAlgorithmException {
  if (certChainsOld != null) {
    ILdapEntry[] entries=certChainsOld.getEntries();
    if (entries != null && entries.length > 0) {
      int certsIndex=getCurrMaxIndex(TRUSTED_CERT_CHAIN_OBJECT_CLASS,CONTAINER_TRUSTED_CERTIFICATE_CHAINS) + 1;
      String dn=String.format("CN=%s,CN=%s,CN=Tenants,CN=IdentityManager,CN=Services,%s",CONTAINER_TRUSTED_CERTIFICATE_CHAINS,tenantName,this.rootDn);
      Map<String,LdapMod[]> ldapObjects=new HashMap<>();
      for (      ILdapEntry lduCert : entries) {
        ArrayList<String> certFingerprints=new ArrayList<>();
        certFingerprints.addAll(CertificatesUtil.getCertFingerPrints(lduCert));
        if (!containsCertChain(certChainsNew,certFingerprints)) {
          List<LdapMod> objAttributes=createAtts(lduCert);
          String cn=getTrustedCertChainCn(certsIndex);
          LdapValue[] values={new LdapValue(cn)};
          LdapMod mod=new LdapMod(LdapModOperation.ADD,"cn",values);
          objAttributes.add(mod);
          String objNewDn="CN=" + cn + ","+ dn;
          ldapObjects.put(objNewDn,objAttributes.toArray(new LdapMod[]{}));
          certsIndex++;
        }
      }
      if (ldapObjects != null && ldapObjects.size() > 0) {
        addObjects(ldapObjects);
      }
    }
  }
}

private void addTrustedCertChainsIfAbsent ( ILdapMessage certChainsOld , List < ArrayList < String > > certChainsNew ) throws CertificateEncodingException , NoSuchAlgorithmException { if ( certChainsOld != null ) { ILdapEntry [ ] entries = certChainsOld . getEntries ( ) ; if ( entries != null && entries . length > 0 ) { int certsIndex = getCurrMaxIndex ( TRUSTED_CERT_CHAIN_OBJECT_CLASS , CONTAINER_TRUSTED_CERTIFICATE_CHAINS ) + 1 ; String dn = String . format ( "CN=%s,CN=%s,CN=Tenants,CN=IdentityManager,CN=Services,%s" , CONTAINER_TRUSTED_CERTIFICATE_CHAINS , tenantName , this . rootDn ) ; Map < String , LdapMod [ ] > ldapObjects = new HashMap < > ( ) ; for ( ILdapEntry lduCert : entries ) { ArrayList < String > certFingerprints = new ArrayList < > ( ) ; certFingerprints . addAll ( CertificatesUtil . getCertFingerPrints ( lduCert ) ) ; if ( ! containsCertChain ( certChainsNew , certFingerprints ) ) { List < LdapMod > objAttributes = createAtts ( lduCert ) ; String cn = getTrustedCertChainCn ( certsIndex ) ; LdapValue [ ] values = { new LdapValue ( cn ) } ; LdapMod mod = new LdapMod ( LdapModOperation . ADD , "cn" , values ) ; objAttributes . add ( mod ) ; String objNewDn = "CN=" + cn + "," + dn ; ldapObjects . put ( objNewDn , objAttributes . toArray ( new LdapMod [ ] { } ) ) ; certsIndex ++ ; } } if ( ldapObjects != null && ldapObjects . size ( ) > 0 ) { addObjects ( ldapObjects ) ; } } } }
this method will add the cert chains at the new location if its not already present by comparing their fingerprints .
