Authentication: ezcAuthenticationGroupFilter
[ ]
[ Security ]
[ ]
[ ]
[ ]
[ ]
Class: ezcAuthenticationGroupFilter
|
Group authentication filters together. [
source]
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.
Example of using the mode option:
1. $options = new ezcAuthenticationGroupOptions();
2. $options->mode = ezcAuthenticationGroupFilter::MODE_AND;
3.
4. // $filter1 and $filter2 are authentication filters which all need to succeed
5. // in order for the group to succeed
6. $filter = new ezcAuthenticationGroupFilter( array( $filter1, $filter2 ), $options );
Example of using the group filter with LDAP and Database filters:
1. $credentials = new ezcAuthenticationPasswordCredentials( 'jan.modaal', 'qwerty' );
2.
3. // create a database filter
4. $database = new ezcAuthenticationDatabaseInfo( ezcDbInstance::get(), 'users', array( 'user', 'password' ) );
5. $databaseFilter = new ezcAuthenticationDatabaseFilter( $database );
6.
7. // create an LDAP filter
8. $ldap = new ezcAuthenticationLdapInfo( 'localhost', 'uid=%id%', 'dc=example,dc=com', 389 );
9. $ldapFilter = new ezcAuthenticationLdapFilter( $ldap );
10. $authentication = new ezcAuthentication( $credentials );
11.
12. // use the database and LDAP filters in paralel (at least one needs to succeed in
13. // order for the user to be authenticated)
14. $authentication->addFilter( new ezcAuthenticationGroupFilter( array( $databaseFilter, $ldapFilter ) ) );
15. // add more filters if needed
16. if ( !$authentication->run() )
17. {
18. // authentication did not succeed, so inform the user
19. $status = $authentication->getStatus();
20. $err = array(
21. 'ezcAuthenticationLdapFilter' => array(
22. ezcAuthenticationLdapFilter::STATUS_USERNAME_INCORRECT => 'Incorrect username',
23. ezcAuthenticationLdapFilter::STATUS_PASSWORD_INCORRECT => 'Incorrect password'
24. ),
25. 'ezcAuthenticationDatabaseFilter' => array(
26. ezcAuthenticationDatabaseFilter::STATUS_USERNAME_INCORRECT => 'Incorrect username',
27. ezcAuthenticationDatabaseFilter::STATUS_PASSWORD_INCORRECT => 'Incorrect password'
28. )
29. );
30. foreach ( $status as $line )
31. {
32. list( $key, $value ) = each( $line );
33. echo $err[$key][$value] . "\n";
34. }
35. }
36. else
37. {
38. // authentication succeeded, so allow the user to see his content
39. }
Parents
ezcAuthenticationFilter
|
--ezcAuthenticationGroupFilter
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:
Properties
Member Variables
|
protected array(ezcAuthenticationFilter) |
$filters
= array()
Authentication filters. |
Inherited Member Variables
From
ezcAuthenticationFilter:
Method Summary
|
public ezcAuthenticationGroupFilter |
__construct(
$filters, [$options = null] )
Creates a new object of this class. |
|
public void |
addFilter(
$filter )
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 :
Methods
__construct
Creates a new object of this class.
Parameters
| Name |
Type |
Description |
$filters |
array(ezcAuthenticationFilter) |
Authentication filters |
$options |
ezcAuthenticationGroupOptions |
Options for this class |
addFilter
Adds an authentication filter at the end of the filter list.
Parameters
run
Runs the filter and returns a status code when finished.
Parameters
Redefinition of
Last updated: Thu, 01 Nov 2007