ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
Auth_Container_DBLite Class Reference
+ Inheritance diagram for Auth_Container_DBLite:
+ Collaboration diagram for Auth_Container_DBLite:

Public Member Functions

 Auth_Container_DBLite ($dsn)
 Constructor of the container class.
 _connect (&$dsn)
 Connect to database by using the given DSN string.
 _prepare ()
 Prepare database connection.
 _parseOptions ($array)
 Parse options passed to the container class.
 _quoteDBFields ()
 Quote the db_fields option to avoid the possibility of SQL injection.
 fetchData ($username, $password)
 Get user information from database.
- Public Member Functions inherited from Auth_Container
 Auth_Container ()
 Constructor.
 fetchData ($username, $password, $isChallengeResponse=false)
 Fetch data from storage container.
 verifyPassword ($password1, $password2, $cryptType="md5")
 Crypt and verfiy the entered password.
 supportsChallengeResponse ()
 Returns true if the container supports Challenge Response password authentication.
 getCryptType ()
 Returns the crypt current crypt type of the container.
 listUsers ()
 List all users that are available from the storage container.
 getUser ($username)
 Returns a user assoc array.
 addUser ($username, $password, $additional=null)
 Add a new user to the storage container.
 removeUser ($username)
 Remove user from the storage container.
 changePassword ($username, $password)
 Change password for user in the storage container.
 log ($message, $level=AUTH_LOG_DEBUG)
 Log a message to the Auth log.
- Public Member Functions inherited from ilAuthContainerBase
 loginObserver ($a_username, $a_auth)
 Called after successful login.
 failedLoginObserver ($a_username, $a_auth)
 Called after failed login.
 checkAuthObserver ($a_username, $a_auth)
 Called after check auth requests.
 logoutObserver ($a_username, $a_auth)
 Called after logout.

Data Fields

 $options = array()
 $db = null
 $dsn = ''
 $activeUser = ''
- Data Fields inherited from Auth_Container
 $activeUser = ""
 User that is currently selected from the storage container.
 $_auth_obj = null
 The Auth object this container is attached to.

Detailed Description

Definition at line 52 of file DBLite.php.

Member Function Documentation

Auth_Container_DBLite::_connect ( $dsn)

Connect to database by using the given DSN string.

private

Parameters
stringDSN string
Returns
mixed Object on error, otherwise bool

Definition at line 119 of file DBLite.php.

References $dsn, AUTH_LOG_DEBUG, elseif(), PEAR\isError(), Auth_Container\log(), and PEAR\raiseError().

Referenced by _prepare().

{
$this->log('Auth_Container_DBLite::_connect() called.', AUTH_LOG_DEBUG);
if (is_string($dsn) || is_array($dsn)) {
$this->db =& DB::connect($dsn, $this->options['db_options']);
} elseif (is_subclass_of($dsn, "db_common")) {
$this->db =& $dsn;
} else {
return PEAR::raiseError("Invalid dsn or db object given");
}
if (DB::isError($this->db) || PEAR::isError($this->db)) {
return PEAR::raiseError($this->db->getMessage(), $this->db->getCode());
} else {
return true;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Auth_Container_DBLite::_parseOptions (   $array)

Parse options passed to the container class.

private

Parameters
array

Definition at line 185 of file DBLite.php.

References $key.

Referenced by Auth_Container_DBLite().

{
foreach ($array as $key => $value) {
if (isset($this->options[$key])) {
$this->options[$key] = $value;
}
}
}

+ Here is the caller graph for this function:

Auth_Container_DBLite::_prepare ( )

Prepare database connection.

This function checks if we have already opened a connection to the database. If that's not the case, a new connection is opened.

private

Returns
mixed True or a DB error object.

Definition at line 149 of file DBLite.php.

References $res, $t, _connect(), and PEAR\isError().

Referenced by fetchData().

{
if (!DB::isConnection($this->db)) {
$res = $this->_connect($this->options['dsn']);
if (DB::isError($res) || PEAR::isError($res)) {
return $res;
}
}
if ($this->options['auto_quote'] && $this->db->dsn['phptype'] != 'sqlite') {
if (strpos('.', $this->options['table']) === false) {
$this->options['final_table'] = $this->db->quoteIdentifier($this->options['table']);
} else {
$t = explode('.', $this->options['table']);
for ($i = 0, $count = count($t); $i < $count; $i++)
$t[$i] = $this->db->quoteIdentifier($t[$i]);
$this->options['final_table'] = implode('.', $t);
}
$this->options['final_usernamecol'] = $this->db->quoteIdentifier($this->options['usernamecol']);
$this->options['final_passwordcol'] = $this->db->quoteIdentifier($this->options['passwordcol']);
} else {
$this->options['final_table'] = $this->options['table'];
$this->options['final_usernamecol'] = $this->options['usernamecol'];
$this->options['final_passwordcol'] = $this->options['passwordcol'];
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Auth_Container_DBLite::_quoteDBFields ( )

Quote the db_fields option to avoid the possibility of SQL injection.

private

Returns
string A properly quoted string that can be concatenated into a SELECT clause.

Definition at line 204 of file DBLite.php.

Referenced by fetchData().

{
if (isset($this->options['db_fields'])) {
if (is_array($this->options['db_fields'])) {
if ($this->options['auto_quote']) {
$fields = array();
foreach ($this->options['db_fields'] as $field) {
$fields[] = $this->db->quoteIdentifier($field);
}
return implode(', ', $fields);
} else {
return implode(', ', $this->options['db_fields']);
}
} else {
if (strlen($this->options['db_fields']) > 0) {
if ($this->options['auto_quote']) {
return $this->db->quoteIdentifier($this->options['db_fields']);
} else {
$this->options['db_fields'];
}
}
}
}
return '';
}

+ Here is the caller graph for this function:

Auth_Container_DBLite::Auth_Container_DBLite (   $dsn)

Constructor of the container class.

Initate connection to the database via PEAR::DB

Parameters
stringConnection data or DB object
Returns
object Returns an error object if something went wrong

Definition at line 87 of file DBLite.php.

References $dsn, _parseOptions(), and PEAR\raiseError().

{
$this->options['table'] = 'auth';
$this->options['usernamecol'] = 'username';
$this->options['passwordcol'] = 'password';
$this->options['dsn'] = '';
$this->options['db_fields'] = '';
$this->options['cryptType'] = 'md5';
$this->options['db_options'] = array();
$this->options['db_where'] = '';
$this->options['auto_quote'] = true;
if (is_array($dsn)) {
if (empty($this->options['dsn'])) {
PEAR::raiseError('No connection parameters specified!');
}
} else {
$this->options['dsn'] = $dsn;
}
}

+ Here is the call graph for this function:

Auth_Container_DBLite::fetchData (   $username,
  $password 
)

Get user information from database.

This function uses the given username to fetch the corresponding login data from the database table. If an account that matches the passed username and password is found, the function returns true. Otherwise it returns false.

Parameters
stringUsername
stringPassword
Returns
mixed Error object or boolean

Definition at line 247 of file DBLite.php.

References $err, $key, $password, $query, $res, _prepare(), _quoteDBFields(), AUTH_LOG_DEBUG, DB_FETCHMODE_ASSOC, Auth_Container\log(), PEAR\raiseError(), Auth\setAuthData(), and Auth_Container\verifyPassword().

{
$this->log('Auth_Container_DBLite::fetchData() called.', AUTH_LOG_DEBUG);
// Prepare for a database query
$err = $this->_prepare();
if ($err !== true) {
return PEAR::raiseError($err->getMessage(), $err->getCode());
}
// Find if db_fields contains a *, if so assume all col are selected
if (is_string($this->options['db_fields'])
&& strstr($this->options['db_fields'], '*')) {
$sql_from = "*";
} else {
$sql_from = $this->options['final_usernamecol'].
", ".$this->options['final_passwordcol'];
if (strlen($fields = $this->_quoteDBFields()) > 0) {
$sql_from .= ', '.$fields;
}
}
$query = "SELECT ".$sql_from.
" FROM ".$this->options['final_table'].
" WHERE ".$this->options['final_usernamecol']." = ".$this->db->quoteSmart($username);
// check if there is an optional parameter db_where
if ($this->options['db_where'] != '') {
// there is one, so add it to the query
$query .= " AND ".$this->options['db_where'];
}
$this->log('Running SQL against DB: '.$query, AUTH_LOG_DEBUG);
$res = $this->db->getRow($query, null, DB_FETCHMODE_ASSOC);
if (DB::isError($res)) {
return PEAR::raiseError($res->getMessage(), $res->getCode());
}
if (!is_array($res)) {
$this->activeUser = '';
return false;
}
if ($this->verifyPassword(trim($password, "\r\n"),
trim($res[$this->options['passwordcol']], "\r\n"),
$this->options['cryptType'])) {
// Store additional field values in the session
foreach ($res as $key => $value) {
if ($key == $this->options['passwordcol'] ||
$key == $this->options['usernamecol']) {
continue;
}
$this->log('Storing additional field: '.$key, AUTH_LOG_DEBUG);
// Use reference to the auth object if exists
// This is because the auth session variable can change so a static call to setAuthData does not make sence
if (is_object($this->_auth_obj)) {
$this->_auth_obj->setAuthData($key, $value);
} else {
}
}
$this->activeUser = $res[$this->options['usernamecol']];
return true;
}
$this->activeUser = $res[$this->options['usernamecol']];
return false;
}

+ Here is the call graph for this function:

Field Documentation

Auth_Container_DBLite::$activeUser = ''

Definition at line 74 of file DBLite.php.

Auth_Container_DBLite::$db = null

Definition at line 67 of file DBLite.php.

Auth_Container_DBLite::$dsn = ''

Definition at line 68 of file DBLite.php.

Referenced by _connect(), and Auth_Container_DBLite().

Auth_Container_DBLite::$options = array()

Definition at line 61 of file DBLite.php.


The documentation for this class was generated from the following file: