Apache Zeta Components Manual :: File Source for authentication.php
Source for file authentication.php
Documentation is available at authentication.php
* File containing the ezcAuthentication class.
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @package Authentication
* 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
* 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):
* $credentials = new ezcAuthenticationPasswordCredentials( 'jan.modaal', 'b1b3773a05c0ed0176787a4f1574ff0075f7521e' );
* $authentication = new ezcAuthentication( $credentials );
* $authentication->session = new ezcAuthenticationSession();
* $authentication->addFilter( new ezcAuthenticationHtpasswdFilter( '/etc/htpasswd' ) );
* // add other filters if needed
* if ( !$authentication->run() )
* // authentication did not succeed, so inform the user
* $status = $authentication->getStatus();
* 'ezcAuthenticationHtpasswdFilter' => array(
* ezcAuthenticationHtpasswdFilter::STATUS_USERNAME_INCORRECT => 'Incorrect username',
* ezcAuthenticationHtpasswdFilter::STATUS_PASSWORD_INCORRECT => 'Incorrect password'
* foreach ( $status as $line )
* list( $key, $value ) = each( $line );
* echo $err[$key][$value] . "\n";
* // authentication succeeded, so allow the user to see his content
* @property ezcAuthenticationSession $session
* The session object to use during authentication to store the
* authentication information between requests.
* @property ezcAuthenticationStatus $status
* The status object which holds the status of the run filters.
* @property ezcAuthenticationCredentials $credentials
* The user credentials to pass to the authentication filters.
* @package Authentication
* The filter queue of the authentication process.
* @var array(ezcAuthenticationFilter)
* Options for the Authentication object.
* @var ezcAuthenticationOptions
* The properties of this class.
* @var array(string=>mixed)
private $properties =
array();
* Creates a new object of this class.
* @param ezcAuthenticationCredentials $credentials Authentication credentials
* @param ezcAuthenticationOptions $options Options for this class
public function __construct( ezcAuthenticationCredentials $credentials, ezcAuthenticationOptions $options =
null )
$this->credentials =
$credentials;
* Sets the property $name to $value.
* @throws ezcBasePropertyNotFoundException
* if the property $name does not exist
* @throws ezcBaseValueException
* if $value is not correct for the property $name
* @param string $name The name of the property to set
* @param mixed $value The new value of the property
public function __set( $name, $value )
$this->properties[$name] =
$value;
$this->properties[$name] =
$value;
$this->properties[$name] =
$value;
* Returns the value of the property $name.
* @throws ezcBasePropertyNotFoundException
* if the property $name does not exist
* @param string $name The name of the property for which to return the value
public function __get( $name )
return $this->properties[$name];
* Returns true if the property $name is set, otherwise false.
* @param string $name The name of the property to test if it is set
public function __isset( $name )
return isset
( $this->properties[$name] );
* Sets the options of this class to $options.
* @param ezcAuthenticationOptions $options Options for this class
public function setOptions( ezcAuthenticationOptions $options )
* Returns the options of this class.
* @return ezcAuthenticationOptions
* Runs through all the filters in the filter list.
$credentials =
$this->credentials;
if ( isset
( $this->session ) )
$code =
$this->session->run( $credentials );
$this->status->append( get_class( $this->session ), $code );
foreach ( $this->filters as $filter )
$code =
$filter[0]->run( $credentials );
$statuses =
$filter[0]->status->get();
// 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 );
$this->status->append( get_class( $filter[0] ), $code );
if ( isset
( $this->session ) )
$this->session->save( $credentials->__toString() );
* 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.
* @param ezcAuthenticationFilter $filter The authentication filter to add
* @param bool $stop If authentication should continue past this filter
public function addFilter( ezcAuthenticationFilter $filter, $stop =
false )
$this->filters[] =
array( $filter, $stop );
* Returns the status of authentication.
* The format of the returned array is array( array( class => code ) ).
* array( 'ezcAuthenticationSession' => ezcAuthenticationSession::STATUS_EMPTY ),
* array( 'ezcAuthenticationDatabaseFilter' => ezcAuthenticationDatabaseFilter::STATUS_PASSWORD_INCORRECT )
* @return array(string=>mixed)
return $this->status->get();