protected LDAPAttributeSet getAttributeSet(Certificate cert, String objectclass, String dn, String email, boolean extra, boolean person,
String password, ExtendedInformation extendedinformation) {
if (log.isTraceEnabled()) {
log.trace(">getAttributeSet(dn="+dn+", email="+email+")");
}
LDAPAttributeSet attributeSet = new LDAPAttributeSet();
LDAPAttribute attr = new LDAPAttribute("objectclass");
// The full LDAP object tree is divided with ; in the objectclass
StringTokenizer token = new StringTokenizer(objectclass,";");
while (token.hasMoreTokens()) {
String value = token.nextToken();
if (log.isDebugEnabled()) {
log.debug("Adding objectclass value: "+value);
}
attr.addValue(value);
}
attributeSet.add(attr);
/* To Add an entry to the directory,
* -- Create the attributes of the entry and add them to an attribute set
* -- Specify the DN of the entry to be created
* -- Create an LDAPEntry object with the DN and the attribute set
* -- Call the LDAPConnection add method to add it to the directory
*/
if (extra) {
attributeSet.addAll(getAttributesFromDN(dn, MATCHINGEXTRAATTRIBUTES));
// Only persons have (normally) all these extra attributes.
// A CA might have them if you don't use the default objectClass, but we don't
// handle that case.
if (person) {
// First get the easy ones where LDAP and EJBCA spelling is the same
attributeSet.addAll(getAttributesFromDN(dn, MATCHINGPERSONALATTRIBUTES));
// sn means surname in LDAP, and is required for persons
String cn = CertTools.getPartFromDN(dn, "CN");
String sn = CertTools.getPartFromDN(dn, "SURNAME");
if ( (sn == null) && (cn != null) ) {
// Only construct this if we are the standard object class
if (getUserObjectClass().endsWith("inetOrgPerson")) {
// Take surname to be the last part of the cn
int index = cn.lastIndexOf(' ');
if (index <=0) {
// If there is no natural sn, use cn since sn is required
sn = cn;
} else {
if (index < cn.length()) {
sn = new String(cn.substring(index+1));
}
}
}
}
if (sn != null) {
attributeSet.add(new LDAPAttribute("sn", sn));
}
// gn means givenname in LDAP, and is required for persons
String gn = CertTools.getPartFromDN(dn, "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) {
attributeSet.add(new LDAPAttribute("givenName", gn));
}
String title = CertTools.getPartFromDN(dn, "T");
if (title != null) {
attributeSet.add(new LDAPAttribute("title", title));
}
if (email != null) {
attributeSet.add(new LDAPAttribute("mail", email));
}
// 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)
// Modifying the schema is as simple as adding serialNumber as MAY in the inetOrgPerson object class in inetorgperson.schema.
Collection<Integer> usefields = getUseFieldInLdapDN();
if (usefields.contains(Integer.valueOf(DNFieldExtractor.SN))) {
String serno = CertTools.getPartFromDN(dn, "SN");
if (serno != null) {
attributeSet.add(new LDAPAttribute("serialNumber", serno));
}
}
// 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)) {
if (log.isDebugEnabled()) {
log.debug("Adding userPassword attribute");
}
attributeSet.add(new LDAPAttribute("userPassword", password));
}
}
}
if (log.isTraceEnabled()) {