Example #1
0
 /**
  * Constructor.
  *
  * Tries to bind to the AD domain over LDAP or LDAPs
  *
  * @param array $options     The Adldap configuration options array
  * @param mixed $connection  The connection you'd like to use
  * @param bool  $autoConnect Whether or not you want to connect on construct
  *
  * @throws AdldapException
  */
 public function __construct(array $options = [], $connection = null, $autoConnect = true)
 {
     // Create a new LDAP Connection if one isn't set
     if (!$connection) {
         $connection = new Connections\Ldap();
     }
     $this->setLdapConnection($connection);
     /*
      * If we dev wants to connect automatically, we'll create the
      * configuration object and set the the Adldap properties.
      */
     if ($autoConnect) {
         $configuration = new Configuration($options);
         if ($configuration->countAttributes() > 0) {
             $this->setAccountSuffix($configuration->{'account_suffix'});
             $this->setBaseDn($configuration->{'base_dn'});
             $this->setDomainControllers($configuration->{'domain_controllers'});
             $this->setAdminUsername($configuration->{'admin_username'});
             $this->setAdminPassword($configuration->{'admin_password'});
             $this->setRealPrimaryGroup($configuration->{'real_primarygroup'});
             $this->setUseSSL($configuration->{'use_ssl'});
             $this->setUseTLS($configuration->{'use_tls'});
             $this->setRecursiveGroups($configuration->{'recursive_groups'});
             $this->setFollowReferrals($configuration->{'follow_referrals'});
             if ($configuration->hasAttribute('ad_port')) {
                 $this->setPort($configuration->{'ad_port'});
             }
             if ($configuration->hasAttribute('user_id_key')) {
                 $this->setUserIdKey($configuration->{'user_id_key'});
             }
             if ($configuration->hasAttribute('person_filter')) {
                 $this->setPersonFilter($configuration->{'person_filter'});
             }
             $sso = $configuration->{'sso'};
             /*
              * If we've set SSO to true, we'll make sure we check
              * if SSO is supported, and if so we'll bind it to the
              * current LDAP connection.
              */
             if ($sso) {
                 if ($this->ldapConnection->isSaslSupported()) {
                     $this->ldapConnection->useSSO();
                 }
             }
         }
         // Looks like we're all set. Let's try and connect
         $this->connect();
     }
 }