}
}
LDAPAttribute oldsn = oldEntry.getAttribute("sn");
if (((sn != null) && (oldsn == null) && addNonExisting) || ( (sn != null) && (oldsn != null ) && modifyExisting)) {
LDAPAttribute attr = new LDAPAttribute("sn", sn);
modSet.add(new LDAPModification(LDAPModification.REPLACE, attr));
}
// gn means givenname in LDAP, and is required for inetOrgPerson
String gn = CertTools.getPartFromDN(dn, "GIVENNAME");
LDAPAttribute oldgn = oldEntry.getAttribute("GIVENNAME");
if ( (gn == null) && (cn != null) ) {
// Only construct this if we are the standard object class
if (getUserObjectClass().endsWith("inetOrgPerson")) {
// Take givenname to be the first part of the cn
int index = cn.indexOf(' ');
if (index <=0) {
// If there is no natural gn/sn, ignore gn if we are using sn
if (sn == null) {
gn = cn;
}
} else {
gn = new String(cn.substring(0, index));
}
}
if ( ( ((gn != null) && (oldgn == null)) && addNonExisting) || ( ((gn != null) && (oldgn != null )) && modifyExisting) ) {
LDAPAttribute attr = new LDAPAttribute("givenName", gn);
modSet.add(new LDAPModification(LDAPModification.REPLACE, attr));
}
}
String title = CertTools.getPartFromDN(dn, "T");
LDAPAttribute oldTitle = oldEntry.getAttribute("Title");
if ( ( (title != null) && (oldTitle == null) && addNonExisting) || ( (title != null) && (oldTitle != null ) && modifyExisting) ) {
LDAPAttribute attr = new LDAPAttribute("givenName", title);
modSet.add(new LDAPModification(LDAPModification.REPLACE, attr));
}
LDAPAttribute oldEmail = oldEntry.getAttribute("mail");
if ( ( (email != null) && (oldEmail == null) && addNonExisting) || ( (email != null) && (oldEmail != null ) && modifyExisting) ) {
LDAPAttribute mailAttr = new LDAPAttribute("mail", email);
modSet.add(new LDAPModification(LDAPModification.REPLACE, mailAttr));
}
// All generic personal attributes
modSet.addAll(getModificationSetFromDN(dn, oldEntry, MATCHINGPERSONALATTRIBUTES));
// If we have selected to use the SN (serialNUmber DN field, we will also add it as an attribute
// This is not present in the normal objectClass (inetOrgPerson)
Collection<Integer> usefields = getUseFieldInLdapDN();
if (usefields.contains(Integer.valueOf(DNFieldExtractor.SN))) {
String serno = CertTools.getPartFromDN(dn, "SN");
LDAPAttribute oldserno = oldEntry.getAttribute("SN");
if (((serno != null) && (oldserno == null) && addNonExisting) || ( (serno != null) && (oldserno != null ) && modifyExisting)) {
LDAPAttribute attr = new LDAPAttribute("serialNumber", serno);
modSet.add(new LDAPModification(LDAPModification.REPLACE, attr));
}
}
// If this is an objectClass which is a SecurityObject, such as simpleSecurityObject, we will add the password as well, if not null
if ( (getSetUserPassword() && (password != null)) && (addNonExisting || modifyExisting) ) {
if (log.isDebugEnabled()) {
log.debug("Modifying userPassword attribute");
}
LDAPAttribute attr = new LDAPAttribute("userPassword", password);
modSet.add(new LDAPModification(LDAPModification.REPLACE, attr));
}
}
}
if (log.isTraceEnabled()) {
log.trace("<getModificationSet()");