00001 <?php
00002
00016
00017
00018
00019 import('security.AuthSource');
00020
00021 class AuthSourceDAO extends DAO {
00022 var $plugins;
00023
00027 function AuthSourceDAO() {
00028 parent::DAO();
00029 $this->plugins = &PluginRegistry::loadCategory(AUTH_PLUGIN_CATEGORY);
00030 }
00031
00037 function &getPlugin($authId) {
00038 $plugin = null;
00039 $auth = &$this->getSource($authId);
00040 if ($auth != null) {
00041 $plugin =& $auth->getPluginClass();
00042 if ($plugin != null) {
00043 $plugin = &$plugin->getInstance($auth->getSettings(), $auth->getAuthId());
00044 }
00045 }
00046 return $plugin;
00047 }
00048
00053 function &getDefaultPlugin() {
00054 $plugin = null;
00055 $auth = &$this->getDefaultSource();
00056 if ($auth != null) {
00057 $plugin =& $auth->getPluginClass();
00058 if ($plugin != null) {
00059 $plugin = &$plugin->getInstance($auth->getSettings(), $auth->getAuthId());
00060 }
00061 }
00062 return $plugin;
00063 }
00064
00070 function &getSource($authId) {
00071 $result = &$this->retrieve(
00072 'SELECT * FROM auth_sources WHERE auth_id = ?', $authId
00073 );
00074
00075 $returner = null;
00076 if ($result->RecordCount() != 0) {
00077 $returner = &$this->_returnAuthSourceFromRow($result->GetRowAssoc(false));
00078 }
00079
00080 $result->Close();
00081 unset($result);
00082
00083 return $returner;
00084 }
00085
00090 function &getDefaultSource() {
00091 $result = &$this->retrieve(
00092 'SELECT * FROM auth_sources WHERE auth_default = 1'
00093 );
00094
00095 $returner = null;
00096 if ($result->RecordCount() != 0) {
00097 $returner = &$this->_returnAuthSourceFromRow($result->GetRowAssoc(false));
00098 }
00099
00100 $result->Close();
00101 unset($result);
00102
00103 return $returner;
00104 }
00105
00111 function &_returnAuthSourceFromRow(&$row) {
00112 $auth = &new AuthSource();
00113 $auth->setAuthId($row['auth_id']);
00114 $auth->setTitle($row['title']);
00115 $auth->setPlugin($row['plugin']);
00116 $auth->setPluginClass(@$this->plugins[$row['plugin']]);
00117 $auth->setDefault($row['auth_default']);
00118 $auth->setSettings(unserialize($row['settings']));
00119 return $auth;
00120 }
00121
00126 function insertSource(&$auth) {
00127 if (!isset($this->plugins[$auth->getPlugin()])) return false;
00128 if (!$auth->getTitle()) $auth->setTitle($this->plugins[$auth->getPlugin()]->getDisplayName());
00129 $this->update(
00130 'INSERT INTO auth_sources
00131 (title, plugin, settings)
00132 VALUES
00133 (?, ?, ?)',
00134 array(
00135 $auth->getTitle(),
00136 $auth->getPlugin(),
00137 serialize($auth->getSettings() ? $auth->getSettings() : array())
00138 )
00139 );
00140
00141 $auth->setAuthId($this->getInsertId('auth_sources', 'auth_id'));
00142 return $auth->getAuthId();
00143 }
00144
00149 function updateSource(&$auth) {
00150 return $this->update(
00151 'UPDATE auth_sources SET
00152 title = ?,
00153 settings = ?
00154 WHERE auth_id = ?',
00155 array(
00156 $auth->getTitle(),
00157 serialize($auth->getSettings() ? $auth->getSettings() : array()),
00158 $auth->getAuthId()
00159 )
00160 );
00161 }
00162
00167 function deleteSource($authId) {
00168 return $this->update(
00169 'DELETE FROM auth_sources WHERE auth_id = ?', $authId
00170 );
00171 }
00172
00177 function setDefault($authId) {
00178 $this->update(
00179 'UPDATE auth_sources SET auth_default = 0'
00180 );
00181 $this->update(
00182 'UPDATE auth_sources SET auth_default = 1 WHERE auth_id = ?', $authId
00183 );
00184 }
00185
00190 function &getSources($rangeInfo = null) {
00191 $result = &$this->retrieveRange(
00192 'SELECT * FROM auth_sources ORDER BY auth_id',
00193 false, $rangeInfo
00194 );
00195
00196 $returner = &new DAOResultFactory($result, $this, '_returnAuthSourceFromRow');
00197 return $returner;
00198 }
00199 }
00200
00201 ?>