* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 * @link https://wiki.jasig.org/display/CASC/phpCAS * * @ingroup internalPGTStorageDb */ class CAS_PGTStorage_Db extends CAS_PGTStorage_AbstractStorage { /** the PDO object to use for database interactions */ private $_pdo; /** database connection options to use when creating a new PDO object */ private $_dsn; private $_username; private $_password; private $_driver_options; /** @var string the table to use for storing/retrieving pgt's */ private $_table; /** * attribute that stores the previous error mode for the PDO handle while * processing a transaction */ private $_errMode; /** * This method returns the PDO object to use for database interactions. * * @return PDO object */ private function _getPdo() { return $this->_pdo; } /** * This method returns the table to use when storing/retrieving PGT's * * @return string the name of the pgt storage table. */ private function _getTable() { return $this->_table; } /** * This method returns an informational string giving the type of storage * used by the object (used for debugging purposes). * * @return string an informational string. */ public function getStorageType() { return "db"; } /** * This method returns an informational string giving informations on the * parameters of the storage.(used for debugging purposes). * * @return string an informational string. * @public */ public function getStorageInfo() { return 'table=`'.$this->_getTable().'\''; } /** * The class constructor. * * @param CAS_Client $cas_parent the CAS_Client instance that creates * the object. * @param string $dsn_or_pdo a dsn string to use for creating a PDO * object or a PDO object * @param string $username the username to use when connecting to * the database * @param string $password the password to use when connecting to * the database * @param string $table the table to use for storing and * retrieving PGT's * @param string $driver_options any driver options to use when * connecting to the database */ public function __construct( $cas_parent, $dsn_or_pdo, $username = '', $password = '', $table = '', $driver_options = null, ) { phpCAS::traceBegin(); // call the ancestor's constructor parent::__construct($cas_parent); // set default values if ( empty($table) ) { $table = CAS_PGT_STORAGE_DB_DEFAULT_TABLE; } if ( !is_array($driver_options) ) { $driver_options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION); } // store the specified parameters if ($dsn_or_pdo instanceof PDO) { $this->_pdo = $dsn_or_pdo; } else { $this->_dsn = $dsn_or_pdo; $this->_username = $username; $this->_password = $password; $this->_driver_options = $driver_options; } // store the table name $this->_table = $table; phpCAS::traceEnd(); } /** * This method is used to initialize the storage. Halts on error. * * @return void */ public function init() { phpCAS::traceBegin(); // if the storage has already been initialized, return immediatly if ($this->isInitialized()) { return; } // initialize the base object parent::init(); // create the PDO object if it doesn't exist already if (!($this->_pdo instanceof PDO)) { try { $this->_pdo = new PDO( $this->_dsn, $this->_username, $this->_password, $this->_driver_options ); } catch(PDOException $e) { phpCAS::error('Database connection error: ' . $e->getMessage()); } } phpCAS::traceEnd(); } /** * This method will enable the Exception error mode on the PDO object * * @return void */ private function _setErrorMode() { $pdo = $this->_getPdo(); $this->_errMode = $pdo->getAttribute(PDO::ATTR_ERRMODE); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } /** * this method will reset the error mode on the PDO object * * @return void */ private function _resetErrorMode() { $pdo = $this->_getPdo(); $pdo->setAttribute(PDO::ATTR_ERRMODE, $this->_errMode); } /** * This method returns the query used to create a pgt storage table * * @return string the create table SQL, no bind params in query */ protected function createTableSql() { return 'CREATE TABLE ' . $this->_getTable() . ' (pgt_iou VARCHAR(255) NOT NULL PRIMARY KEY, pgt VARCHAR(255) NOT NULL)'; } /** * This method returns the query used to store a pgt * * @return string the store PGT SQL, :pgt and :pgt_iou are the bind params contained * in the query */ protected function storePgtSql() { return 'INSERT INTO ' . $this->_getTable() . ' (pgt_iou, pgt) VALUES (:pgt_iou, :pgt)'; } /** * This method returns the query used to retrieve a pgt. the first column * of the first row should contain the pgt * * @return string the retrieve PGT SQL, :pgt_iou is the only bind param contained * in the query */ protected function retrievePgtSql() { return 'SELECT pgt FROM ' . $this->_getTable() . ' WHERE pgt_iou = :pgt_iou'; } /** * This method returns the query used to delete a pgt. * * @return string the delete PGT SQL, :pgt_iou is the only bind param contained in * the query */ protected function deletePgtSql() { return 'DELETE FROM ' . $this->_getTable() . ' WHERE pgt_iou = :pgt_iou'; } /** * This method creates the database table used to store pgt's and pgtiou's * * @return void */ public function createTable() { phpCAS::traceBegin(); // initialize this PGTStorage object if it hasn't been initialized yet if ( !$this->isInitialized() ) { $this->init(); } // initialize the PDO object for this method $pdo = $this->_getPdo(); $this->_setErrorMode(); try { $pdo->beginTransaction(); $query = $pdo->query($this->createTableSql()); $query->closeCursor(); $pdo->commit(); } catch(PDOException $e) { // attempt rolling back the transaction before throwing a phpCAS error try { $pdo->rollBack(); } catch(PDOException $e) { } phpCAS::error('error creating PGT storage table: ' . $e->getMessage()); } // reset the PDO object $this->_resetErrorMode(); phpCAS::traceEnd(); } /** * This method stores a PGT and its corresponding PGT Iou in the database. * Echoes a warning on error. * * @param string $pgt the PGT * @param string $pgt_iou the PGT iou * * @return void */ public function write($pgt, $pgt_iou) { phpCAS::traceBegin(); // initialize the PDO object for this method $pdo = $this->_getPdo(); $this->_setErrorMode(); try { $pdo->beginTransaction(); $query = $pdo->prepare($this->storePgtSql()); $query->bindValue(':pgt', $pgt, PDO::PARAM_STR); $query->bindValue(':pgt_iou', $pgt_iou, PDO::PARAM_STR); $query->execute(); $query->closeCursor(); $pdo->commit(); } catch(PDOException $e) { // attempt rolling back the transaction before throwing a phpCAS error try { $pdo->rollBack(); } catch(PDOException $e) { } phpCAS::error('error writing PGT to database: ' . $e->getMessage()); } // reset the PDO object $this->_resetErrorMode(); phpCAS::traceEnd(); } /** * This method reads a PGT corresponding to a PGT Iou and deletes the * corresponding db entry. * * @param string $pgt_iou the PGT iou * * @return string|false the corresponding PGT, or FALSE on error */ public function read($pgt_iou) { phpCAS::traceBegin(); $pgt = false; // initialize the PDO object for this method $pdo = $this->_getPdo(); $this->_setErrorMode(); try { $pdo->beginTransaction(); // fetch the pgt for the specified pgt_iou $query = $pdo->prepare($this->retrievePgtSql()); $query->bindValue(':pgt_iou', $pgt_iou, PDO::PARAM_STR); $query->execute(); $pgt = $query->fetchColumn(0); $query->closeCursor(); // delete the specified pgt_iou from the database $query = $pdo->prepare($this->deletePgtSql()); $query->bindValue(':pgt_iou', $pgt_iou, PDO::PARAM_STR); $query->execute(); $query->closeCursor(); $pdo->commit(); } catch(PDOException $e) { // attempt rolling back the transaction before throwing a phpCAS error try { $pdo->rollBack(); } catch(PDOException $e) { } phpCAS::trace('error reading PGT from database: ' . $e->getMessage()); } // reset the PDO object $this->_resetErrorMode(); phpCAS::traceEnd(); return $pgt; } } __halt_compiler();----SIGNATURE:----1jrrT5qu+zXyrkXz/PypkL0ZbzLTYyloKwtyXRyqalqBSFsjnc8k1kjBuU4z8PX35vm2XbXmECJKvBHHaLY8tcEBqnf4tWpnovQ2oHjrGwsY5WMP1w1eyFu7y5aTbpLWSxM2QAkl5tnucYn8x+2KqyPOM+gfE4Dw9PVG77fquLfX0ETOSqyLSULXViZm6ftWamNZAdT2BTr7jJDXer59aFvhKr9cy2xqa8SKBJFczLpOUeL/pU+rh7bvo3wu5qMROh8UG1zTWwVFn748A4Xw01o7OeCYXM/ueh3OdLz/nqKaqfyHpftB3Y54nQl0aNYoYpqs+zwIW4gR1rS+4fntf4AlLQuJURVkaaJlnZfuZHx1SbdK1YSxms+ZfxELJCycwxghGgudrUavEHIexl32w8XXR0sNv1SfiB9BNDwNxihRHBE4S9jouftoTA2iwY9sxuOqC8a45AEx0Q5gPr+lJRFL8T8qiIM+pOEZg887I2LflbYiQme/EcoplVqYk3yNmOQMJ9D71JwEZNMDL3vv6Dthk0DGV3jFITVcu/x+sQ307+JtA0lLfL5+gfndKXBQKwRmmg18UyUfM+Z5YnbbHjHjAaC9jYryuQWJ6YQ91SSAQPpRCGaasbpNVYU5k+5rFrQ+iOQRdxKnNO91U6M2P/kAvPrNSR4jTYRnGYKCDac=----ATTACHMENT:----MzE4ODQ4NDYzNzAxMjQxMSAzMzg3MTI3NzYzOTAyNTAzIDQ0ODA3NTk2NTE5NTU4OTE=