public function testGroupMultipleCredentialsFailAddFilterMissingCredentials() { $filter1 = new ezcAuthenticationTokenFilter(self::$data1[0][1], self::$data1[0][2]); $filter2 = new ezcAuthenticationTokenFilter(self::$data2[1][1], self::$data2[1][2]); $options = new ezcAuthenticationGroupOptions(); $options->multipleCredentials = true; $group = new ezcAuthenticationGroupFilter(array(), $options); try { $group->addFilter($filter1); $this->fail('Expected exception was not thrown.'); } catch (ezcAuthenticationException $e) { $this->assertSame('A credentials object must be specified for each filter when the multipleCredentials option is enabled.', $e->getMessage()); } }
public function testGroupOptionsGetSet() { $options = new ezcAuthenticationGroupOptions(); $filter = new ezcAuthenticationGroupFilter(array()); $filter->setOptions($options); $this->assertEquals($options, $filter->getOptions()); }
<?php require_once 'tutorial_autoload.php'; $credentials1 = new ezcAuthenticationPasswordCredentials('jan.modaal', 'b1b3773a05c0ed0176787a4f1574ff0075f7521e'); // incorrect password $credentials2 = new ezcAuthenticationPasswordCredentials('john.doe', 'wpeE20wyWHnLE'); // correct username + password $options = new ezcAuthenticationGroupOptions(); $options->multipleCredentials = true; $options->mode = ezcAuthenticationGroupFilter::MODE_AND; $group = new ezcAuthenticationGroupFilter(array(), $options); $group->addFilter(new ezcAuthenticationHtpasswdFilter('../../tests/filters/htpasswd/data/htpasswd'), $credentials1); $group->addFilter(new ezcAuthenticationHtpasswdFilter('../../tests/filters/htpasswd/data/htpasswd'), $credentials2); $authentication = new ezcAuthentication($credentials1); $authentication->addFilter($group); // add more filters if needed if (!$authentication->run()) { // authentication did not succeed, so inform the user $status = $authentication->getStatus(); $err = array(array('ezcAuthenticationHtpasswdFilter' => array(ezcAuthenticationHtpasswdFilter::STATUS_OK => '', ezcAuthenticationHtpasswdFilter::STATUS_USERNAME_INCORRECT => 'Incorrect username ' . $credentials1->id, ezcAuthenticationHtpasswdFilter::STATUS_PASSWORD_INCORRECT => 'Incorrect password for ' . $credentials1->id)), array('ezcAuthenticationHtpasswdFilter' => array(ezcAuthenticationHtpasswdFilter::STATUS_OK => '', ezcAuthenticationHtpasswdFilter::STATUS_USERNAME_INCORRECT => 'Incorrect username ' . $credentials2->id, ezcAuthenticationHtpasswdFilter::STATUS_PASSWORD_INCORRECT => 'Incorrect password for ' . $credentials2->id))); foreach ($status as $line => $error) { list($key, $value) = each($error); echo $err[$line][$key][$value] . "\n"; } } else { // authentication succeeded, so allow the user to see his content }