Apache Zeta Components Manual :: File Source for openid_db_store.php
Source for file openid_db_store.php
Documentation is available at openid_db_store.php
* File containing the ezcAuthenticationOpenidDbStore 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 AuthenticationDatabaseTiein
* @version //autogentag//
* Class providing database storage for OpenID authentication.
* This class requires that the database used contains two special tables. See
* the tutorial for information on how to create those tables.
* // create an OpenID options object
* $options = new ezcAuthenticationOpenidOptions();
* $options->mode = ezcAuthenticationOpenidFilter::MODE_SMART;
* // define a database store
* $options->store = new ezcAuthenticationOpenidDbStore( ezcDbInstance::get() );
* // create an OpenID filter based on the options object
* $filter = new ezcAuthenticationOpenidFilter( $options );
* @property ezcDbHandler $instance
* The database instance to use for database storage.
* @package AuthenticationDatabaseTiein
* @version //autogentag//
* Holds the properties of this class.
* @var array(string=>mixed)
private $properties =
array();
* Creates a new object of this class.
* @param ezcDbHandler $instance The database instance used for this store
* @param ezcAuthenticationOpenidDbStoreOptions $options Options for this class
public function __construct( ezcDbHandler $instance, ezcAuthenticationOpenidDbStoreOptions $options =
null )
$this->instance =
$instance;
* 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;
* 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] );
* Stores the nonce in the store.
* Returns true if the nonce was stored successfully, and false otherwise.
* @throws ezcBaseFilePermissionException
* if the nonce cannot be written in the store
* @param string $nonce The nonce value to store
$table =
$this->options->tableNonces;
$query->insertInto( $this->instance->quoteIdentifier( $table['name'] ) )
->set( $this->instance->quoteIdentifier( $table['fields']['nonce'] ), $query->bindValue( $nonce ) )
->set( $this->instance->quoteIdentifier( $table['fields']['timestamp'] ), $query->bindValue( time() ) );
$stmt =
$query->prepare();
* Checks if the nonce exists and afterwards deletes it.
* Returns the timestamp of the nonce if it exists, and false otherwise.
* @param string $nonce The nonce value to check and delete
$table =
$this->options->tableNonces;
->from( $this->instance->quoteIdentifier( $table['name'] ) )
$e->eq( $this->instance->quoteIdentifier( $table['fields']['nonce'] ), $query->bindValue( $nonce ) )
$query =
$query->prepare();
$rows =
$query->fetchAll();
if ( count( $rows ) >
0 )
$lastModified = (int)
$rows[$table['fields']['timestamp']];
// $nonce was not found in the database
* Removes the nonce from the nonces table.
$table =
$this->options->tableNonces;
$query->deleteFrom( $this->instance->quoteIdentifier( $table['name'] ) )
$e->eq( $this->instance->quoteIdentifier( $table['fields']['nonce'] ), $query->bindValue( $nonce ) )
$query =
$query->prepare();
* Stores an association in the store linked to the OpenID provider URL.
* @param string $url The URL of the OpenID provider
* @param ezcAuthenticationOpenidAssociation $association The association value to store
$table =
$this->options->tableAssociations;
$query->insertInto( $this->instance->quoteIdentifier( $table['name'] ) )
->set( $this->instance->quoteIdentifier( $table['fields']['url'] ), $query->bindValue( $url ) )
->set( $this->instance->quoteIdentifier( $table['fields']['association'] ), $query->bindValue( $data ) );
$stmt =
$query->prepare();
* Returns the unserialized association linked to the OpenID provider URL.
* Returns false if the association could not be retrieved or if it expired.
* @param string $url The URL of the OpenID provider
* @return ezcAuthenticationOpenidAssociation
$table =
$this->options->tableAssociations;
->from( $this->instance->quoteIdentifier( $table['name'] ) )
$e->eq( $this->instance->quoteIdentifier( $table['fields']['url'] ), $query->bindValue( $url ) )
$query =
$query->prepare();
$rows =
$query->fetchAll();
if ( count( $rows ) >
0 )
$data =
unserialize( $rows[$table['fields']['association']] );
// no association was found for $url
* Removes the association linked to the OpenID provider URL.
* @param string $url The URL of the OpenID provider
$table =
$this->options->tableAssociations;
$query->deleteFrom( $this->instance->quoteIdentifier( $table['name'] ) )
$e->eq( $this->instance->quoteIdentifier( $table['fields']['url'] ), $query->bindValue( $url ) )
$query =
$query->prepare();