Zeta Components - high quality PHP components

Zeta Components Manual :: Docs For Class ezcAuthentication

Authentication::ezcAuthentication

Class ezcAuthentication

Container for authentication filters.

This is the main class of the authentication component. Filters are added to an object of this class, which will run the filters in sequence. At the end of this process, the status property will contain the statuses of the filters, and the developer can use those statuses to display to the user messages such as "Password incorrect".

The session property is optional and it is used to store the authentication information between requests.

The credentials property will be passed to all the filters in the queue.

Example (using the Htpasswd filter):

  1.  $credentials = new ezcAuthenticationPasswordCredentials( 'jan.modaal', 'b1b3773a05c0ed0176787a4f1574ff0075f7521e' );
  2.  $authentication = new ezcAuthentication( $credentials );
  3.  $authentication->session = new ezcAuthenticationSession();
  4.  $authentication->addFilter( new ezcAuthenticationHtpasswdFilter( '/etc/htpasswd' ) );
  5.  // add other filters if needed
  6.  if ( !$authentication->run() )
  7.  {
  8.      // authentication did not succeed, so inform the user
  9.      $status = $authentication->getStatus();
  10.      $err = array(
  11.              'ezcAuthenticationHtpasswdFilter' => array(
  12.                  ezcAuthenticationHtpasswdFilter::STATUS_USERNAME_INCORRECT => 'Incorrect username',
  13.                  ezcAuthenticationHtpasswdFilter::STATUS_PASSWORD_INCORRECT => 'Incorrect password'
  14.                  )
  15.              );
  16.      foreach ( $status as $line )
  17.      {
  18.          list( $key, $value ) = each( $line );
  19.          echo $err[$key][$value] . "\n";
  20.      }
  21.  }
  22.  else
  23.  {
  24.      // authentication succeeded, so allow the user to see his content
  25.  }

Source for this file: /Authentication/src/authentication.php

Version:   //autogen//

Properties

ezcAuthenticationCredentials read/write $credentials
The user credentials to pass to the authentication filters.
ezcAuthenticationSession read/write $session
The session object to use during authentication to store the authentication information between requests.
ezcAuthenticationStatus read/write $status
The status object which holds the status of the run filters.

Member Variables

protected array(ezcAuthenticationFilter) $filters = array()
The filter queue of the authentication process.
protected ezcAuthenticationOptions $options
Options for the Authentication object.

Method Summary

public ezcAuthentication __construct( $credentials , [ $options = null] )
Creates a new object of this class.
public void addFilter( $filter , [ $stop = false] )
Adds an authentication filter at the end of the filter list.
public ezcAuthenticationOptions getOptions( )
Returns the options of this class.
public array(string=>mixed) getStatus( )
Returns the status of authentication.
public bool run( )
Runs through all the filters in the filter list.
public void setOptions( $options )
Sets the options of this class to $options.

Methods

__construct

ezcAuthentication __construct( ezcAuthenticationCredentials $credentials , [ezcAuthenticationOptions $options = null] )

Creates a new object of this class.

Parameters:
Name Type Description
$credentials ezcAuthenticationCredentials Authentication credentials
$options ezcAuthenticationOptions Options for this class

addFilter

void addFilter( ezcAuthenticationFilter $filter , [bool $stop = false] )

Adds an authentication filter at the end of the filter list.

By specifying the second parameter as true, the authentication process (triggered by calling the run() method) will stop after processing this filter regardless of its success.

Parameters:
Name Type Description
$filter ezcAuthenticationFilter The authentication filter to add
$stop bool If authentication should continue past this filter

getOptions

ezcAuthenticationOptions getOptions( )

Returns the options of this class.

getStatus

array(string=>mixed) getStatus( )

Returns the status of authentication.

The format of the returned array is array( array( class => code ) ).

Example:

  1.  array(
  2.         array( 'ezcAuthenticationSession' => ezcAuthenticationSession::STATUS_EMPTY ),
  3.         array( 'ezcAuthenticationDatabaseFilter' => ezcAuthenticationDatabaseFilter::STATUS_PASSWORD_INCORRECT )
  4.       );

run

bool run( )

Runs through all the filters in the filter list.

setOptions

void setOptions( ezcAuthenticationOptions $options )

Sets the options of this class to $options.

Parameters:
Name Type Description
$options ezcAuthenticationOptions Options for this class
Documentation generated by phpDocumentor 1.4.3