You are here

protected function LdapServerAdmin::validate in Lightweight Directory Access Protocol (LDAP) 7.2

Same name and namespace in other branches
  1. 8.2 ldap_servers/LdapServerAdmin.class.php \LdapServerAdmin::validate()
  2. 7 ldap_servers/LdapServerAdmin.class.php \LdapServerAdmin::validate()
1 call to LdapServerAdmin::validate()
LdapServerAdmin::drupalFormValidate in ldap_servers/LdapServerAdmin.class.php

File

ldap_servers/LdapServerAdmin.class.php, line 367

Class

LdapServerAdmin

Code

protected function validate($op) {
  $errors = [];
  if ($op == 'add') {
    $ldap_servers = $this
      ->getLdapServerObjects(NULL, 'all');
    if (count($ldap_servers)) {
      foreach ($ldap_servers as $sid => $ldap_server) {
        if ($this->name == $ldap_server->name) {
          $errors['name'] = t('An LDAP server configuration with the  name %name already exists.', [
            '%name' => $this->name,
          ]);
        }
        elseif ($this->sid == $ldap_server->sid) {
          $errors['sid'] = t('An LDAP server configuration with the  id %sid  already exists.', [
            '%sid' => $this->sid,
          ]);
        }
      }
    }
  }

  // Check that no modules use this server.
  if ($this->status == 0) {
    $warnings = module_invoke_all('ldap_server_in_use', $this->sid, $this->name);
    if (count($warnings)) {
      $errors['status'] = join("<br/>", array_values($warnings));
    }
  }
  if (!is_numeric($this->port)) {
    $errors['port'] = t('The TCP/IP port must be an integer.');
  }
  if ($this->bind_method == LDAP_SERVERS_BIND_METHOD_USER && !$this->user_dn_expression) {
    $errors['user_dn_expression'] = t('When using "Bind with Users Credentials", Expression for user DN is required');
  }
  if ($this->mail_attr && $this->mail_template) {
    $errors['mail_attr'] = t('Mail attribute or Mail Template may be used.  Not both.');
  }
  if ($this->bind_method == LDAP_SERVERS_BIND_METHOD_SERVICE_ACCT && !$this->binddn) {
    $errors['binddn'] = t('When using "Bind with Service Account", Bind DN is required.');
  }
  if ($op == 'add') {
    if ($this->bind_method == LDAP_SERVERS_BIND_METHOD_SERVICE_ACCT && ($op == 'add' && !$this->bindpw_new || $op != 'add' && !$this->bindpw)) {
      $errors['bindpw'] = t('When using "Bind with Service Account", Bind password is required.');
    }
  }
  return $errors;
}