예제 #1
0
 /**
  * @param $username string
  * @param $password string
  * @param $filter string
  * @return bool
  */
 public function Authenticate($username, $password, $filter)
 {
     $this->PopulateUser($username, $filter);
     if ($this->user == null) {
         return false;
     }
     Log::Debug('Trying to authenticate user %s against ldap with dn %s', $username, $this->user->GetDn());
     $result = $this->ldap->bind($this->user->GetDn(), $password);
     if ($result === true) {
         Log::Debug('Authentication was successful');
         return true;
     }
     if (Net_LDAP2::isError($result)) {
         $message = 'Could not authenticate user against ldap %s: ' . $result->getMessage();
         Log::Error($message, $username);
     }
     return false;
 }
 /**
  * Add an entry to our document.
  * 
  * @param  LdapUser $userOrGroup
  * @return void
  * @access protected
  * @since 3/30/09
  */
 protected function addEntry(LdapUser $userOrGroup)
 {
     try {
         $elem = $this->doc->documentElement->appendChild($this->doc->createElementNS('http://www.yale.edu/tp/cas', 'cas:entry'));
         if ($userOrGroup->isGroup()) {
             $elem->appendChild($this->doc->createElementNS('http://www.yale.edu/tp/cas', 'cas:group', htmlspecialchars($userOrGroup->getId())));
         } else {
             $elem->appendChild($this->doc->createElementNS('http://www.yale.edu/tp/cas', 'cas:user', $userOrGroup->getId()));
         }
         foreach ($userOrGroup->getAttributeKeys() as $attribute) {
             foreach ($userOrGroup->getAttributeValues($attribute) as $value) {
                 $attraElem = $elem->appendChild($this->doc->createElementNS('http://www.yale.edu/tp/cas', 'cas:attribute'));
                 $attraElem->setAttribute('name', $attribute);
                 $attraElem->setAttribute('value', $value);
             }
         }
     } catch (OperationFailedException $e) {
         print_r($userOrGroup);
         throw $e;
     }
 }
예제 #3
0
 /**
  * Add an entry to our document.
  * 
  * @param  LdapUser $userOrGroup
  * @return void
  * @access protected
  * @since 3/30/09
  */
 protected function addEntry(LdapUser $userOrGroup)
 {
     try {
         print "\n\t<cas:entry>";
         if ($userOrGroup->isGroup()) {
             print "\n\t\t<cas:group>" . htmlentities($userOrGroup->getId()) . "</cas:group>";
         } else {
             print "\n\t\t<cas:user>" . htmlentities($userOrGroup->getId()) . "</cas:user>";
         }
         foreach ($userOrGroup->getAttributeKeys() as $attribute) {
             foreach ($userOrGroup->getAttributeValues($attribute) as $value) {
                 print "\n\t\t<cas:attribute name=\"" . $attribute . "\" value=\"" . htmlentities($value) . "\"/>";
             }
         }
         print "\n\t</cas:entry>";
     } catch (OperationFailedException $e) {
         print_r($userOrGroup);
         throw $e;
     }
 }
예제 #4
0
 /**
  * Answer the values of an attribute
  * 
  * @param string $attribute The Ldap key for an attribute
  * @return array
  * @access protected
  * @since 3/30/09
  */
 protected function getLdapAttributeValues($attribute)
 {
     $attribute = strtolower($attribute);
     if ($attribute == 'member') {
         return $this->members;
     }
     return parent::getLdapAttributeValues($attribute);
 }
예제 #5
0
파일: Ldap.php 프로젝트: hugutux/booked
 private function Synchronize($username)
 {
     $registration = $this->GetRegistration();
     $registration->Synchronize(new AuthenticatedUser($username, $this->user->GetEmail(), $this->user->GetFirstName(), $this->user->GetLastName(), $this->password, Configuration::Instance()->GetKey(ConfigKeys::LANGUAGE), Configuration::Instance()->GetDefaultTimezone(), $this->user->GetPhone(), $this->user->GetInstitution(), $this->user->GetTitle()));
 }
예제 #6
0
 public function testMapsUserAttributes()
 {
     $mapping = array('sn' => 'sn', 'givenname' => 'givenname', 'mail' => 'fooName');
     $entry = new TestLdapEntry();
     $entry->Set('sn', 'sn');
     $entry->Set('givenname', 'given');
     $entry->Set('fooName', 'foo');
     $entry->Set('telephonenumber', 'phone');
     $user = new LdapUser($entry, $mapping);
     $this->assertEquals('sn', $user->GetLastName());
     $this->assertEquals('given', $user->GetFirstName());
     $this->assertEquals('foo', $user->GetEmail());
     $this->assertEquals('phone', $user->GetPhone());
 }