Changeset 2916
- Timestamp:
- 07/22/08 16:42:26 (3 months ago)
- Files:
-
- trunk/utils/copix/auth/CopixAuth.class.php (modified) (9 diffs)
- trunk/utils/copix/auth/CopixCredentialHandlerFactory.class.php (modified) (7 diffs)
- trunk/utils/copix/auth/CopixGroupHandlerFactory.class.php (modified) (4 diffs)
- trunk/utils/copix/auth/CopixUser.class.php (modified) (19 diffs)
- trunk/utils/copix/auth/CopixUserException.class.php (added)
- trunk/utils/copix/auth/CopixUserHandlerFactory.class.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/utils/copix/auth/CopixAuth.class.php
r2870 r2916 1 1 <?php 2 2 /** 3 * @package copix4 * @subpackage auth5 * @author Gérald Croës6 * @copyright CopixTeam7 * @link http://copix.org8 * @license http://www.gnu.org/licenses/lgpl.html GNU General Lesser Public Licence, see LICENCE file3 * @package copix 4 * @subpackage auth 5 * @author Gérald Croës 6 * @copyright CopixTeam 7 * @link http://copix.org 8 * @license http://www.gnu.org/licenses/lgpl.html GNU General Lesser Public Licence, see LICENCE file 9 9 */ 10 10 … … 12 12 * Classe de base pour les exceptions d'authentification 13 13 * 14 * @package copix15 * @subpackage auth14 * @package copix 15 * @subpackage auth 16 16 */ 17 17 class CopixAuthException extends CopixException {} … … 20 20 * Gestion des informations sur l'authentification 21 21 * 22 * @package copix23 * @subpackage auth22 * @package copix 23 * @subpackage auth 24 24 */ 25 25 class CopixAuth { … … 29 29 * @return CopixUser 30 30 */ 31 static public function getCurrentUser () {31 public static function getCurrentUser () { 32 32 if (($user = CopixSession::get ('copix|auth|user')) === null) { 33 33 CopixSession::set ('copix|auth|user', new CopixUser ()); 34 } elseif (! ($user instanceof ICopixUser)){34 } else if (!($user instanceof ICopixUser)) { 35 35 CopixSession::set ('copix|auth|user', new CopixUser ()); 36 36 } … … 41 41 * Destruction de l'utilisateur courant 42 42 */ 43 static public function destroyCurrentUser () {43 public static function destroyCurrentUser () { 44 44 CopixSession::set ('copix|auth|user', null); 45 45 } … … 49 49 * Classe qui gère le parsing des module.xml pour enregistrer les handlers 50 50 * 51 * @package copix52 * @subpackage auth51 * @package copix 52 * @subpackage auth 53 53 */ 54 54 class CopixAuthParserHandler { 55 56 55 /** 57 56 * Parse les handlers de type User … … 62 61 public static function parseUserHandler ($pXmlNode) { 63 62 $toReturn = array (); 64 foreach ($pXmlNode as $module =>$userHandlers) {63 foreach ($pXmlNode as $module => $userHandlers) { 65 64 foreach ($userHandlers as $userHandler) { 66 $tempUserHandler = array ();67 $tempUserHandler['name'] = (string)$module.'|'.$userHandler['name'];68 $tempUserHandler['required'] = (isset ($userHandler['required'])) ? ($userHandler['required']!='false') : null;69 $tempUserHandler['rank'] = (isset ($userHandler['rank'])) ? (string)$userHandler['rank'] : null;65 $tempUserHandler = array (); 66 $tempUserHandler['name'] = (string)$module . '|' . $userHandler['name']; 67 $tempUserHandler['required'] = (isset ($userHandler['required'])) ? ($userHandler['required'] != 'false') : null; 68 $tempUserHandler['rank'] = (isset ($userHandler['rank'])) ? (string)$userHandler['rank'] : null; 70 69 $toReturn[$tempUserHandler['name']] = $tempUserHandler; 71 70 } … … 82 81 public static function parseCredentialHandler ($pXmlNode) { 83 82 $toReturn = array (); 84 foreach ($pXmlNode as $module =>$credentialHandlers) {83 foreach ($pXmlNode as $module => $credentialHandlers) { 85 84 foreach ($credentialHandlers as $credentialHandler) { 86 $tempCredentialHandler = array ();87 $tempCredentialHandler['name'] = (string)$module.'|'.$credentialHandler['name'];88 $tempCredentialHandler['stopOnSuccess'] = (isset ($credentialHandler['stopOnSuccess'])) ? ($credentialHandler['stopOnSuccess'] !='false') : null;89 $tempCredentialHandler['stopOnFailure'] = (isset ($credentialHandler['stopOnFailure'])) ? ($credentialHandler['stopOnFailure'] !='false') : null;85 $tempCredentialHandler = array (); 86 $tempCredentialHandler['name'] = (string)$module . '|' . $credentialHandler['name']; 87 $tempCredentialHandler['stopOnSuccess'] = (isset ($credentialHandler['stopOnSuccess'])) ? ($credentialHandler['stopOnSuccess'] != 'false') : null; 88 $tempCredentialHandler['stopOnFailure'] = (isset ($credentialHandler['stopOnFailure'])) ? ($credentialHandler['stopOnFailure'] != 'false') : null; 90 89 if (isset ($credentialHandler->handle)) { 91 90 $tempHandle = array (); … … 116 115 public static function parseGroupHandler ($pXmlNode) { 117 116 $toReturn = array (); 118 foreach ($pXmlNode as $module =>$groupHandlers) {117 foreach ($pXmlNode as $module => $groupHandlers) { 119 118 foreach ($groupHandlers as $groupHandler) { 120 $tempGroupHandler = array ();121 $tempGroupHandler['name'] = (string)$module.'|'.$groupHandler['name'];122 $tempGroupHandler['required'] = (isset ($groupHandler['required'])) ? ($groupHandler['required']!='false') : null;119 $tempGroupHandler = array (); 120 $tempGroupHandler['name'] = (string)$module . '|' . $groupHandler['name']; 121 $tempGroupHandler['required'] = (isset ($groupHandler['required'])) ? ($groupHandler['required'] != 'false') : null; 123 122 $toReturn[$tempGroupHandler['name']] = $tempGroupHandler; 124 123 } 125 124 } 126 125 return $toReturn; 127 } 128 126 } 129 127 } trunk/utils/copix/auth/CopixCredentialHandlerFactory.class.php
r2870 r2916 1 1 <?php 2 2 /** 3 * @package copix4 * @subpackage auth5 * @author Croës Gérald6 * @copyright CopixTeam7 * @link http://www.copix.org8 * @license http://www.gnu.org/licenses/lgpl.html GNU General Lesser Public Licence, see LICENCE file3 * @package copix 4 * @subpackage auth 5 * @author Croës Gérald 6 * @copyright CopixTeam 7 * @link http://www.copix.org 8 * @license http://www.gnu.org/licenses/lgpl.html GNU General Lesser Public Licence, see LICENCE file 9 9 */ 10 10 … … 12 12 * Exception de base pour les droits insufisants 13 13 * 14 * @package copix15 * @subpackage auth14 * @package copix 15 * @subpackage auth 16 16 */ 17 17 class CopixCredentialException extends CopixException {} … … 20 20 * Interface pour les credentials handlers 21 21 * 22 * @package copix23 * @subpackage auth22 * @package copix 23 * @subpackage auth 24 24 */ 25 25 interface ICopixCredentialHandler { … … 30 30 * @param string $pString Chaine de droit, qui ne doit pas contenir le type 31 31 * @param CopixUser L'utilisateur courant 32 * @return bool 32 * @return boolean 33 33 */ 34 34 public function assert ($pStringType, $pString, $pUser); … … 36 36 37 37 /** 38 * @package copix39 * @subpackage auth38 * @package copix 39 * @subpackage auth 40 40 */ 41 41 class CopixCredentialHandlerFactory { … … 43 43 * Handlers déjà instanciés 44 44 * 45 * @var array of ICopixCredentialsHandler45 * @var ICopixCredentialsHandler[] 46 46 */ 47 47 private static $_handlers = array (); … … 59 59 self::$_handlers[$pHandlerId] = _ioClass ($pHandlerId); 60 60 } catch (Exception $e) { 61 throw new CopixUserException (_i18n ('copix:copixuser.error.undefinedCredentialHandler', $pHandlerId)); 61 throw new CopixUserException ( 62 _i18n ('copix:copixuser.error.undefinedCredentialHandler', $pHandlerId), 63 CopixUserException::UNDEFINED_CREDENTIAL_HANDLER 64 ); 62 65 } 63 66 } trunk/utils/copix/auth/CopixGroupHandlerFactory.class.php
r2870 r2916 1 1 <?php 2 2 /** 3 * @package copix4 * @subpackage auth5 * @author Gérald Croës6 * @copyright CopixTeam7 * @link http://copix.org8 * @license http://www.gnu.org/licenses/lgpl.html GNU General Lesser Public Licence, see LICENCE file3 * @package copix 4 * @subpackage auth 5 * @author Gérald Croës 6 * @copyright CopixTeam 7 * @link http://copix.org 8 * @license http://www.gnu.org/licenses/lgpl.html GNU General Lesser Public Licence, see LICENCE file 9 9 */ 10 10 … … 12 12 * Interface de gestion des groupes 13 13 * 14 * @package copix15 * @subpackage auth14 * @package copix 15 * @subpackage auth 16 16 */ 17 17 interface ICopixGroupHandler { … … 47 47 * @var array 48 48 */ 49 static private$_handlers = array ();49 private static $_handlers = array (); 50 50 51 51 /** … … 54 54 * @param mixed $pHandlerId Identifiant du handler à créer 55 55 * @return CopixUserHandler 56 * @throws CopixUserException 56 * @throws CopixUserException Handler de group non définit 57 57 */ 58 static public function create ($pHandlerId) {58 public static function create ($pHandlerId) { 59 59 if (!isset (self::$_handlers[$pHandlerId])) { 60 60 try { 61 61 self::$_handlers[$pHandlerId] = _ioClass ($pHandlerId); 62 62 } catch (Exception $e) { 63 throw new CopixUserException (_i18n ('copix:copixuser.error.undefinedGroupHandler', $pHandlerId)); 63 throw new CopixUserException ( 64 _i18n ('copix:copixuser.error.undefinedGroupHandler', $pHandlerId), 65 CopixUserException::UNDEFINED_GROUP_HANDLER 66 ); 64 67 } 65 68 } trunk/utils/copix/auth/CopixUser.class.php
r2870 r2916 1 1 <?php 2 2 /** 3 * @package copix4 * @subpackage auth5 * @author Croës Gérald6 * @copyright CopixTeam7 * @link http://copix.org8 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file3 * @package copix 4 * @subpackage auth 5 * @author Croës Gérald 6 * @copyright CopixTeam 7 * @link http://copix.org 8 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file 9 9 */ 10 11 /**12 * Exceptions utilisateurs13 *14 * @package copix15 * @subpackage auth16 */17 class CopixUserException extends CopixException {}18 10 19 11 /** 20 12 * Authentification et gestion des droits 21 13 * 22 * @package copix23 * @subpackage auth14 * @package copix 15 * @subpackage auth 24 16 */ 25 17 class CopixUser implements ICopixUser { … … 55 47 $this->_groups = false; 56 48 57 $responses = array ();49 $responses = array (); 58 50 $isConnected = false; 59 51 // N.B: les gestionnaires étant triés par rang croissant, les réponses le seront aussi... … … 66 58 if( $result->getResult () ) { 67 59 $isConnected = true; 68 } else if ($handler['required'] === true && (!isset ($pParams['append']) || !$pParams['append'])) {60 } else if ($handler['required'] === true && (!isset ($pParams['append']) || !$pParams['append'])) { 69 61 //On ne passe pas dans le required si on est en mode append 70 62 $isConnected = false; … … 112 104 $arGroupHandler = array (); 113 105 //Pour chaque utilisateur testé lors du processus de login, on demande la liste de ses groupes 114 foreach ($this->getResponses (true) as $logResult) {115 foreach ($handler->getUserGroups ($logResult->getId (), $logResult->getHandler ()) as $id => $group) {106 foreach ($this->getResponses (true) as $logResult) { 107 foreach ($handler->getUserGroups ($logResult->getId (), $logResult->getHandler ()) as $id => $group) { 116 108 $arGroupHandler[$id] = $group; 117 109 } … … 134 126 * 135 127 * @param string $pString Chaine de droit à tester (ex : basic:admin@news) 136 * @throws CopixCredentialException 128 * @throws CopixCredentialException L'utilisateur courant n'a pas ce droit 137 129 */ 138 130 public function assertCredential ($pString) { … … 154 146 } 155 147 156 $pStringType = substr ($pString, 0, strpos ($pString, ':'));157 $pStringString = substr ($pString, strpos ($pString, ':') +1);148 $pStringType = substr ($pString, 0, strpos ($pString, ':')); 149 $pStringString = substr ($pString, strpos ($pString, ':') + 1); 158 150 159 151 $success = false; 160 foreach (CopixConfig::instance ()->copixauth_getRegisteredCredentialHandlers () as $handler) {152 foreach (CopixConfig::instance ()->copixauth_getRegisteredCredentialHandlers () as $handler) { 161 153 if ((is_array ($handler['handle']) && in_array ($pStringType, $handler['handle'])) || $handler['handle'] === 'all') { 162 154 if (!((is_array ($handler['handleExcept']) && in_array ($pStringType, $handler['handleExcept'])) || $handler['handleExcept'] === $pStringType)) { … … 167 159 } 168 160 $success = $success || false; 169 } elseif ($result === true) {161 } else if ($result === true) { 170 162 if ($handler['stopOnSuccess']) { 171 163 return $this->_asserted[$pString] = true; … … 196 188 */ 197 189 public function getId () { 198 return !is_null($response = $this->_getFirstLogged ()) ? $response->getId () : null;190 return (!is_null ($response = $this->_getFirstLogged ())) ? $response->getId () : null; 199 191 } 200 192 … … 205 197 */ 206 198 public function getCaption () { 207 return !is_null($response = $this->_getFirstLogged ()) ? $response->getCaption () : null;199 return (!is_null ($response = $this->_getFirstLogged ())) ? $response->getCaption () : null; 208 200 } 209 201 … … 214 206 */ 215 207 public function getLogin () { 216 return !is_null($response = $this->_getFirstLogged ()) ? $response->getLogin () : null;208 return (!is_null ($response = $this->_getFirstLogged ())) ? $response->getLogin () : null; 217 209 } 218 210 … … 223 215 */ 224 216 public function getHandler () { 225 return !is_null($response = $this->_getFirstLogged ()) ? $response->getHandler () : null;217 return (!is_null ($response = $this->_getFirstLogged ())) ? $response->getHandler () : null; 226 218 } 227 219 … … 231 223 * @return array Tableau de la forme ("nom_du_gestionnaire", "id_utilisateur") ou null 232 224 */ 233 public function getIdentity () {234 return !is_null($response = $this->_getFirstLogged ()) ? $response->getIdentity() : null;225 public function getIdentity () { 226 return (!is_null ($response = $this->_getFirstLogged ())) ? $response->getIdentity () : null; 235 227 } 236 228 … … 238 230 * recherche l'information $pInformationId dans les réponses apportées durant le processus de login. 239 231 * 240 * @param string $pInformationId Le nom de l'information que l'on recherche241 * @param string $pUserHandler Dans quelle réponse on cherche. Si rien n'est donné, on prend la première information qui porte le nom demandé242 */ 243 public function getExtra ($pInformationId, $pUserHandler = null) {244 if ($pUserHandler === null) {245 foreach ($this->_logged as $userHandler =>$userResponse){232 * @param string $pInformationId Le nom de l'information que l'on recherche 233 * @param string $pUserHandler Dans quelle réponse on cherche. Si rien n'est donné, on prend la première information qui porte le nom demandé 234 */ 235 public function getExtra ($pInformationId, $pUserHandler = null) { 236 if ($pUserHandler === null) { 237 foreach ($this->_logged as $userHandler => $userResponse) { 246 238 $extra = $userResponse->getExtra (); 247 if (isset ($extra[$pInformationId])) {239 if (isset ($extra[$pInformationId])) { 248 240 return $extra[$pInformationId]; 249 241 } 250 242 } 251 } else{252 if (isset ($this->_logged[$pUserHandler])) {243 } else { 244 if (isset ($this->_logged[$pUserHandler])) { 253 245 $extra = $this->_logged[$pUserHandler]->getExtra (); 254 return isset ($extra[$pInformationId]) ? $extra[$pInformationId] : null;246 return (isset ($extra[$pInformationId])) ? $extra[$pInformationId] : null; 255 247 } 256 248 } … … 263 255 * @return array Tableau de la forme ("nom_du_gestionnaire", "id_utilisateur"), potentiellement vide 264 256 */ 265 public function getIdentities () {266 $toReturn = array ();267 foreach ($this->_logged as $response) {268 if ($response->getResult()) {269 $toReturn[] = $response->getIdentity ();257 public function getIdentities () { 258 $toReturn = array (); 259 foreach ($this->_logged as $response) { 260 if ($response->getResult ()) { 261 $toReturn[] = $response->getIdentity (); 270 262 } 271 263 } … … 274 266 275 267 /** 276 * Retourne la première réponse positive .268 * Retourne la première réponse positive 277 269 * 278 270 * @return CopixUserLogResponse … … 281 273 // Rappelez vous : les réponses sont classées par rang 282 274 foreach($this->_logged as $response) { 283 if($response->getResult ()) {275 if($response->getResult ()) { 284 276 return $response; 285 277 } … … 291 283 * Indique si l'utisateur à été correctement identifié via un handler donné 292 284 * 285 * @deprecated 286 * @see CopixUser::isConnectedWith 287 */ 288 public function isLoggedWith ($pHandlerName) { 289 return $this->isConnectedWith ($pHandlerName); 290 } 291 292 /** 293 * Indique si l'utilisateur est connecté avec un handler donné 294 * 293 295 * @param string $pHandlerName Nom du handler 294 296 * @return bool 295 * @deprecated296 * @see CopixUser::isConnectedWith297 */298 public function isLoggedWith ($pHandlerName) {299 return $this->isConnectedWith ($pHandlerName);300 }301 302 /**303 * Indique si l'utilisateur est connecté avec un handler donné.304 *305 * @param string $pHandlerName Nom du handler306 * @return bool307 297 */ 308 298 public function isConnectedWith ($pHandlerName) { 309 foreach ($this->_logged as $response) {310 if ($response->getResult() && $response->getHandler() == $pHandlerName) {299 foreach ($this->_logged as $response) { 300 if ($response->getResult () && $response->getHandler () == $pHandlerName) { 311 301 return true; 312 302 } … … 316 306 317 307 /** 318 * Vérifie si l'utilisateur est connecté avec le gestionnaire et l'identifiant indiqué .308 * Vérifie si l'utilisateur est connecté avec le gestionnaire et l'identifiant indiqué 319 309 * 320 * @param string $ $pHandlerName Nom du gestionnaire.310 * @param string $pHandlerName Nom du gestionnaire. 321 311 * @param mixed $pUserId Identifiant de l'utilisateur. 322 * @return boolean Vrai si l'utilisateur est reconnu.323 */ 324 public function isConnectedAs ($pHandlerName, $pUserId) {325 foreach ($this->_logged as $response) {326 if ($response->getResult() && $response->getHandler() == $pHandlerName && $response->getId() == $pUserId) {312 * @return boolean 313 */ 314 public function isConnectedAs ($pHandlerName, $pUserId) { 315 foreach ($this->_logged as $response) { 316 if ($response->getResult () && $response->getHandler () == $pHandlerName && $response->getId () == $pUserId) { 327 317 return true; 328 318 } … … 335 325 * 336 326 * @param string $pHandlerName Nom du handler 337 * @return array of CopixUserResponse /false si aucune réponse327 * @return CopixUserResponse[] ou false si aucune réponse 338 328 */ 339 329 public function getHandlerResponse ($pHandlerName) { 340 $toReturn = array ();341 foreach ($this->_logged as $response) {342 if ($response->getHandler() == $pHandlerName) {330 $toReturn = array (); 331 foreach ($this->_logged as $response) { 332 if ($response->getHandler () == $pHandlerName) { 343 333 $toReturn[] = $response; 344 334 } 345 335 } 346 switch (count($toReturn)) {336 switch (count ($toReturn)) { 347 337 case 0: return false; 348 338 case 1: return $toReturn[0]; trunk/utils/copix/auth/CopixUserHandlerFactory.class.php
r2870 r2916 1 1 <?php 2 2 /** 3 * @package copix4 * @subpackage auth5 * @author Gérald Croës6 * @copyright CopixTeam7 * @link http://copix.org8 * @license http://www.gnu.org/licenses/lgpl.html GNU General Lesser Public Licence, see LICENCE file3 * @package copix 4 * @subpackage auth 5 * @author Gérald Croës 6 * @copyright CopixTeam 7 * @link http://copix.org 8 * @license http://www.gnu.org/licenses/lgpl.html GNU General Lesser Public Licence, see LICENCE file 9 9 */ 10 10 11 11 /** 12 * Interface des classes décrivant un utilisateur .12 * Interface des classes décrivant un utilisateur 13 13 * 14 * @package copix 15 * @subpackage auth 14 16 */ 15 17 interface ICopixUser { 16 17 18 /** 18 * Retourne le libellé de l'utilisateur .19 * Retourne le libellé de l'utilisateur 19 20 * 20 21 * @return string 21 22 */ 22 public function getCaption ();23 public function getCaption (); 23 24 24 25 /** 25 * Retourne le login de l'utilisateur .26 * Retourne le login de l'utilisateur 26 27 * 27 28 * @return string 28 29 */ 29 public function getLogin ();30 public function getLogin (); 30 31 31 32 /** 32 * Retourne l'identifiant technique de l'utilisateur .33 * Retourne l'identifiant technique de l'utilisateur 33 34 * 34 35 * @return mixed 35 36 */ 36 public function getId ();37 public function getId (); 37 38 38 39 /** 39 * Retourne le nom du handler responsable de cet utilisateur .40 * Retourne le nom du handler responsable de cet utilisateur 40 41 * 41 42 * @return string 42 43 */ 43 public function getHandler(); 44 44 public function getHandler (); 45 45 } 46 46 … … 48 48 * Interface pour les handlers d'utilisateur 49 49 * 50 * @package copix51 * @subpackage auth50 * @package copix 51 * @subpackage auth 52 52 */ 53 53 interface ICopixUserHandler { … … 78 78 * 79 79 * @param array $pParams Critères de recherche (id, login et caption au minimum) 80 * @return array of ICopixUser80 * @return ICopixUser[] 81 81 */ 82 82 public function find ($pParams = array ()); … … 108 108 self::$_handlers[$pHandlerId] = _ioClass ($pHandlerId); 109 109 } catch (Exception $e) { 110 throw new CopixUserException (_i18n ('copix:copixuser.error.undefinedUserHandler', $pHandlerId)); 110 throw new CopixUserException ( 111 _i18n ('copix:copixuser.error.undefinedUserHandler', $pHandlerId), 112 CopixUserException::UNDEFINED_USER_HANDLER 113 ); 111 114 } 112 115 }
