Zeta Components Manual :: Docs For Class ezcAuthenticationGroupFilter
Authentication::ezcAuthenticationGroupFilter
Class ezcAuthenticationGroupFilter
Group authentication filters together.
If there are no filters in the group, then the run() method will return STATUS_OK.
The way of grouping the filters is specified with the mode option:
- ezcAuthenticationGroupFilter::MODE_OR (default): at least one filter in the group needs to succeed in order for the group to succeed.
- ezcAuthenticationGroupFilter::MODE_AND: all filters in the group need to succeed in order for the group to succeed.
- // $filter1 and $filter2 are authentication filters which all need to succeed
- // in order for the group to succeed
Example of using the group filter with LDAP and Database filters:
- // create a database filter
- $database = new ezcAuthenticationDatabaseInfo( ezcDbInstance::get(), 'users', array( 'user', 'password' ) );
- // create an LDAP filter
- // use the database and LDAP filters in paralel (at least one needs to succeed in
- // order for the user to be authenticated)
- $authentication->addFilter( new ezcAuthenticationGroupFilter( array( $databaseFilter, $ldapFilter ) ) );
- // add more filters if needed
- {
- // authentication did not succeed, so inform the user
- $status = $authentication->getStatus();
- $err = array(
- array( 'ezcAuthenticationLdapFilter' => array(
- ) ),
- array( 'ezcAuthenticationDatabaseFilter' => array(
- ) )
- );
- foreach ( $status as $line => $error )
- {
- echo $err[$line][$key][$value] . "\n";
- }
- }
- else
- {
- // authentication succeeded, so allow the user to see his content
- }
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:
- $credentials1 = new ezcAuthenticationPasswordCredentials( 'jan.modaal', 'b1b3773a05c0ed0176787a4f1574ff0075f7521e' ); // incorrect password
- $credentials2 = new ezcAuthenticationPasswordCredentials( 'john.doe', 'wpeE20wyWHnLE' ); // correct username + password
- $options->multipleCredentials = true;
- $group->addFilter( new ezcAuthenticationHtpasswdFilter( '../../tests/filters/htpasswd/data/htpasswd' ), $credentials1 );
- $group->addFilter( new ezcAuthenticationHtpasswdFilter( '../../tests/filters/htpasswd/data/htpasswd' ), $credentials2 );
- // add more filters if needed
- {
- // authentication did not succeed, so inform the user
- $status = $authentication->getStatus();
- $err = array(
- array( 'ezcAuthenticationHtpasswdFilter' => array(
- ezcAuthenticationHtpasswdFilter::STATUS_USERNAME_INCORRECT => 'Incorrect username ' . $credentials1->id,
- ezcAuthenticationHtpasswdFilter::STATUS_PASSWORD_INCORRECT => 'Incorrect password for ' . $credentials1->id
- ) ),
- array( 'ezcAuthenticationHtpasswdFilter' => array(
- ezcAuthenticationHtpasswdFilter::STATUS_USERNAME_INCORRECT => 'Incorrect username ' . $credentials2->id,
- ezcAuthenticationHtpasswdFilter::STATUS_PASSWORD_INCORRECT => 'Incorrect password for ' . $credentials2->id
- ) )
- );
- foreach ( $status as $line => $error )
- {
- echo $err[$line][$key][$value] . "\n";
- }
- }
- else
- {
- // authentication succeeded, so allow the user to see his content
- }
Source for this file: /Authentication/src/filters/group/group_filter.php
ezcAuthenticationFilter | --ezcAuthenticationGroupFilter
Version: | //autogen// |
Constants
MODE_AND
= 2
|
All the filters need to succeed in order for the group to succeed. |
MODE_OR
= 1
|
At least one filter needs to succeed in order for the group to succeed. |
STATUS_GROUP_FAILED
= 1
|
All or some of the filters in the group failed (depeding on the mode option). |
Inherited Constants
From ezcAuthenticationFilter: | |
---|---|
ezcAuthenticationFilter::STATUS_OK
|
Successful authentication. |
Properties
ezcAuthenticationStatus | read/write |
$status
The status object which holds the status of the run filters. |
Member Variables
protected array(ezcAuthenticationFilter) |
$filters
= array()
Authentication filters. |
Inherited Member Variables
From ezcAuthenticationFilter | |
---|---|
protected |
ezcAuthenticationFilter::$options
|
Method Summary
public ezcAuthenticationGroupFilter |
__construct(
$filters
, [ $options
= null] )
Creates a new object of this class. |
public void |
addFilter(
$filter
, [ $credentials
= null] )
Adds an authentication filter at the end of the filter list. |
public int |
run(
$credentials
)
Runs the filter and returns a status code when finished. |
Inherited Methods
From ezcAuthenticationFilter | |
---|---|
public ezcAuthenticationFilterOptions |
ezcAuthenticationFilter::getOptions()
Returns the options of this class. |
public abstract int |
ezcAuthenticationFilter::run()
Runs the filter and returns a status code when finished. |
public void |
ezcAuthenticationFilter::setOptions()
Sets the options of this class to $options. |
Methods
__construct
Creates a new object of this class.
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:
- // enable multiple credentials
- $options->multipleCredentials = true;
- // add the filters to the group with the constructor
- array( $filter1, $credentials1 ),
- array( $filter2, $credentials2 ) ), $options );
- // the filters can also be added to the group with addFilter()
Parameters:
Name | Type | Description |
---|---|---|
$filters |
array(ezcAuthenticationFilter|mixed) | Authentication filters |
$options |
ezcAuthenticationGroupOptions | Options for this class |
Exceptions:
Type | Description |
---|---|
ezcAuthenticationException |
if the multipleCredentials option is enabled and a credentials object was not specified |
addFilter
Adds an authentication filter at the end of the filter list.
Example of using multipleCredentials:
- // enable multiple credentials
- $options->multipleCredentials = true;
- // add the filters to the group with addFilter()
- // the filters can also be added to the group with the constructor
Parameters:
Name | Type | Description |
---|---|---|
$filter |
ezcAuthenticationFilter | The authentication filter to add |
$credentials |
ezcAuthenticationCredentials | Credentials object associated with $filter if the multipleCredentials option is enabled |
Exceptions:
Type | Description |
---|---|
ezcAuthenticationGroupException |
if the multipleCredentials option is enabled and a credentials object was not specified |
run
Runs the filter and returns a status code when finished.
Parameters:
Name | Type | Description |
---|---|---|
$credentials |
ezcAuthenticationCredentials | Authentication credentials |
Redefinition of:
Method | Description |
---|---|
ezcAuthenticationFilter::run() |
Runs the filter and returns a status code when finished. |