예제 #1
0
파일: ContactDAO.java 프로젝트: TATRC/KMR2
 /**
  * Update a given field of a contact in LDAP.
  *
  * @param contactDTO
  */
 public void updateContact(ContactDTO contactDTO) {
   Attributes personAttributes = new BasicAttributes();
   BasicAttribute personBasicAttribute = new BasicAttribute("objectclass");
   personBasicAttribute.add("person");
   personAttributes.put(personBasicAttribute);
   personAttributes.put("cn", contactDTO.getCommonName());
   personAttributes.put("sn", contactDTO.getSurname());
   personAttributes.put("description", contactDTO.getDescription());
   ldapTemplate.rebind("cn=" + contactDTO.getCommonName(), null, personAttributes);
 }
예제 #2
0
  /**
   * Synchronisation de la table Operator avec le serveur Ldap. On met à jour ou créé les contacts.
   *
   * @param oldLogin : Eventuel ancien login (en cas de modification).
   * @param fullname : Nom commun
   * @param name : Nom de login
   * @param pass : Mot de passe
   */
  public void synchronisation(String OldLogin, String fullname, String login, String pass) {
    OperatorDao operatorDao = this.simpleConnection();
    Boolean exists;

    Operator_Ldap operator = new Operator_Ldap();
    if (login == null && OldLogin != null) login = OldLogin;

    if (fullname == null) fullname = login;
    operator.setCn(fullname);
    operator.setSn(login);

    if (pass != null) operator.setUserPassword(pass);
    else operator.setUserPassword("");

    if (OldLogin == login || OldLogin == null) {
      // On test si l'utilisateur a déjà été référencé dans ldap.
      try {
        operatorDao.findByPrimaryKey(login);
        exists = true;
      } catch (Exception e) {
        exists = false;
      }

      if (exists == true && login.equals(operator.getSn())) {
        Name dn = buildDn(operator);
        ldapTemplate.rebind(dn, null, buildAttributes(operator));
      } else {
        operatorDao.createOnePerson(operator);
      }
    } else {
      Name dn = buildDn(OldLogin);
      ldapTemplate.unbind(dn);
      operatorDao.createOnePerson(operator);
    }
    operatorDao.disconnection();
  }