. * * Consult LICENSE file for details ************************************************/ abstract class RequestProcessor { static protected $backend; static protected $deviceManager; static protected $topCollector; static protected $decoder; static protected $encoder; static protected $userIsAuthenticated; static protected $specialHeaders; /** * Authenticates the remote user * The sent HTTP authentication information is used to on Backend->Logon(). * As second step the GET-User verified by Backend->Setup() for permission check * Request::GetGETUser() is usually the same as the Request::GetAuthUser(). * If the GETUser is different from the AuthUser, the AuthUser MUST HAVE admin * permissions on GETUsers data store. Only then the Setup() will be sucessfull. * This allows the user 'john' to do operations as user 'joe' if he has sufficient privileges. * * @access public * @return * @throws AuthenticationRequiredException */ static public function Authenticate() { self::$userIsAuthenticated = false; $backend = ZPush::GetBackend(); if($backend->Logon(Request::GetAuthUser(), Request::GetAuthDomain(), Request::GetAuthPassword()) == false) throw new AuthenticationRequiredException("Access denied. Username or password incorrect"); // mark this request as "authenticated" self::$userIsAuthenticated = true; // check Auth-User's permissions on GETUser's store if($backend->Setup(Request::GetGETUser(), true) == false) throw new AuthenticationRequiredException(sprintf("Not enough privileges of '%s' to setup for user '%s': Permission denied", Request::GetAuthUser(), Request::GetGETUser())); } /** * Indicates if the user was "authenticated" * * @access public * @return boolean */ static public function isUserAuthenticated() { if (!isset(self::$userIsAuthenticated)) return false; return self::$userIsAuthenticated; } /** * Initialize the RequestProcessor * * @access public * @return */ static public function Initialize() { self::$backend = ZPush::GetBackend(); self::$deviceManager = ZPush::GetDeviceManager(); self::$topCollector = ZPush::GetTopCollector(); if (!ZPush::CommandNeedsPlainInput(Request::GetCommandCode())) self::$decoder = new WBXMLDecoder(Request::GetInputStream()); self::$encoder = new WBXMLEncoder(Request::GetOutputStream(), Request::GetGETAcceptMultipart()); } /** * Loads the command handler and processes a command sent from the mobile * * @access public * @return boolean */ static public function HandleRequest() { $handler = ZPush::GetRequestHandlerForCommand(Request::GetCommandCode()); // TODO handle WBXML exceptions here and print stack return $handler->Handle(Request::GetCommandCode()); } /** * Returns any additional headers which should be sent to the mobile * * @access public * @return array */ static public function GetSpecialHeaders() { if (!isset(self::$specialHeaders) || !is_array(self::$specialHeaders)) return array(); return self::$specialHeaders; } /** * Handles a command * * @param int $commandCode * * @access public * @return boolean */ abstract public function Handle($commandCode); } ?>