class_UserAuthFilter.php

Go to the documentation of this file.
00001 <?php
00024 class UserAuthFilter extends BaseFilter implements Filterable {
00025         // Exception constants
00026         const EXCEPTION_AUTH_DATA_INVALID = 0x1b0;
00027 
00031         private $authMethod = "";
00032 
00038         protected function __construct () {
00039                 // Call parent constructor
00040                 parent::__construct(__CLASS__);
00041         }
00042 
00048         public final static function createUserAuthFilter () {
00049                 // Get a new instance
00050                 $filterInstance = new UserAuthFilter();
00051 
00052                 // Set default auth method
00053                 $filterInstance->setDefaultAuthMethod();
00054 
00055                 // Return the instance
00056                 return $filterInstance;
00057         }
00058 
00064         protected function setDefaultAuthMethod () {
00065                 $this->authMethod = $this->getConfigInstance()->readConfig('auth_method_class');
00066         }
00067 
00078         public function execute (Requestable $requestInstance, Responseable $responseInstance) {
00079                 // Then get an auth instance for checking and updating the auth cookies
00080                 $authInstance = ObjectFactory::createObjectByName($this->authMethod, array($responseInstance));
00081 
00082                 // Set request instance
00083                 $authInstance->setRequestInstance($requestInstance);
00084 
00085                 // Now, get the auth data for comparison
00086                 $authLogin = $authInstance->getUserAuth();
00087                 $authHash  = $authInstance->getPasswordAuth();
00088 
00089                 // If one is empty stop here
00090                 if ((empty($authLogin)) || (empty($authHash))) {
00091                         // Destroy the auth data
00092                         $authInstance->destroyAuthData();
00093 
00094                         // Mark the request as invalid
00095                         $requestInstance->requestIsValid(false);
00096 
00097                         // Add fatal message
00098                         $responseInstance->addFatalMessage('auth_data_incomplete');
00099 
00100                         // Stop here
00101                         throw new UserAuthorizationException($this, self::EXCEPTION_AUTH_DATA_INVALID);
00102                 } // END - if
00103 
00104                 // Regular user account
00105                 $className = $this->getConfigInstance()->readConfig('user_class');
00106                 $methodName = 'createMemberByUserName';
00107 
00108                 // Now, try to get a user or guest instance
00109                 if ($authLogin == $this->getConfigInstance()->readConfig('guest_login_user')) {
00110                         // Set class
00111                         $className = $this->getConfigInstance()->readConfig('guest_class');
00112                         $methodName = 'createGuestByUserName';
00113                 } // END - if
00114 
00115                 // Does the guest class exist?
00116                 if (!class_exists($className)) {
00117                         // Then abort here
00118                         throw new ClassNotFoundException (array($this, $className), self::EXCEPTION_CLASS_NOT_FOUND);
00119                 } // END - if
00120 
00121                 // Now try the dynamic login
00122                 $userInstance = call_user_func_array(array($className, $methodName), array($authLogin));
00123 
00124                 // Is the password correct?
00125                 if ($userInstance->getPasswordHash() !== $authHash) {
00126                         // Mismatching password
00127                         throw new UserPasswordMismatchException(array($this, $userInstance), BaseUser::EXCEPTION_USER_PASS_MISMATCH);
00128                 } // END - if
00129 
00130                 // Remember auth and user instances in registry
00131                 Registry::getRegistry()->addInstance('auth', $authInstance);
00132                 Registry::getRegistry()->addInstance('user', $userInstance);
00133         }
00134 }
00135 
00136 // [EOF]
00137 ?>

Generated on Mon Dec 8 01:06:45 2008 for Ship-Simulator by  doxygen 1.5.6