public boolean canConnect() throws ValidationException {

    try {
      // now try to connect
      String dnName =
          ldapAccess.dnSearch(
              this.dirProperties, this.baseDN, this.attrMap.get(SettingType.LDAP_ATTR_UID) + "=*");

      if (dnName == null) {

        return false;
      }

      return true;

    } catch (NameNotFoundException nnfe) {
      // sessionCtx.setRollbackOnly();
      ValidationException vf =
          new ValidationException(
              ReasonEnum.LDAP_BASE_DN_INVALID, null, new Object[] {this.baseDN});
      logger.logError(
          Log4jLogger.SYSTEM_LOG,
          vf,
          LogMessageIdentifier.ERROR_LDAP_ACCESS_FAILED,
          nnfe.getMessage());
      throw vf;
    } catch (NamingException e1) {
      // sessionCtx.setRollbackOnly();
      Object[] params =
          new Object[] {this.dirProperties.get(Context.PROVIDER_URL), e1.getMessage()};
      ValidationException vf =
          new ValidationException(ReasonEnum.LDAP_CONNECTION_REFUSED, null, params);
      logger.logError(
          Log4jLogger.SYSTEM_LOG,
          vf,
          LogMessageIdentifier.ERROR_LDAP_SYSTEM_CONNECTION_REFUSED,
          "LDAPuser");
      throw vf;
    }
  }
  /**
   * Validate the LDAP properties by performing a search request.
   *
   * @param baseDN the baseDN
   * @return the read attribute
   * @throws ValidationException Thrown in case the LDAP access failed or no record was found
   */
  public VOUserDetails validateLdapProperties(VOUserDetails user) throws ValidationException {

    LdapVOUserDetailsMapper mapper = new LdapVOUserDetailsMapper(user, this.attrMap);
    VOUserDetails tmpUser = new VOUserDetails();
    tmpUser.setAdditionalName(user.getAdditionalName());
    tmpUser.setEMail(user.getEMail());
    tmpUser.setFirstName(user.getFirstName());
    tmpUser.setLastName(user.getLastName());
    tmpUser.setLocale(user.getLocale());

    try {

      String dnName =
          ldapAccess.dnSearch(
              this.dirProperties,
              this.baseDN,
              this.attrMap.get(SettingType.LDAP_ATTR_UID) + "=" + user.getUserId());

      if (dnName == null) {
        // sessionCtx.setRollbackOnly();
        ValidationException vf =
            new ValidationException(
                ReasonEnum.LDAP_USER_NOT_FOUND, null, new Object[] {user.getUserId()});
        logger.logError(
            Log4jLogger.SYSTEM_LOG,
            vf,
            LogMessageIdentifier.ERROR_LDAP_SEARCH_OF_USER_FAILED,
            user.getUserId());
        throw vf;
      }

      List<VOUserDetails> result =
          ldapAccess.search(
              this.dirProperties,
              this.baseDN,
              this.attrMap.get(SettingType.LDAP_ATTR_UID) + "=" + user.getUserId(),
              mapper,
              true);
      int size = result.size();
      if (size == 1) {
        user = result.get(0);
        if (user.getLocale() != null
            && !user.getLocale().isEmpty()
            && user.getLocale().length() > LOCAL_LENGTH) {
          user.setLocale(user.getLocale().substring(0, LOCAL_LENGTH));
        }
        validateLdapPropertyValue(
            this.attrMap,
            SettingType.LDAP_ATTR_ADDITIONAL_NAME,
            tmpUser.getAdditionalName(),
            user.getAdditionalName());
        validateLdapPropertyValue(
            this.attrMap, SettingType.LDAP_ATTR_EMAIL, tmpUser.getEMail(), user.getEMail());
        validateLdapPropertyValue(
            this.attrMap,
            SettingType.LDAP_ATTR_FIRST_NAME,
            tmpUser.getFirstName(),
            user.getFirstName());
        validateLdapPropertyValue(
            this.attrMap,
            SettingType.LDAP_ATTR_LAST_NAME,
            tmpUser.getLastName(),
            user.getLastName());
        validateLdapPropertyValue(
            this.attrMap, SettingType.LDAP_ATTR_LOCALE, tmpUser.getLocale(), user.getLocale());

        return result.get(0);
      } else if (size == 0) {
        // sessionCtx.setRollbackOnly();
        ValidationException vf =
            new ValidationException(
                ReasonEnum.LDAP_USER_NOT_FOUND, null, new Object[] {user.getUserId()});
        logger.logError(
            Log4jLogger.SYSTEM_LOG,
            vf,
            LogMessageIdentifier.ERROR_VALIDATION_PARAMETER_LDAP_FOUND_ERROR,
            "LDAP User");
        throw vf;
      } else {
        // sessionCtx.setRollbackOnly();
        ValidationException vf =
            new ValidationException(
                ReasonEnum.LDAP_USER_NOT_UNIQUE, null, new Object[] {user.getUserId()});
        logger.logError(
            Log4jLogger.SYSTEM_LOG,
            vf,
            LogMessageIdentifier.ERROR_VALIDATION_PARAMETER_LDAP_FOUND_ERROR,
            "LDAP User");
        throw vf;
      }
    } catch (NameNotFoundException nnfe) {
      // sessionCtx.setRollbackOnly();
      ValidationException vf =
          new ValidationException(
              ReasonEnum.LDAP_BASE_DN_INVALID, null, new Object[] {this.baseDN});
      logger.logError(
          Log4jLogger.SYSTEM_LOG,
          vf,
          LogMessageIdentifier.ERROR_LDAP_ACCESS_FAILED,
          nnfe.getMessage());
      throw vf;
    } catch (NamingException e1) {
      // sessionCtx.setRollbackOnly();
      Object[] params = new Object[] {dirProperties.get(Context.PROVIDER_URL), e1.getMessage()};
      ValidationException vf =
          new ValidationException(ReasonEnum.LDAP_CONNECTION_REFUSED, null, params);
      logger.logError(
          Log4jLogger.SYSTEM_LOG,
          vf,
          LogMessageIdentifier.ERROR_LDAP_SYSTEM_CONNECTION_REFUSED,
          "LDAPuser");
      throw vf;
    }
  }