import v2.0.0.0_RC3 | 2012-07-01
https://github.com/lucanos/CommunityID -> http://www.itadmins.net/archives/357
This commit is contained in:
@ -16,7 +16,7 @@
|
||||
* @package Zend_Amf
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Server.php 16971 2009-07-22 18:05:45Z mikaelkael $
|
||||
* @version $Id: Server.php 18951 2009-11-12 16:26:19Z alexander $
|
||||
*/
|
||||
|
||||
/** Zend_Server_Interface */
|
||||
@ -62,10 +62,10 @@ class Zend_Amf_Server implements Zend_Server_Interface
|
||||
* @var array
|
||||
*/
|
||||
protected $_methods = array();
|
||||
|
||||
|
||||
/**
|
||||
* Array of classes that can be called without being explicitly loaded
|
||||
*
|
||||
*
|
||||
* Keys are class names.
|
||||
*
|
||||
* @var array
|
||||
@ -121,13 +121,13 @@ class Zend_Amf_Server implements Zend_Server_Interface
|
||||
|
||||
/**
|
||||
* Authentication handler object
|
||||
*
|
||||
*
|
||||
* @var Zend_Amf_Auth_Abstract
|
||||
*/
|
||||
protected $_auth;
|
||||
/**
|
||||
* ACL handler object
|
||||
*
|
||||
*
|
||||
* @var Zend_Acl
|
||||
*/
|
||||
protected $_acl;
|
||||
@ -136,9 +136,9 @@ class Zend_Amf_Server implements Zend_Server_Interface
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
Zend_Amf_Parse_TypeLoader::setResourceLoader(new Zend_Loader_PluginLoader(array("Zend_Amf_Parse_Resource" => "Zend/Amf/Parse/Resource")));
|
||||
Zend_Amf_Parse_TypeLoader::setResourceLoader(new Zend_Loader_PluginLoader(array("Zend_Amf_Parse_Resource" => "Zend/Amf/Parse/Resource")));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set authentication adapter
|
||||
*
|
||||
@ -159,7 +159,7 @@ class Zend_Amf_Server implements Zend_Server_Interface
|
||||
{
|
||||
return $this->_auth;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set ACL adapter
|
||||
*
|
||||
@ -180,7 +180,7 @@ class Zend_Amf_Server implements Zend_Server_Interface
|
||||
{
|
||||
return $this->_acl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set production flag
|
||||
*
|
||||
@ -225,8 +225,8 @@ class Zend_Amf_Server implements Zend_Server_Interface
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the ACL allows accessing the function or method
|
||||
*
|
||||
* Check if the ACL allows accessing the function or method
|
||||
*
|
||||
* @param string|object $object Object or class being accessed
|
||||
* @param string $function Function or method being acessed
|
||||
* @return unknown_type
|
||||
@ -239,7 +239,7 @@ class Zend_Amf_Server implements Zend_Server_Interface
|
||||
if($object) {
|
||||
$class = is_object($object)?get_class($object):$object;
|
||||
if(!$this->_acl->has($class)) {
|
||||
require_once 'Zend/Acl/Resource.php';
|
||||
require_once 'Zend/Acl/Resource.php';
|
||||
$this->_acl->add(new Zend_Acl_Resource($class));
|
||||
}
|
||||
$call = array($object, "initAcl");
|
||||
@ -250,15 +250,15 @@ class Zend_Amf_Server implements Zend_Server_Interface
|
||||
} else {
|
||||
$class = null;
|
||||
}
|
||||
|
||||
|
||||
$auth = Zend_Auth::getInstance();
|
||||
if($auth->hasIdentity()) {
|
||||
$role = $auth->getIdentity()->role;
|
||||
} else {
|
||||
if($this->_acl->hasRole(Zend_Amf_Constants::GUEST_ROLE)) {
|
||||
if($this->_acl->hasRole(Zend_Amf_Constants::GUEST_ROLE)) {
|
||||
$role = Zend_Amf_Constants::GUEST_ROLE;
|
||||
} else {
|
||||
require_once 'Zend/Amf/Server/Exception.php';
|
||||
require_once 'Zend/Amf/Server/Exception.php';
|
||||
throw new Zend_Amf_Server_Exception("Unauthenticated access not allowed");
|
||||
}
|
||||
}
|
||||
@ -269,7 +269,7 @@ class Zend_Amf_Server implements Zend_Server_Interface
|
||||
throw new Zend_Amf_Server_Exception("Access not allowed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get PluginLoader for the Server
|
||||
*
|
||||
@ -277,13 +277,13 @@ class Zend_Amf_Server implements Zend_Server_Interface
|
||||
*/
|
||||
protected function getLoader()
|
||||
{
|
||||
if(empty($this->_loader)) {
|
||||
require_once 'Zend/Loader/PluginLoader.php';
|
||||
$this->_loader = new Zend_Loader_PluginLoader();
|
||||
}
|
||||
return $this->_loader;
|
||||
if(empty($this->_loader)) {
|
||||
require_once 'Zend/Loader/PluginLoader.php';
|
||||
$this->_loader = new Zend_Loader_PluginLoader();
|
||||
}
|
||||
return $this->_loader;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads a remote class or method and executes the function and returns
|
||||
* the result
|
||||
@ -295,23 +295,23 @@ class Zend_Amf_Server implements Zend_Server_Interface
|
||||
*/
|
||||
protected function _dispatch($method, $params = null, $source = null)
|
||||
{
|
||||
if($source) {
|
||||
if(($mapped = Zend_Amf_Parse_TypeLoader::getMappedClassName($source)) !== false) {
|
||||
$source = $mapped;
|
||||
}
|
||||
}
|
||||
if($source) {
|
||||
if(($mapped = Zend_Amf_Parse_TypeLoader::getMappedClassName($source)) !== false) {
|
||||
$source = $mapped;
|
||||
}
|
||||
}
|
||||
$qualifiedName = empty($source) ? $method : $source.".".$method;
|
||||
|
||||
|
||||
if (!isset($this->_table[$qualifiedName])) {
|
||||
// if source is null a method that was not defined was called.
|
||||
if ($source) {
|
||||
$className = str_replace(".", "_", $source);
|
||||
if(class_exists($className, false) && !isset($this->_classAllowed[$className])) {
|
||||
require_once 'Zend/Amf/Server/Exception.php';
|
||||
$className = str_replace(".", "_", $source);
|
||||
if(class_exists($className, false) && !isset($this->_classAllowed[$className])) {
|
||||
require_once 'Zend/Amf/Server/Exception.php';
|
||||
throw new Zend_Amf_Server_Exception('Can not call "' . $className . '" - use setClass()');
|
||||
}
|
||||
}
|
||||
try {
|
||||
$this->getLoader()->load($className);
|
||||
$this->getLoader()->load($className);
|
||||
} catch (Exception $e) {
|
||||
require_once 'Zend/Amf/Server/Exception.php';
|
||||
throw new Zend_Amf_Server_Exception('Class "' . $className . '" does not exist: '.$e->getMessage());
|
||||
@ -326,7 +326,7 @@ class Zend_Amf_Server implements Zend_Server_Interface
|
||||
|
||||
$info = $this->_table[$qualifiedName];
|
||||
$argv = $info->getInvokeArguments();
|
||||
|
||||
|
||||
if (0 < count($argv)) {
|
||||
$params = array_merge($params, $argv);
|
||||
}
|
||||
@ -377,13 +377,13 @@ class Zend_Amf_Server implements Zend_Server_Interface
|
||||
require_once 'Zend/Amf/Value/Messaging/AcknowledgeMessage.php';
|
||||
switch($message->operation) {
|
||||
case Zend_Amf_Value_Messaging_CommandMessage::DISCONNECT_OPERATION :
|
||||
case Zend_Amf_Value_Messaging_CommandMessage::CLIENT_PING_OPERATION :
|
||||
case Zend_Amf_Value_Messaging_CommandMessage::CLIENT_PING_OPERATION :
|
||||
$return = new Zend_Amf_Value_Messaging_AcknowledgeMessage($message);
|
||||
break;
|
||||
case Zend_Amf_Value_Messaging_CommandMessage::LOGIN_OPERATION :
|
||||
$data = explode(':', base64_decode($message->body));
|
||||
$userid = $data[0];
|
||||
$password = isset($data[1])?$data[1]:"";
|
||||
$userid = $data[0];
|
||||
$password = isset($data[1])?$data[1]:"";
|
||||
if(empty($userid)) {
|
||||
require_once 'Zend/Amf/Server/Exception.php';
|
||||
throw new Zend_Amf_Server_Exception('Login failed: username not supplied');
|
||||
@ -410,7 +410,7 @@ class Zend_Amf_Server implements Zend_Server_Interface
|
||||
|
||||
/**
|
||||
* Create appropriate error message
|
||||
*
|
||||
*
|
||||
* @param int $objectEncoding Current AMF encoding
|
||||
* @param string $message Message that was being processed when error happened
|
||||
* @param string $description Error description
|
||||
@ -422,55 +422,55 @@ class Zend_Amf_Server implements Zend_Server_Interface
|
||||
protected function _errorMessage($objectEncoding, $message, $description, $detail, $code, $line)
|
||||
{
|
||||
$return = null;
|
||||
switch ($objectEncoding) {
|
||||
case Zend_Amf_Constants::AMF0_OBJECT_ENCODING :
|
||||
return array (
|
||||
'description' => ($this->isProduction ()) ? '' : $description,
|
||||
'detail' => ($this->isProduction ()) ? '' : $detail,
|
||||
'line' => ($this->isProduction ()) ? 0 : $line,
|
||||
'code' => $code
|
||||
);
|
||||
case Zend_Amf_Constants::AMF3_OBJECT_ENCODING :
|
||||
require_once 'Zend/Amf/Value/Messaging/ErrorMessage.php';
|
||||
$return = new Zend_Amf_Value_Messaging_ErrorMessage ( $message );
|
||||
$return->faultString = $this->isProduction () ? '' : $description;
|
||||
$return->faultCode = $code;
|
||||
$return->faultDetail = $this->isProduction () ? '' : $detail;
|
||||
break;
|
||||
}
|
||||
switch ($objectEncoding) {
|
||||
case Zend_Amf_Constants::AMF0_OBJECT_ENCODING :
|
||||
return array (
|
||||
'description' => ($this->isProduction ()) ? '' : $description,
|
||||
'detail' => ($this->isProduction ()) ? '' : $detail,
|
||||
'line' => ($this->isProduction ()) ? 0 : $line,
|
||||
'code' => $code
|
||||
);
|
||||
case Zend_Amf_Constants::AMF3_OBJECT_ENCODING :
|
||||
require_once 'Zend/Amf/Value/Messaging/ErrorMessage.php';
|
||||
$return = new Zend_Amf_Value_Messaging_ErrorMessage ( $message );
|
||||
$return->faultString = $this->isProduction () ? '' : $description;
|
||||
$return->faultCode = $code;
|
||||
$return->faultDetail = $this->isProduction () ? '' : $detail;
|
||||
break;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle AMF authenticaton
|
||||
*
|
||||
* @param string $userid
|
||||
* @param string $password
|
||||
* @return boolean
|
||||
*/
|
||||
protected function _handleAuth( $userid, $password)
|
||||
{
|
||||
if (!$this->_auth) {
|
||||
return true;
|
||||
}
|
||||
$this->_auth->setCredentials($userid, $password);
|
||||
$auth = Zend_Auth::getInstance();
|
||||
$result = $auth->authenticate($this->_auth);
|
||||
if ($result->isValid()) {
|
||||
if (!$this->isSession()) {
|
||||
$this->setSession();
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
// authentication failed, good bye
|
||||
require_once 'Zend/Amf/Server/Exception.php';
|
||||
throw new Zend_Amf_Server_Exception(
|
||||
"Authentication failed: " . join("\n",
|
||||
$result->getMessages()), $result->getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle AMF authenticaton
|
||||
*
|
||||
* @param string $userid
|
||||
* @param string $password
|
||||
* @return boolean
|
||||
*/
|
||||
protected function _handleAuth( $userid, $password)
|
||||
{
|
||||
if (!$this->_auth) {
|
||||
return true;
|
||||
}
|
||||
$this->_auth->setCredentials($userid, $password);
|
||||
$auth = Zend_Auth::getInstance();
|
||||
$result = $auth->authenticate($this->_auth);
|
||||
if ($result->isValid()) {
|
||||
if (!$this->isSession()) {
|
||||
$this->setSession();
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
// authentication failed, good bye
|
||||
require_once 'Zend/Amf/Server/Exception.php';
|
||||
throw new Zend_Amf_Server_Exception(
|
||||
"Authentication failed: " . join("\n",
|
||||
$result->getMessages()), $result->getCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Takes the deserialized AMF request and performs any operations.
|
||||
*
|
||||
@ -490,38 +490,38 @@ class Zend_Amf_Server implements Zend_Server_Interface
|
||||
|
||||
// set reponse encoding
|
||||
$response->setObjectEncoding($objectEncoding);
|
||||
|
||||
|
||||
$responseBody = $request->getAmfBodies();
|
||||
|
||||
$handleAuth = false;
|
||||
if ($this->_auth) {
|
||||
$headers = $request->getAmfHeaders();
|
||||
if (isset($headers[Zend_Amf_Constants::CREDENTIALS_HEADER]) &&
|
||||
isset($headers[Zend_Amf_Constants::CREDENTIALS_HEADER]->userid)) {
|
||||
$handleAuth = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_auth) {
|
||||
$headers = $request->getAmfHeaders();
|
||||
if (isset($headers[Zend_Amf_Constants::CREDENTIALS_HEADER]) &&
|
||||
isset($headers[Zend_Amf_Constants::CREDENTIALS_HEADER]->userid)) {
|
||||
$handleAuth = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Iterate through each of the service calls in the AMF request
|
||||
foreach($responseBody as $body)
|
||||
{
|
||||
try {
|
||||
if ($handleAuth) {
|
||||
if ($this->_handleAuth(
|
||||
$headers[Zend_Amf_Constants::CREDENTIALS_HEADER]->userid,
|
||||
$headers[Zend_Amf_Constants::CREDENTIALS_HEADER]->password)) {
|
||||
// use RequestPersistentHeader to clear credentials
|
||||
$response->addAmfHeader(
|
||||
new Zend_Amf_Value_MessageHeader(
|
||||
Zend_Amf_Constants::PERSISTENT_HEADER,
|
||||
false,
|
||||
new Zend_Amf_Value_MessageHeader(
|
||||
Zend_Amf_Constants::CREDENTIALS_HEADER,
|
||||
false, null)));
|
||||
$handleAuth = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($handleAuth) {
|
||||
if ($this->_handleAuth(
|
||||
$headers[Zend_Amf_Constants::CREDENTIALS_HEADER]->userid,
|
||||
$headers[Zend_Amf_Constants::CREDENTIALS_HEADER]->password)) {
|
||||
// use RequestPersistentHeader to clear credentials
|
||||
$response->addAmfHeader(
|
||||
new Zend_Amf_Value_MessageHeader(
|
||||
Zend_Amf_Constants::PERSISTENT_HEADER,
|
||||
false,
|
||||
new Zend_Amf_Value_MessageHeader(
|
||||
Zend_Amf_Constants::CREDENTIALS_HEADER,
|
||||
false, null)));
|
||||
$handleAuth = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($objectEncoding == Zend_Amf_Constants::AMF0_OBJECT_ENCODING) {
|
||||
// AMF0 Object Encoding
|
||||
$targetURI = $body->getTargetURI();
|
||||
@ -567,7 +567,7 @@ class Zend_Amf_Server implements Zend_Server_Interface
|
||||
}
|
||||
$responseType = Zend_AMF_Constants::RESULT_METHOD;
|
||||
} catch (Exception $e) {
|
||||
$return = $this->_errorMessage($objectEncoding, $message,
|
||||
$return = $this->_errorMessage($objectEncoding, $message,
|
||||
$e->getMessage(), $e->getTraceAsString(),$e->getCode(), $e->getLine());
|
||||
$responseType = Zend_AMF_Constants::STATUS_METHOD;
|
||||
}
|
||||
@ -584,10 +584,10 @@ class Zend_Amf_Server implements Zend_Server_Interface
|
||||
if(!strpos($_SERVER['QUERY_STRING'], $currentID) !== FALSE) {
|
||||
if(strrpos($_SERVER['QUERY_STRING'], "?") !== FALSE) {
|
||||
$joint = "&";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// create a new AMF message header with the session id as a variable.
|
||||
$sessionValue = $joint . $this->_sessionName . "=" . $currentID;
|
||||
$sessionHeader = new Zend_Amf_Value_MessageHeader(Zend_Amf_Constants::URL_APPEND_HEADER, false, $sessionValue);
|
||||
@ -739,11 +739,11 @@ class Zend_Amf_Server implements Zend_Server_Interface
|
||||
}
|
||||
|
||||
// Use the class name as the name space by default.
|
||||
|
||||
|
||||
if ($namespace == '') {
|
||||
$namespace = is_object($class) ? get_class($class) : $class;
|
||||
}
|
||||
|
||||
|
||||
$this->_classAllowed[is_object($class) ? get_class($class) : $class] = true;
|
||||
|
||||
$this->_methods[] = Zend_Server_Reflection::reflectClass($class, $argv, $namespace);
|
||||
@ -793,12 +793,12 @@ class Zend_Amf_Server implements Zend_Server_Interface
|
||||
/**
|
||||
* Creates an array of directories in which services can reside.
|
||||
* TODO: add support for prefixes?
|
||||
*
|
||||
*
|
||||
* @param string $dir
|
||||
*/
|
||||
public function addDirectory($dir)
|
||||
{
|
||||
$this->getLoader()->addPrefixPath("", $dir);
|
||||
$this->getLoader()->addPrefixPath("", $dir);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user