userrights.class.inc.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * User rights management API
  18. *
  19. * @author Erwan Taloc <erwan.taloc@combodo.com>
  20. * @author Romain Quetiez <romain.quetiez@combodo.com>
  21. * @author Denis Flaven <denis.flaven@combodo.com>
  22. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  23. */
  24. class UserRightException extends CoreException
  25. {
  26. }
  27. define('UR_ALLOWED_NO', 0);
  28. define('UR_ALLOWED_YES', 1);
  29. define('UR_ALLOWED_DEPENDS', 2);
  30. define('UR_ACTION_READ', 1); // View an object
  31. define('UR_ACTION_MODIFY', 2); // Create/modify an object/attribute
  32. define('UR_ACTION_DELETE', 3); // Delete an object
  33. define('UR_ACTION_BULK_READ', 4); // Export multiple objects
  34. define('UR_ACTION_BULK_MODIFY', 5); // Create/modify multiple objects
  35. define('UR_ACTION_BULK_DELETE', 6); // Delete multiple objects
  36. define('UR_ACTION_APPLICATION_DEFINED', 10000); // Application specific actions (CSV import, View schema...)
  37. /**
  38. * User management module API
  39. *
  40. * @package iTopORM
  41. */
  42. abstract class UserRightsAddOnAPI
  43. {
  44. abstract public function Setup(); // initial installation
  45. abstract public function CreateAdministrator($sAdminUser, $sAdminPwd, $sLanguage = 'EN US'); // could be used during initial installation
  46. abstract public function Init(); // loads data (possible optimizations)
  47. // Cf UserContext...
  48. abstract public function GetFilter($sLogin, $sClass); // returns a filter object
  49. // Used to build select queries showing only objects visible for the given user
  50. abstract public function GetSelectFilter($sLogin, $sClass); // returns a filter object
  51. abstract public function IsActionAllowed($oUser, $sClass, $iActionCode, /*dbObjectSet*/ $oInstanceSet = null);
  52. abstract public function IsStimulusAllowed($oUser, $sClass, $sStimulusCode, /*dbObjectSet*/ $oInstanceSet = null);
  53. abstract public function IsActionAllowedOnAttribute($oUser, $sClass, $sAttCode, $iActionCode, /*dbObjectSet*/ $oInstanceSet = null);
  54. abstract public function IsAdministrator($oUser);
  55. abstract public function FlushPrivileges();
  56. }
  57. abstract class User extends cmdbAbstractObject
  58. {
  59. public static function Init()
  60. {
  61. $aParams = array
  62. (
  63. "category" => "core",
  64. "key_type" => "autoincrement",
  65. "name_attcode" => "login",
  66. "state_attcode" => "",
  67. "reconc_keys" => array(),
  68. "db_table" => "priv_user",
  69. "db_key_field" => "id",
  70. "db_finalclass_field" => "",
  71. "display_template" => "",
  72. );
  73. MetaModel::Init_Params($aParams);
  74. //MetaModel::Init_InheritAttributes();
  75. MetaModel::Init_AddAttribute(new AttributeExternalKey("contactid", array("targetclass"=>"Person", "allowed_values"=>null, "sql"=>"contactid", "is_null_allowed"=>true, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array())));
  76. MetaModel::Init_AddAttribute(new AttributeExternalField("last_name", array("allowed_values"=>null, "extkey_attcode"=> 'contactid', "target_attcode"=>"name")));
  77. MetaModel::Init_AddAttribute(new AttributeExternalField("first_name", array("allowed_values"=>null, "extkey_attcode"=> 'contactid', "target_attcode"=>"first_name")));
  78. MetaModel::Init_AddAttribute(new AttributeExternalField("email", array("allowed_values"=>null, "extkey_attcode"=> 'contactid', "target_attcode"=>"email")));
  79. MetaModel::Init_AddAttribute(new AttributeString("login", array("allowed_values"=>null, "sql"=>"login", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  80. MetaModel::Init_AddAttribute(new AttributeApplicationLanguage("language", array("sql"=>"language", "default_value"=>"EN US", "is_null_allowed"=>false, "depends_on"=>array())));
  81. MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("profile_list", array("linked_class"=>"URP_UserProfile", "ext_key_to_me"=>"userid", "ext_key_to_remote"=>"profileid", "allowed_values"=>null, "count_min"=>1, "count_max"=>0, "depends_on"=>array())));
  82. // Display lists
  83. MetaModel::Init_SetZListItems('details', array('contactid', 'first_name', 'email', 'login', 'language', 'profile_list')); // Attributes to be displayed for the complete details
  84. MetaModel::Init_SetZListItems('list', array('finalclass', 'first_name', 'last_name', 'login')); // Attributes to be displayed for a list
  85. // Search criteria
  86. MetaModel::Init_SetZListItems('standard_search', array('login', 'contactid')); // Criteria of the std search form
  87. MetaModel::Init_SetZListItems('advanced_search', array('login', 'contactid')); // Criteria of the advanced search form
  88. }
  89. abstract public function CheckCredentials($sPassword);
  90. abstract public function TrustWebServerContext();
  91. abstract public function CanChangePassword();
  92. abstract public function ChangePassword($sOldPassword, $sNewPassword);
  93. function GetGrantAsHtml($sClass, $iAction)
  94. {
  95. if (UserRights::IsActionAllowed($sClass, $iAction, null, $this))
  96. {
  97. return '<span style="background-color: #ddffdd;">'.Dict::S('UI:UserManagement:ActionAllowed:Yes').'</span>';
  98. }
  99. else
  100. {
  101. return '<span style="background-color: #ffdddd;">'.Dict::S('UI:UserManagement:ActionAllowed:No').'</span>';
  102. }
  103. }
  104. function DoShowGrantSumary($oPage, $sClassCategory)
  105. {
  106. if (UserRights::IsAdministrator($this))
  107. {
  108. // Looks dirty, but ok that's THE ONE
  109. $oPage->p(Dict::S('UI:UserManagement:AdminProfile+'));
  110. return;
  111. }
  112. $aDisplayData = array();
  113. foreach (MetaModel::GetClasses($sClassCategory) as $sClass)
  114. {
  115. // Skip non instantiable classes
  116. if (MetaModel::IsAbstract($sClass)) continue;
  117. $aClassStimuli = MetaModel::EnumStimuli($sClass);
  118. if (count($aClassStimuli) > 0)
  119. {
  120. $aStimuli = array();
  121. foreach ($aClassStimuli as $sStimulusCode => $oStimulus)
  122. {
  123. if (UserRights::IsStimulusAllowed($sClass, $sStimulusCode, null, $this))
  124. {
  125. $aStimuli[] = '<span title="'.$sStimulusCode.': '.htmlentities($oStimulus->GetDescription()).'">'.htmlentities($oStimulus->GetLabel()).'</span>';
  126. }
  127. }
  128. $sStimuli = implode(', ', $aStimuli);
  129. }
  130. else
  131. {
  132. $sStimuli = '<em title="'.Dict::S('UI:UserManagement:NoLifeCycleApplicable+').'">'.Dict::S('UI:UserManagement:NoLifeCycleApplicable').'</em>';
  133. }
  134. $aDisplayData[] = array(
  135. 'class' => MetaModel::GetName($sClass),
  136. 'read' => $this->GetGrantAsHtml($sClass, UR_ACTION_READ),
  137. 'bulkread' => $this->GetGrantAsHtml($sClass, UR_ACTION_BULK_READ),
  138. 'write' => $this->GetGrantAsHtml($sClass, UR_ACTION_MODIFY),
  139. 'bulkwrite' => $this->GetGrantAsHtml($sClass, UR_ACTION_BULK_MODIFY),
  140. 'stimuli' => $sStimuli,
  141. );
  142. }
  143. $aDisplayConfig = array();
  144. $aDisplayConfig['class'] = array('label' => Dict::S('UI:UserManagement:Class'), 'description' => Dict::S('UI:UserManagement:Class+'));
  145. $aDisplayConfig['read'] = array('label' => Dict::S('UI:UserManagement:Action:Read'), 'description' => Dict::S('UI:UserManagement:Action:Read+'));
  146. $aDisplayConfig['bulkread'] = array('label' => Dict::S('UI:UserManagement:Action:BulkRead'), 'description' => Dict::S('UI:UserManagement:Action:BulkRead+'));
  147. $aDisplayConfig['write'] = array('label' => Dict::S('UI:UserManagement:Action:Modify'), 'description' => Dict::S('UI:UserManagement:Action:Modify+'));
  148. $aDisplayConfig['bulkwrite'] = array('label' => Dict::S('UI:UserManagement:Action:BulkModify'), 'description' => Dict::S('UI:UserManagement:Action:BulkModify+'));
  149. $aDisplayConfig['stimuli'] = array('label' => Dict::S('UI:UserManagement:Action:Stimuli'), 'description' => Dict::S('UI:UserManagement:Action:Stimuli+'));
  150. $oPage->table($aDisplayConfig, $aDisplayData);
  151. }
  152. function DisplayBareRelations(WebPage $oPage, $bEditMode = false)
  153. {
  154. parent::DisplayBareRelations($oPage, $bEditMode);
  155. if (!$bEditMode)
  156. {
  157. $oPage->SetCurrentTab(Dict::S('UI:UserManagement:GrantMatrix'));
  158. $this->DoShowGrantSumary($oPage, 'bizmodel');
  159. // debug
  160. if (false)
  161. {
  162. $oPage->SetCurrentTab('More on user rigths (dev only)');
  163. $oPage->add("<h3>User rights</h3>\n");
  164. $this->DoShowGrantSumary($oPage, 'addon/userrights');
  165. $oPage->add("<h3>Change log</h3>\n");
  166. $this->DoShowGrantSumary($oPage, 'core/cmdb');
  167. $oPage->add("<h3>Application</h3>\n");
  168. $this->DoShowGrantSumary($oPage, 'application');
  169. $oPage->add("<h3>GUI</h3>\n");
  170. $this->DoShowGrantSumary($oPage, 'gui');
  171. }
  172. }
  173. }
  174. }
  175. /**
  176. * Abstract class for all types of "internal" authentication i.e. users
  177. * for which the application is supplied a login and a password opposed
  178. * to "external" users for whom the authentication is performed outside
  179. * of the application (by the web server for example).
  180. * Note that "internal" users do not necessary correspond to a local authentication
  181. * they may be authenticated by a remote system, like in authent-ldap.
  182. */
  183. abstract class UserInternal extends User
  184. {
  185. // Nothing special, just a base class to categorize this type of authenticated users
  186. public static function Init()
  187. {
  188. $aParams = array
  189. (
  190. "category" => "core",
  191. "key_type" => "autoincrement",
  192. "name_attcode" => "login",
  193. "state_attcode" => "",
  194. "reconc_keys" => array('login'),
  195. "db_table" => "priv_internalUser",
  196. "db_key_field" => "id",
  197. "db_finalclass_field" => "",
  198. );
  199. MetaModel::Init_Params($aParams);
  200. MetaModel::Init_InheritAttributes();
  201. // Display lists
  202. MetaModel::Init_SetZListItems('details', array('contactid', 'first_name', 'email', 'login', 'language', 'profile_list')); // Attributes to be displayed for the complete details
  203. MetaModel::Init_SetZListItems('list', array('finalclass', 'first_name', 'last_name', 'login')); // Attributes to be displayed for a list
  204. // Search criteria
  205. MetaModel::Init_SetZListItems('standard_search', array('login', 'contactid')); // Criteria of the std search form
  206. MetaModel::Init_SetZListItems('advanced_search', array('login', 'contactid')); // Criteria of the advanced search form
  207. }
  208. }
  209. /**
  210. * User management core API
  211. *
  212. * @package iTopORM
  213. */
  214. class UserRights
  215. {
  216. protected static $m_oAddOn;
  217. protected static $m_oUser;
  218. protected static $m_oRealUser;
  219. public static function SelectModule($sModuleName)
  220. {
  221. if (!class_exists($sModuleName))
  222. {
  223. throw new CoreException("Could not select this module, '$sModuleName' in not a valid class name");
  224. return;
  225. }
  226. if (!is_subclass_of($sModuleName, 'UserRightsAddOnAPI'))
  227. {
  228. throw new CoreException("Could not select this module, the class '$sModuleName' is not derived from UserRightsAddOnAPI");
  229. return;
  230. }
  231. self::$m_oAddOn = new $sModuleName;
  232. self::$m_oAddOn->Init();
  233. self::$m_oUser = null;
  234. self::$m_oRealUser = null;
  235. }
  236. public static function GetModuleInstance()
  237. {
  238. return self::$m_oAddOn;
  239. }
  240. // Installation: create the very first user
  241. public static function CreateAdministrator($sAdminUser, $sAdminPwd, $sLanguage = 'EN US')
  242. {
  243. return self::$m_oAddOn->CreateAdministrator($sAdminUser, $sAdminPwd, $sLanguage);
  244. }
  245. // Installation (e.g: give default values for users)
  246. public static function Setup()
  247. {
  248. // to be discussed...
  249. return self::$m_oAddOn->Setup();
  250. }
  251. protected static function IsLoggedIn()
  252. {
  253. if (self::$m_oUser == null)
  254. {
  255. return false;
  256. }
  257. else
  258. {
  259. return true;
  260. }
  261. }
  262. public static function Login($sName, $sAuthentication = 'any')
  263. {
  264. $oUser = self::FindUser($sName, $sAuthentication);
  265. if (is_null($oUser))
  266. {
  267. return false;
  268. }
  269. self::$m_oUser = $oUser;
  270. Dict::SetUserLanguage(self::GetUserLanguage());
  271. return true;
  272. }
  273. public static function CheckCredentials($sName, $sPassword, $sAuthentication = 'any')
  274. {
  275. $oUser = self::FindUser($sName, $sAuthentication);
  276. if (is_null($oUser))
  277. {
  278. return false;
  279. }
  280. if (!$oUser->CheckCredentials($sPassword))
  281. {
  282. return false;
  283. }
  284. return true;
  285. }
  286. public static function TrustWebServerContext()
  287. {
  288. if (!is_null(self::$m_oUser))
  289. {
  290. return self::$m_oUser->TrustWebServerContext();
  291. }
  292. else
  293. {
  294. return false;
  295. }
  296. }
  297. public static function CanChangePassword()
  298. {
  299. if (!is_null(self::$m_oUser))
  300. {
  301. return self::$m_oUser->CanChangePassword();
  302. }
  303. else
  304. {
  305. return false;
  306. }
  307. }
  308. public static function CanLogOff()
  309. {
  310. if (!is_null(self::$m_oUser))
  311. {
  312. return self::$m_oUser->CanLogOff();
  313. }
  314. else
  315. {
  316. return false;
  317. }
  318. }
  319. public static function ChangePassword($sCurrentPassword, $sNewPassword)
  320. {
  321. if (!is_null(self::$m_oUser))
  322. {
  323. return self::$m_oUser->ChangePassword($sCurrentPassword, $sNewPassword);
  324. }
  325. else
  326. {
  327. return false;
  328. }
  329. }
  330. public static function Impersonate($sName, $sPassword)
  331. {
  332. if (!self::CheckLogin()) return false;
  333. $oUser = self::FindUser($sName);
  334. if (is_null($oUser))
  335. {
  336. return false;
  337. }
  338. if (!$oUser->CheckCredentials($sPassword))
  339. {
  340. return false;
  341. }
  342. self::$m_oRealUser = self::$m_oUser;
  343. self::$m_oUser = $oUser;
  344. Dict::SetUserLanguage(self::GetUserLanguage());
  345. return true;
  346. }
  347. public static function GetUser()
  348. {
  349. if (is_null(self::$m_oUser))
  350. {
  351. return '';
  352. }
  353. else
  354. {
  355. return self::$m_oUser->Get('login');
  356. }
  357. }
  358. public static function GetUserLanguage()
  359. {
  360. if (is_null(self::$m_oUser))
  361. {
  362. return 'EN US';
  363. }
  364. else
  365. {
  366. return self::$m_oUser->Get('language');
  367. }
  368. }
  369. public static function GetUserId($sName = '')
  370. {
  371. if (empty($sName))
  372. {
  373. // return current user id
  374. if (is_null(self::$m_oUser))
  375. {
  376. return null;
  377. }
  378. return self::$m_oUser->GetKey();
  379. }
  380. else
  381. {
  382. // find the id out of the login string
  383. $oUser = self::$m_oAddOn->FindUser($sName);
  384. if (is_null($oUser))
  385. {
  386. return null;
  387. }
  388. return $oUser->GetKey();
  389. }
  390. }
  391. public static function GetContactId($sName = '')
  392. {
  393. if (empty($sName))
  394. {
  395. $oUser = self::$m_oUser;
  396. }
  397. else
  398. {
  399. $oUser = FindUser($sName);
  400. }
  401. if (is_null($oUser))
  402. {
  403. return '';
  404. }
  405. return $oUser->Get('contactid');
  406. }
  407. public static function IsImpersonated()
  408. {
  409. if (is_null(self::$m_oRealUser))
  410. {
  411. return false;
  412. }
  413. return true;
  414. }
  415. public static function GetRealUser()
  416. {
  417. if (is_null(self::$m_oRealUser))
  418. {
  419. return '';
  420. }
  421. return self::$m_oRealUser->Get('login');
  422. }
  423. public static function GetRealUserId()
  424. {
  425. if (is_null(self::$m_oRealUser))
  426. {
  427. return '';
  428. }
  429. return self::$m_oRealUser->GetKey();
  430. }
  431. protected static function CheckLogin()
  432. {
  433. if (!self::IsLoggedIn())
  434. {
  435. //throw new UserRightException('No user logged in', array());
  436. return false;
  437. }
  438. return true;
  439. }
  440. public static function GetFilter($sClass)
  441. {
  442. // #@# to cleanup !
  443. return new DBObjectSearch($sClass);
  444. if (!self::CheckLogin()) return false;
  445. if (self::IsAdministrator()) return new DBObjectSearch($sClass);
  446. // this module is forbidden for non admins
  447. if (MetaModel::HasCategory($sClass, 'addon/userrights')) return false;
  448. // the rest is allowed (#@# to be improved)
  449. if (!MetaModel::HasCategory($sClass, 'bizmodel')) return new DBObjectSearch($sClass);
  450. return self::$m_oAddOn->GetFilter(self::$m_oUser->GetKey(), $sClass);
  451. }
  452. public static function GetSelectFilter($sClass)
  453. {
  454. // Need to load some records before the login is performed (user preferences)
  455. if (MetaModel::HasCategory($sClass, 'alwaysreadable')) return true;
  456. // ne marche pas... pourquoi?
  457. //if (!self::CheckLogin()) return false;
  458. if (self::IsAdministrator()) return true;
  459. // this module is forbidden for non admins.... BUT I NEED IT HERE TO DETERMINE USER RIGHTS
  460. if (MetaModel::HasCategory($sClass, 'addon/userrights')) return true;
  461. // the rest is allowed (#@# to be improved)
  462. if (!MetaModel::HasCategory($sClass, 'bizmodel')) return true;
  463. return self::$m_oAddOn->GetSelectFilter(self::$m_oUser, $sClass);
  464. }
  465. public static function IsActionAllowed($sClass, $iActionCode, /*dbObjectSet*/ $oInstanceSet = null, $oUser = null)
  466. {
  467. if (!self::CheckLogin()) return false;
  468. if (self::IsAdministrator($oUser)) return true;
  469. // #@# Temporary?????
  470. // The read access is controlled in MetaModel::MakeSelectQuery()
  471. if ($iActionCode == UR_ACTION_READ) return true;
  472. // this module is forbidden for non admins
  473. if (MetaModel::HasCategory($sClass, 'addon/userrights')) return false;
  474. // the rest is allowed (#@# to be improved)
  475. if (!MetaModel::HasCategory($sClass, 'bizmodel')) return true;
  476. if (is_null($oUser))
  477. {
  478. $oUser = self::$m_oUser;
  479. }
  480. return self::$m_oAddOn->IsActionAllowed($oUser, $sClass, $iActionCode, $oInstanceSet);
  481. }
  482. public static function IsStimulusAllowed($sClass, $sStimulusCode, /*dbObjectSet*/ $oInstanceSet = null, $oUser = null)
  483. {
  484. if (!self::CheckLogin()) return false;
  485. if (self::IsAdministrator($oUser)) return true;
  486. // this module is forbidden for non admins
  487. if (MetaModel::HasCategory($sClass, 'addon/userrights')) return false;
  488. // the rest is allowed (#@# to be improved)
  489. if (!MetaModel::HasCategory($sClass, 'bizmodel')) return true;
  490. if (is_null($oUser))
  491. {
  492. $oUser = self::$m_oUser;
  493. }
  494. return self::$m_oAddOn->IsStimulusAllowed($oUser, $sClass, $sStimulusCode, $oInstanceSet);
  495. }
  496. public static function IsActionAllowedOnAttribute($sClass, $sAttCode, $iActionCode, /*dbObjectSet*/ $oInstanceSet = null, $oUser = null)
  497. {
  498. if (!self::CheckLogin()) return false;
  499. if (self::IsAdministrator($oUser)) return true;
  500. // this module is forbidden for non admins
  501. if (MetaModel::HasCategory($sClass, 'addon/userrights')) return false;
  502. // the rest is allowed (#@# to be improved)
  503. if (!MetaModel::HasCategory($sClass, 'bizmodel')) return true;
  504. if (is_null($oUser))
  505. {
  506. $oUser = self::$m_oUser;
  507. }
  508. return self::$m_oAddOn->IsActionAllowedOnAttribute($oUser, $sClass, $sAttCode, $iActionCode, $oInstanceSet);
  509. }
  510. public static function IsAdministrator($oUser = null)
  511. {
  512. if (!self::CheckLogin()) return false;
  513. if (is_null($oUser))
  514. {
  515. $oUser = self::$m_oUser;
  516. }
  517. return self::$m_oAddOn->IsAdministrator($oUser);
  518. }
  519. public static function FlushPrivileges()
  520. {
  521. return self::$m_oAddOn->FlushPrivileges();
  522. }
  523. static $m_aCacheUsers;
  524. /**
  525. * Find a user based on its login and its type of authentication
  526. * @param string $sLogin Login/identifier of the user
  527. * @param string $sAuthentication Type of authentication used: internal|external|any
  528. * @return User The found user or null
  529. */
  530. protected static function FindUser($sLogin, $sAuthentication = 'any')
  531. {
  532. if ($sAuthentication == 'any')
  533. {
  534. $oUser = self::FindUser($sLogin, 'internal');
  535. if ($oUser == null)
  536. {
  537. $oUser = self::FindUser($sLogin, 'external');
  538. }
  539. }
  540. else
  541. {
  542. if (!isset(self::$m_aCacheUsers))
  543. {
  544. self::$m_aCacheUsers = array('internal' => array(), 'external' => array());
  545. }
  546. if (!isset(self::$m_aCacheUsers[$sAuthentication][$sLogin]))
  547. {
  548. switch($sAuthentication)
  549. {
  550. case 'external':
  551. $sBaseClass = 'UserExternal';
  552. break;
  553. case 'internal':
  554. $sBaseClass = 'UserInternal';
  555. break;
  556. default:
  557. echo "<p>sAuthentication = $sAuthentication</p>\n";
  558. assert(false); // should never happen
  559. }
  560. $oSearch = DBObjectSearch::FromOQL("SELECT $sBaseClass WHERE login = :login");
  561. $oSet = new DBObjectSet($oSearch, array(), array('login' => $sLogin));
  562. $oUser = $oSet->fetch();
  563. self::$m_aCacheUsers[$sAuthentication][$sLogin] = $oUser;
  564. }
  565. $oUser = self::$m_aCacheUsers[$sAuthentication][$sLogin];
  566. }
  567. return $oUser;
  568. }
  569. }
  570. ?>