Пример #1
0
 public function GetLdapUser($username)
 {
     $attributes = $this->options->Attributes();
     Log::Debug('ActiveDirectory - Loading user attributes: %s', implode(', ', $attributes));
     $entries = $this->ldap->user()->infoCollection($username, $attributes);
     /** @var adLDAPUserCollection $entries */
     if ($entries && count($entries) > 0) {
         return new ActiveDirectoryUser($entries, $this->options->AttributeMapping());
     } else {
         Log::Debug('ActiveDirectory - Could not load user details for user %s. Reason %s', $username, $this->ldap->getLastError());
     }
     return null;
 }
Пример #2
0
 public function Validate($username, $password)
 {
     if ($this->AreCredentialsKnown()) {
         $username = ServiceLocator::GetServer()->GetHeader('AUTH_USER');
         $username = $this->CleanUsername($username);
         Log::Debug('ActiveDirectory Validate trying to load details for authenticated user: %s', $username);
         $this->ldap->Connect();
         $this->user = $this->ldap->GetLdapUser($username);
         return $this->LdapUserExists();
     }
     $this->password = $password;
     $username = $this->CleanUsername($username);
     $connected = $this->ldap->Connect();
     if (!$connected) {
         throw new Exception('Could not connect to ActiveDirectory LDAP server. Please check your ActiveDirectory LDAP configuration settings');
     }
     $isValid = $this->ldap->Authenticate($username, $password);
     Log::Debug('Result of ActiveDirectory LDAP Authenticate for user %s: %d', $username, $isValid);
     if ($isValid) {
         $this->user = $this->ldap->GetLdapUser($username);
         $userLoaded = $this->LdapUserExists();
         if (!$userLoaded) {
             Log::Error('Could not load user details from ActiveDirectory LDAP. Check your basedn setting. User: %s', $username);
         }
         return $userLoaded;
     } else {
         if ($this->options->RetryAgainstDatabase()) {
             return $this->authToDecorate->Validate($username, $password);
         }
     }
     return false;
 }
Пример #3
0
 public function testGetsDefaultAttributes()
 {
     $configFile = new FakeConfigFile();
     $configFile->SetKey(ActiveDirectoryConfig::ATTRIBUTE_MAPPING, '');
     $this->fakeConfig->SetFile(ActiveDirectoryConfig::CONFIG_ID, $configFile);
     $options = new ActiveDirectoryOptions();
     $expectedAttributes = array('sn', 'givenname', 'mail', 'telephonenumber', 'physicaldeliveryofficename', 'title');
     $this->assertEquals($expectedAttributes, $options->Attributes());
 }