String cn = CertTools.getPartFromDN(dn,"cn"); if(cn != null){ String newcn = cn + cnpostfix; newdn = dn.replaceFirst(cn,newcn);
if ((dn != null) && (cnpostfix != null)) { String o; X509NameTokenizer xt = new X509NameTokenizer(dn); boolean alreadyreplaced = false; while (xt.hasMoreTokens()) { o = xt.nextToken(); if (!alreadyreplaced && (o.length() > 3) && o.substring(0, 3).equalsIgnoreCase("cn=")) { o += cnpostfix; alreadyreplaced = true; } if(newdn==null){ newdn=o; }else{ newdn += "," + o; } }
    public static String insertCNPostfix(String dn, String cnpostfix){      String newdn = dn;            String cn = CertTools.getPartFromDN(dn,"cn");      if(cn != null){      	String newcn = cn + cnpostfix;      	newdn = dn.replaceFirst(cn,newcn);      }            return newdn;    }