/** * Add a new contact to LDAP. * * @param contactDTO */ public void insertContact(ContactDTO contactDTO) { Attributes personAttributes = new BasicAttributes(); BasicAttribute personBasicAttribute1 = new BasicAttribute("objectclass"); BasicAttribute personBasicAttribute2 = new BasicAttribute("objectclass"); BasicAttribute personBasicAttribute3 = new BasicAttribute("objectclass"); BasicAttribute personBasicAttribute4 = new BasicAttribute("objectclass"); personBasicAttribute1.add("person"); personBasicAttribute2.add("inetOrgPerson"); personBasicAttribute3.add("organizationalPerson"); personBasicAttribute4.add("kmr-orgPerson"); personAttributes.put(personBasicAttribute1); personAttributes.put(personBasicAttribute2); personAttributes.put(personBasicAttribute3); personAttributes.put(personBasicAttribute4); if (null != contactDTO.getCommonName() && !contactDTO.getCommonName().isEmpty()) { personAttributes.put("cn", contactDTO.getCommonName()); } if (null != contactDTO.getSurname() && !contactDTO.getSurname().isEmpty()) { personAttributes.put("sn", contactDTO.getSurname()); } if (null != contactDTO.getGivenName() && !contactDTO.getGivenName().isEmpty()) { personAttributes.put("givenName", contactDTO.getGivenName()); } if (null != contactDTO.getInitials() && !contactDTO.getInitials().isEmpty()) { personAttributes.put("initials", contactDTO.getInitials()); } if (null != contactDTO.getUid() && !contactDTO.getUid().isEmpty()) { personAttributes.put("uid", contactDTO.getUid()); } if (null != contactDTO.getHomePhone() && !contactDTO.getHomePhone().isEmpty()) { personAttributes.put("homePhone", contactDTO.getHomePhone()); } if (null != contactDTO.getMobile() && !contactDTO.getMobile().isEmpty()) { personAttributes.put("mobile", contactDTO.getMobile()); } if (null != contactDTO.getTelephoneNumber() && !contactDTO.getTelephoneNumber().isEmpty()) { personAttributes.put("telephoneNumber", contactDTO.getTelephoneNumber()); } if (null != contactDTO.getPostalAddress() && !contactDTO.getPostalAddress().isEmpty()) { personAttributes.put("postalAddress", contactDTO.getPostalAddress()); } if (null != contactDTO.getStreet() && !contactDTO.getStreet().isEmpty()) { personAttributes.put("street", contactDTO.getStreet()); } if (null != contactDTO.getCity() && !contactDTO.getCity().isEmpty()) { personAttributes.put("l", contactDTO.getCity()); } if (null != contactDTO.getState() && !contactDTO.getState().isEmpty()) { personAttributes.put("st", contactDTO.getState()); } if (null != contactDTO.getPostalCode() && !contactDTO.getPostalCode().isEmpty()) { personAttributes.put("postalCode", contactDTO.getPostalCode()); } if (null != contactDTO.getMail() && !contactDTO.getMail().isEmpty()) { personAttributes.put("mail", contactDTO.getMail()); } if (null != contactDTO.getUserPassword()) { personAttributes.put("userPassword", contactDTO.getUserPassword()); } // personAttributes.put("sn", contactDTO.getSSN()); if (null != contactDTO.getDescription() && !contactDTO.getDescription().isEmpty()) { personAttributes.put("description", contactDTO.getDescription()); } try { ldapTemplate.bind("cn=" + contactDTO.getCommonName(), null, personAttributes); } catch (NameAlreadyBoundException ne) { logger.severe( "The name provided: " + contactDTO.getCommonName() + " is already in the directory"); } }