class_UserAuthFilter.php
Go to the documentation of this file.00001 <?php
00024 class UserAuthFilter extends BaseFilter implements Filterable {
00025
00026 const EXCEPTION_AUTH_DATA_INVALID = 0x1b0;
00027
00031 private $authMethod = "";
00032
00038 protected function __construct () {
00039
00040 parent::__construct(__CLASS__);
00041 }
00042
00048 public final static function createUserAuthFilter () {
00049
00050 $filterInstance = new UserAuthFilter();
00051
00052
00053 $filterInstance->setDefaultAuthMethod();
00054
00055
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
00080 $authInstance = ObjectFactory::createObjectByName($this->authMethod, array($responseInstance));
00081
00082
00083 $authInstance->setRequestInstance($requestInstance);
00084
00085
00086 $authLogin = $authInstance->getUserAuth();
00087 $authHash = $authInstance->getPasswordAuth();
00088
00089
00090 if ((empty($authLogin)) || (empty($authHash))) {
00091
00092 $authInstance->destroyAuthData();
00093
00094
00095 $requestInstance->requestIsValid(false);
00096
00097
00098 $responseInstance->addFatalMessage('auth_data_incomplete');
00099
00100
00101 throw new UserAuthorizationException($this, self::EXCEPTION_AUTH_DATA_INVALID);
00102 }
00103
00104
00105 $className = $this->getConfigInstance()->readConfig('user_class');
00106 $methodName = 'createMemberByUserName';
00107
00108
00109 if ($authLogin == $this->getConfigInstance()->readConfig('guest_login_user')) {
00110
00111 $className = $this->getConfigInstance()->readConfig('guest_class');
00112 $methodName = 'createGuestByUserName';
00113 }
00114
00115
00116 if (!class_exists($className)) {
00117
00118 throw new ClassNotFoundException (array($this, $className), self::EXCEPTION_CLASS_NOT_FOUND);
00119 }
00120
00121
00122 $userInstance = call_user_func_array(array($className, $methodName), array($authLogin));
00123
00124
00125 if ($userInstance->getPasswordHash() !== $authHash) {
00126
00127 throw new UserPasswordMismatchException(array($this, $userInstance), BaseUser::EXCEPTION_USER_PASS_MISMATCH);
00128 }
00129
00130
00131 Registry::getRegistry()->addInstance('auth', $authInstance);
00132 Registry::getRegistry()->addInstance('user', $userInstance);
00133 }
00134 }
00135
00136
00137 ?>