Author: as
Date: Fri Aug 10 13:38:55 2007
New Revision: 5871
Log:
- Implemented feature request #11001: Added multiple credentials support in
the Group filter.
- Fixed the way the status is retrieved from the Group filter, there should
be no BC break for this.
Added:
trunk/Authentication/docs/tutorial/tutorial_multiple_credentials.php
(with props)
trunk/Authentication/tests/filters/group/group_multiple_test.php (with
props)
Modified:
trunk/Authentication/ChangeLog
trunk/Authentication/docs/tutorial.txt
trunk/Authentication/src/authentication.php
trunk/Authentication/src/filters/group/group_filter.php
trunk/Authentication/src/options/group_options.php
trunk/Authentication/tests/filters/group/group_test.php
trunk/Authentication/tests/suite.php
Modified: trunk/Authentication/ChangeLog
==============================================================================
--- trunk/Authentication/ChangeLog [iso-8859-1] (original)
+++ trunk/Authentication/ChangeLog [iso-8859-1] Fri Aug 10 13:38:55 2007
@@ -5,6 +5,8 @@
authentication.
- Implemented feature request #10971: Added the possibility to fetch extra
data during authentication for Database, LDAP, OpenID and TypeKey filters.
+- Implemented feature request #11001: Added multiple credentials support in
+ the Group filter.
1.0 - Monday 02 July 2007
Modified: trunk/Authentication/docs/tutorial.txt
==============================================================================
--- trunk/Authentication/docs/tutorial.txt [iso-8859-1] (original)
+++ trunk/Authentication/docs/tutorial.txt [iso-8859-1] Fri Aug 10 13:38:55 2007
@@ -31,7 +31,9 @@
ezcAuthenticationCredentials
Structure which holds user credentials. Types are id credentials
(ezcAuthenticationIdCredentials) and id + password credentials
- (ezcAuthenticationPasswordCredentials).
+ (ezcAuthenticationPasswordCredentials). Usually there is only one credentials
+ object in the application. Multiple credentials can be used via the
+ ezcAuthenticationGroupFilter class.
ezcAuthenticationSession
Used to store the authenticated username and the timestamp between requests.
@@ -190,6 +192,46 @@
content.
+Multiple credentials
+````````````````````
+
+To be able to use multiple credentials for authentication (each filter with its
+own credentials), you must enable the multipleCredentials option for
+ezcAuthenticationGroupFilter.
+
+The following example demonstrates how to use multiple credentials.
+
+.. include:: tutorial/tutorial_multiple_credentials.php
+ :literal:
+
+First, two credentials objects are created.
+
+A Group filter is created with the multipleCredentials option enabled.
+
+Two Htpasswd filters are added to the Group filter, each with their own
+credentials.
+
+An Authentication object is created with a default credentials (which would
+have been used for other filters outside the Group filter, and to save the
+authenticated state in the session).
+
+The Group filter is then added to the Authentication object.
+
+After running the authentication (line 19), if the usernames and the passwords
+do not pass through the htpasswd filters, then the credentials are incorrect
and
+the user must be informed. The getStatus() method is used for this. The values
+in the status returned must be cycled through and for each value a response is
+created for the user ("Username incorrect john.doe", "Password incorrect for
+john.doe", etc).
+
+If run() returned true (line 44) then the user is logged-in and he can see his
+content.
+
+The above example will output: ::
+
+ Incorrect password for jan.modaal
+
+
Htpasswd
--------
Added: trunk/Authentication/docs/tutorial/tutorial_multiple_credentials.php
==============================================================================
--- trunk/Authentication/docs/tutorial/tutorial_multiple_credentials.php (added)
+++ trunk/Authentication/docs/tutorial/tutorial_multiple_credentials.php
[iso-8859-1] Fri Aug 10 13:38:55 2007
@@ -1,0 +1,48 @@
+<?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
+}
+?>
Propchange: trunk/Authentication/docs/tutorial/tutorial_multiple_credentials.php
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/Authentication/src/authentication.php
==============================================================================
--- trunk/Authentication/src/authentication.php [iso-8859-1] (original)
+++ trunk/Authentication/src/authentication.php [iso-8859-1] Fri Aug 10
13:38:55 2007
@@ -225,21 +225,29 @@
public function run()
{
$code = ezcAuthenticationFilter::STATUS_OK;
+
+ $credentials = $this->credentials;
+
if ( isset( $this->session ) )
{
- $code = $this->session->run( $this->credentials );
+ $code = $this->session->run( $credentials );
$this->status->append( get_class( $this->session ), $code );
}
+
if ( !isset( $this->session ) || $code ===
ezcAuthenticationSession::STATUS_EMPTY )
{
foreach ( $this->filters as $filter )
{
- $code = $filter[0]->run( $this->credentials );
+ $code = $filter[0]->run( $credentials );
if ( $filter[0] instanceof ezcAuthenticationGroupFilter )
{
$statuses = $filter[0]->status->get();
- foreach ( $statuses as $key => $value )
+
+ // append the statuses from the filters in the group to the
+ // status of the Authentication object
+ foreach ( $statuses as $status )
{
+ list( $key, $value ) = each( $status );
$this->status->append( $key, $value );
}
}
@@ -247,10 +255,12 @@
{
$this->status->append( get_class( $filter[0] ), $code );
}
+
if ( ( $filter[1] === true && $code !==
ezcAuthenticationFilter::STATUS_OK ) )
{
return false;
}
+
if ( $filter[1] === true && $code ===
ezcAuthenticationFilter::STATUS_OK )
{
break;
@@ -261,14 +271,17 @@
{
return false;
}
+
if ( $code !== ezcAuthenticationFilter::STATUS_OK )
{
return false;
}
+
if ( isset( $this->session ) )
{
- $this->session->save( $this->credentials->__toString() );
- }
+ $this->session->save( $credentials->__toString() );
+ }
+
return true;
}
@@ -290,13 +303,13 @@
/**
* Returns the status of authentication.
*
- * The format of the returned array is array( class => code ).
+ * The format of the returned array is array( array( class => code ) ).
*
* Example:
* <code>
* array(
- * 'ezcAuthenticationSession' => ezcAuthenticationSession::STATUS_EMPTY,
- * 'ezcAuthenticationDatabaseFilter' =>
ezcAuthenticationDatabaseFilter::STATUS_PASSWORD_INCORRECT
+ * array( 'ezcAuthenticationSession' =>
ezcAuthenticationSession::STATUS_EMPTY ),
+ * array( 'ezcAuthenticationDatabaseFilter' =>
ezcAuthenticationDatabaseFilter::STATUS_PASSWORD_INCORRECT )
* );
* </code>
*
Modified: trunk/Authentication/src/filters/group/group_filter.php
==============================================================================
--- trunk/Authentication/src/filters/group/group_filter.php [iso-8859-1]
(original)
+++ trunk/Authentication/src/filters/group/group_filter.php [iso-8859-1] Fri
Aug 10 13:38:55 2007
@@ -53,19 +53,19 @@
* // authentication did not succeed, so inform the user
* $status = $authentication->getStatus();
* $err = array(
- * 'ezcAuthenticationLdapFilter' => array(
+ * array( 'ezcAuthenticationLdapFilter' => array(
* ezcAuthenticationLdapFilter::STATUS_USERNAME_INCORRECT =>
'Incorrect username',
* ezcAuthenticationLdapFilter::STATUS_PASSWORD_INCORRECT =>
'Incorrect password'
- * ),
- * 'ezcAuthenticationDatabaseFilter' => array(
+ * ) ),
+ * array( 'ezcAuthenticationDatabaseFilter' => array(
* ezcAuthenticationDatabaseFilter::STATUS_USERNAME_INCORRECT
=> 'Incorrect username',
* ezcAuthenticationDatabaseFilter::STATUS_PASSWORD_INCORRECT
=> 'Incorrect password'
- * )
+ * ) )
* );
- * foreach ( $status as $line )
+ * foreach ( $status as $line => $error )
* {
- * list( $key, $value ) = each( $line );
- * echo $err[$key][$value] . "\n";
+ * list( $key, $value ) = each( $error );
+ * echo $err[$line][$key][$value] . "\n";
* }
* }
* else
@@ -74,6 +74,59 @@
* }
* </code>
*
+ * It is possible to use multiple credentials when grouping filters together,
by
+ * enabling the option multipleCredentials for the Group filter object. When
this
+ * option is enabled, each filter added to the group must have a credentials
+ * object passed along with it.
+ *
+ * Example of using the Group filter to handle multiple credentials:
+ * <code>
+ * $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
+ * }
+ * </code>
+ *
* @property ezcAuthenticationStatus $status
* The status object which holds the status of the run filters.
*
@@ -116,14 +169,60 @@
/**
* Creates a new object of this class.
*
- * @param array(ezcAuthenticationFilter) $filters Authentication filters
+ * The filters can be specified as an array of filter objects, or as an
+ * array of array(fiter,credentials) when the multipleCredentials option is
+ * enabled.
+ *
+ * Example of using multipleCredentials:
+ * <code>
+ * $credentials1 = new ezcAuthenticationPasswordCredentials( 'john.doe',
'1234' );
+ * $credentials1 = new ezcAuthenticationPasswordCredentials( 'jan.modaal',
'qwerty' );
+ *
+ * $filter1 = new ezcAuthenticationHtpasswdFilter( '/etc/htpasswd1' );
+ * $filter2 = new ezcAuthenticationHtpasswdFilter( '/etc/htpasswd2' );
+ *
+ * // enable multiple credentials
+ * $options = new ezcAuthenticationGroupOptions();
+ * $options->multipleCredentials = true;
+ *
+ * // add the filters to the group with the constructor
+ * $group = new ezcAuthenticationGroupFilter( array(
+ * array( $filter1, $credentials1 ),
+ * array( $filter2, $credentials2 ) ), $options );
+ *
+ * // the filters can also be added to the group with addFilter()
+ * </code>
+ *
+ * @throws ezcAuthenticationException
+ * if the multipleCredentials option is enabled and a credentials
+ * object was not specified
+ * @param array(ezcAuthenticationFilter|mixed) $filters Authentication
filters
* @param ezcAuthenticationGroupOptions $options Options for this class
*/
public function __construct( array $filters, ezcAuthenticationGroupOptions
$options = null )
{
- $this->filters = $filters;
+ $this->options = ( $options === null ) ? new
ezcAuthenticationGroupOptions() : $options;
+
+ foreach ( $filters as $filter )
+ {
+ if ( is_array( $filter ) )
+ {
+ if ( count( $filter ) > 1 )
+ {
+ $this->addFilter( $filter[0], $filter[1] );
+ }
+ else
+ {
+ $this->addFilter( $filter[0] );
+ }
+ }
+ else
+ {
+ $this->addFilter( $filter );
+ }
+ }
+
$this->status = new ezcAuthenticationStatus();
- $this->options = ( $options === null ) ? new
ezcAuthenticationGroupOptions() : $options;
}
/**
@@ -217,8 +316,11 @@
$success = false;
foreach ( $this->filters as $filter )
{
- $code = $filter->run( $credentials );
- $this->status->append( get_class( $filter ), $code );
+ $credentials = ( $this->options->multipleCredentials === true
) ? $filter[1] :
+
$credentials;
+
+ $code = $filter[0]->run( $credentials );
+ $this->status->append( get_class( $filter[0] ), $code );
if ( $code === self::STATUS_OK )
{
$success = true;
@@ -231,8 +333,11 @@
$success = true;
foreach ( $this->filters as $filter )
{
- $code = $filter->run( $credentials );
- $this->status->append( get_class( $filter ), $code );
+ $credentials = ( $this->options->multipleCredentials === true
) ? $filter[1] :
+
$credentials;
+
+ $code = $filter[0]->run( $credentials );
+ $this->status->append( get_class( $filter[0] ), $code );
if ( $code !== self::STATUS_OK )
{
$success = false;
@@ -250,11 +355,50 @@
/**
* Adds an authentication filter at the end of the filter list.
*
+ *
+ * Example of using multipleCredentials:
+ * <code>
+ * $credentials1 = new ezcAuthenticationPasswordCredentials( 'john.doe',
'1234' );
+ * $credentials1 = new ezcAuthenticationPasswordCredentials( 'jan.modaal',
'qwerty' );
+ *
+ * $filter1 = new ezcAuthenticationHtpasswdFilter( '/etc/htpasswd1' );
+ * $filter2 = new ezcAuthenticationHtpasswdFilter( '/etc/htpasswd2' );
+ *
+ * // enable multiple credentials
+ * $options = new ezcAuthenticationGroupOptions();
+ * $options->multipleCredentials = true;
+ *
+ * // add the filters to the group with addFilter()
+ * $group = new ezcAuthenticationGroupFilter( array(), $options );
+ * $group->addFilter( $filter1, $credentials1 );
+ * $group->addFilter( $filter2, $credentials2 );
+ *
+ * // the filters can also be added to the group with the constructor
+ * </code>
+ *
+ * @throws ezcAuthenticationException
+ * if the multipleCredentials option is enabled and a credentials
+ * object was not specified
* @param ezcAuthenticationFilter $filter The authentication filter to add
- */
- public function addFilter( ezcAuthenticationFilter $filter )
- {
- $this->filters[] = $filter;
+ * @param ezcAuthenticationCredentials $credentials Credentials object
associated
+ * with $filter if the
multipleCredentials
+ * option is enabled
+ */
+ public function addFilter( ezcAuthenticationFilter $filter,
ezcAuthenticationCredentials $credentials = null )
+ {
+ if ( $this->options->multipleCredentials === true )
+ {
+ if ( $credentials === null )
+ {
+ throw new ezcAuthenticationException( 'A credentials object
must be specified for each filter when the multipleCredentials option is
enabled.' );
+ }
+
+ $this->filters[] = array( $filter, $credentials );
+ }
+ else
+ {
+ $this->filters[] = array( $filter );
+ }
}
}
?>
Modified: trunk/Authentication/src/options/group_options.php
==============================================================================
--- trunk/Authentication/src/options/group_options.php [iso-8859-1] (original)
+++ trunk/Authentication/src/options/group_options.php [iso-8859-1] Fri Aug 10
13:38:55 2007
@@ -16,6 +16,7 @@
* <code>
* $options = new ezcAuthenticationGroupOptions();
* $options->mode = ezcAuthenticationGroupFilter::MODE_AND;
+ * $options->mode->multipleCredentials = false;
*
* // $filter1 and $filter2 are authentication filters which need all to
succeed
* // in order for the group to succeed
@@ -29,6 +30,11 @@
* succeed.
* - ezcAuthenticationGroupFilter::MODE_AND: all filters in the
group
* need to succeed in order for the group to succeed.
+ * @property bool $multipleCredentials
+ * If enabled (set to true), each filter must be added to the group
+ * along with a credentials object (through the constructor or with
+ * addFilter()). By default is false (the credentials from the
+ * ezcAuthentication object are used for all filters in the group).
*
* @package Authentication
* @version //autogen//
@@ -47,6 +53,7 @@
public function __construct( array $options = array() )
{
$this->mode = ezcAuthenticationGroupFilter::MODE_OR;
+ $this->multipleCredentials = false;
parent::__construct( $options );
}
@@ -78,6 +85,14 @@
$this->properties[$name] = $value;
break;
+ case 'multipleCredentials':
+ if ( !is_bool( $value ) )
+ {
+ throw new ezcBaseValueException( $name, $value, 'bool' );
+ }
+ $this->properties[$name] = $value;
+ break;
+
default:
parent::__set( $name, $value );
}
Added: trunk/Authentication/tests/filters/group/group_multiple_test.php
==============================================================================
--- trunk/Authentication/tests/filters/group/group_multiple_test.php (added)
+++ trunk/Authentication/tests/filters/group/group_multiple_test.php
[iso-8859-1] Fri Aug 10 13:38:55 2007
@@ -1,0 +1,145 @@
+<?php
+/**
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ * @filesource
+ * @package Authentication
+ * @version //autogen//
+ * @subpackage Tests
+ */
+
+include_once( 'Authentication/tests/test.php' );
+
+/**
+ * @package Authentication
+ * @version //autogen//
+ * @subpackage Tests
+ */
+class ezcAuthenticationGroupMultipleTest extends ezcAuthenticationTest
+{
+ protected static $data1;
+ protected static $data2;
+ protected static $results;
+
+ public static function suite()
+ {
+ self::$data1 = array( // id_credentials, encrypted_token, token_method
+ array( 'qwerty', 'b1b3773a05c0ed0176787a4f1574ff0075f7521e',
'sha1' ),
+ array( 'wrong value', 'b1b3773a05c0ed0176787a4f1574ff0075f7521e',
'sha1' ),
+ );
+
+ self::$data2 = array( // id_credentials, encrypted_token, token_method
+ array( 'asdfgh', 'a152e841783914146e4bcd4f39100686', 'md5' ),
+ array( 'wrong value', 'a152e841783914146e4bcd4f39100686', 'md5' ),
+ );
+
+ self::$results = array( // the first 2 values are keys in $data1 and
$data2
+ // the 3rd value is the mode for the Group
filter
+ // the 4th value is the expected result for
assertEquals()
+ array( 0, 0, ezcAuthenticationGroupFilter::MODE_AND, true ),
+ array( 0, 1, ezcAuthenticationGroupFilter::MODE_AND, false ),
+
+ array( 0, 0, ezcAuthenticationGroupFilter::MODE_OR, true ),
+ array( 0, 1, ezcAuthenticationGroupFilter::MODE_OR, true ),
+
+ array( 1, 0, ezcAuthenticationGroupFilter::MODE_AND, false ),
+ array( 1, 1, ezcAuthenticationGroupFilter::MODE_AND, false ),
+
+ array( 1, 0, ezcAuthenticationGroupFilter::MODE_OR, true ),
+ array( 1, 1, ezcAuthenticationGroupFilter::MODE_OR, false ),
+ );
+
+ return new PHPUnit_Framework_TestSuite( __CLASS__ );
+ }
+
+ public function testGroupMultipleCredentialsAddFilter()
+ {
+ foreach ( self::$results as $result )
+ {
+ $credentials1 = new ezcAuthenticationIdCredentials(
self::$data1[$result[0]][0] );
+ $credentials2 = new ezcAuthenticationIdCredentials(
self::$data2[$result[1]][0] );
+
+ $authentication = new ezcAuthentication( $credentials1 );
+
+ $filter1 = new ezcAuthenticationTokenFilter(
self::$data1[$result[0]][1], self::$data1[$result[0]][2] );
+ $filter2 = new ezcAuthenticationTokenFilter(
self::$data2[$result[1]][1], self::$data2[$result[1]][2] );
+
+ $options = new ezcAuthenticationGroupOptions();
+ $options->multipleCredentials = true;
+ $options->mode = $result[2];
+
+ $group = new ezcAuthenticationGroupFilter( array(), $options );
+ $group->addFilter( $filter1, $credentials1 );
+ $group->addFilter( $filter2, $credentials2 );
+
+ $authentication->addFilter( $group );
+
+ $this->assertEquals( $result[3], $authentication->run(), "Test
failed for ({$result[0]}, {$result[1]}, {$result[2]})." );
+ }
+ }
+
+ public function testGroupMultipleCredentialsConstructor()
+ {
+ foreach ( self::$results as $result )
+ {
+ $credentials1 = new ezcAuthenticationIdCredentials(
self::$data1[$result[0]][0] );
+ $credentials2 = new ezcAuthenticationIdCredentials(
self::$data2[$result[1]][0] );
+
+ $authentication = new ezcAuthentication( $credentials1 );
+
+ $filter1 = new ezcAuthenticationTokenFilter(
self::$data1[$result[0]][1], self::$data1[$result[0]][2] );
+ $filter2 = new ezcAuthenticationTokenFilter(
self::$data2[$result[1]][1], self::$data2[$result[1]][2] );
+
+ $options = new ezcAuthenticationGroupOptions();
+ $options->multipleCredentials = true;
+ $options->mode = $result[2];
+
+ $group = new ezcAuthenticationGroupFilter( array( array( $filter1,
$credentials1 ), array( $filter2, $credentials2 ) ), $options );
+
+ $authentication->addFilter( $group );
+
+ $this->assertEquals( $result[3], $authentication->run(), "Test
failed for ({$result[0]}, {$result[1]}, {$result[2]})." );
+ }
+ }
+
+ 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
testGroupMultipleCredentialsFailConstructorMissingCredentials()
+ {
+ $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;
+
+ try
+ {
+ $group = new ezcAuthenticationGroupFilter( array( $filter1,
$filter2 ), $options );
+ $this->fail( 'Expected exception was not thrown.' );
+ }
+ catch ( ezcAuthenticationException $e )
+ {
+ $this->assertEquals( 'A credentials object must be specified for
each filter when the multipleCredentials option is enabled.', $e->getMessage()
);
+ }
+ }
+}
+?>
Propchange: trunk/Authentication/tests/filters/group/group_multiple_test.php
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/Authentication/tests/filters/group/group_test.php
==============================================================================
--- trunk/Authentication/tests/filters/group/group_test.php [iso-8859-1]
(original)
+++ trunk/Authentication/tests/filters/group/group_test.php [iso-8859-1] Fri
Aug 10 13:38:55 2007
@@ -306,6 +306,25 @@
$this->assertEquals( false, $authentication->run() );
}
+ public function testGroupConstructorArrayArrayFilters()
+ {
+ $optionsGroup = new ezcAuthenticationGroupOptions();
+ $optionsGroup->mode = ezcAuthenticationGroupFilter::MODE_AND;
+ $credentials = new ezcAuthenticationPasswordCredentials( 'john.doe',
'foobar' );
+ $authentication = new ezcAuthentication( $credentials );
+ $options = new ezcAuthenticationHtpasswdOptions();
+ $options->plain = true;
+ $authentication->addFilter(
+ new ezcAuthenticationGroupFilter(
+ array(
+ array( new ezcAuthenticationHtpasswdFilter( self::$empty,
$options ) ),
+ array( new ezcAuthenticationHtpasswdFilter( self::$empty,
$options ) )
+ ), $optionsGroup
+ )
+ );
+ $this->assertEquals( false, $authentication->run() );
+ }
+
public function testGroupOptions()
{
$options = new ezcAuthenticationGroupOptions();
@@ -313,6 +332,7 @@
$this->invalidPropertyTest( $options, 'mode', 'wrong value', '1, 2' );
$this->invalidPropertyTest( $options, 'mode', '1', '1, 2' );
$this->invalidPropertyTest( $options, 'mode', 1000, '1, 2' );
+ $this->invalidPropertyTest( $options, 'multipleCredentials', 'wrong
value', 'bool' );
$this->missingPropertyTest( $options, 'no_such_option' );
}
Modified: trunk/Authentication/tests/suite.php
==============================================================================
--- trunk/Authentication/tests/suite.php [iso-8859-1] (original)
+++ trunk/Authentication/tests/suite.php [iso-8859-1] Fri Aug 10 13:38:55 2007
@@ -16,6 +16,7 @@
require_once( "general/authentication_test.php" );
require_once( "session/session_test.php" );
require_once( "filters/group/group_test.php" );
+require_once( "filters/group/group_multiple_test.php" );
require_once( "filters/htpasswd/htpasswd_test.php" );
require_once( "filters/ldap/ldap_test.php" );
require_once( "filters/openid/openid_test.php" );
@@ -40,6 +41,7 @@
$this->addTest( ezcAuthenticationGeneralTest::suite() );
$this->addTest( ezcAuthenticationSessionTest::suite() );
$this->addTest( ezcAuthenticationGroupTest::suite() );
+ $this->addTest( ezcAuthenticationGroupMultipleTest::suite() );
$this->addTest( ezcAuthenticationHtpasswdTest::suite() );
$this->addTest( ezcAuthenticationLdapTest::suite() );
$this->addTest( ezcAuthenticationOpenidTest::suite() );
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components