示例#1
0
 /**
  * Handler for all SOAP operations.
  *
  * @param string $operation
  * @param array $arguments
  * @return \stdClass|null
  * @throws WebapiException
  * @throws \LogicException
  * @throws AuthorizationException
  */
 public function __call($operation, $arguments)
 {
     $requestedServices = $this->_request->getRequestedServices();
     $serviceMethodInfo = $this->_apiConfig->getServiceMethodInfo($operation, $requestedServices);
     $serviceClass = $serviceMethodInfo[SoapConfig::KEY_CLASS];
     $serviceMethod = $serviceMethodInfo[SoapConfig::KEY_METHOD];
     // check if the operation is a secure operation & whether the request was made in HTTPS
     if ($serviceMethodInfo[SoapConfig::KEY_IS_SECURE] && !$this->_request->isSecure()) {
         throw new WebapiException(__("Operation allowed only in HTTPS"));
     }
     $isAllowed = false;
     foreach ($serviceMethodInfo[SoapConfig::KEY_ACL_RESOURCES] as $resource) {
         if ($this->_authorization->isAllowed($resource)) {
             $isAllowed = true;
             break;
         }
     }
     if (!$isAllowed) {
         throw new AuthorizationException(__(AuthorizationException::NOT_AUTHORIZED, ['resources' => implode(', ', $serviceMethodInfo[SoapConfig::KEY_ACL_RESOURCES])]));
     }
     $service = $this->_objectManager->get($serviceClass);
     $inputData = $this->_prepareRequestData($serviceClass, $serviceMethod, $arguments);
     $outputData = call_user_func_array([$service, $serviceMethod], $inputData);
     return $this->_prepareResponseData($outputData, $serviceClass, $serviceMethod);
 }
示例#2
0
 /**
  * Handler for all SOAP operations.
  *
  * @param string $operation
  * @param array $arguments
  * @return \stdClass|null
  * @throws WebapiException
  * @throws \LogicException
  * @throws AuthorizationException
  */
 public function __call($operation, $arguments)
 {
     $requestedServices = $this->_request->getRequestedServices();
     $serviceMethodInfo = $this->_apiConfig->getServiceMethodInfo($operation, $requestedServices);
     $serviceClass = $serviceMethodInfo[ServiceMetadata::KEY_CLASS];
     $serviceMethod = $serviceMethodInfo[ServiceMetadata::KEY_METHOD];
     // check if the operation is a secure operation & whether the request was made in HTTPS
     if ($serviceMethodInfo[ServiceMetadata::KEY_IS_SECURE] && !$this->_request->isSecure()) {
         throw new WebapiException(__("Operation allowed only in HTTPS"));
     }
     if (!$this->authorization->isAllowed($serviceMethodInfo[ServiceMetadata::KEY_ACL_RESOURCES])) {
         throw new AuthorizationException(__('Consumer is not authorized to access %resources', ['resources' => implode(', ', $serviceMethodInfo[ServiceMetadata::KEY_ACL_RESOURCES])]));
     }
     $service = $this->_objectManager->get($serviceClass);
     $inputData = $this->_prepareRequestData($serviceClass, $serviceMethod, $arguments);
     $outputData = call_user_func_array([$service, $serviceMethod], $inputData);
     return $this->_prepareResponseData($outputData, $serviceClass, $serviceMethod);
 }
示例#3
0
 /**
  * Retrieve service name from available service info.
  *
  * @param array $serviceInfo
  * @return string
  * @throws \LogicException
  */
 protected function _getSoapServiceName($serviceInfo)
 {
     if (isset($serviceInfo['soap']['service'])) {
         $serviceName = $serviceInfo['soap']['service'];
     } elseif (isset($serviceInfo['serviceInterface'])) {
         $serviceName = $this->_soapConfig->getServiceName($serviceInfo['serviceInterface'], false);
     } else {
         throw new \LogicException("Service name cannot be identified.");
     }
     return $serviceName;
 }
示例#4
0
 /**
  * Generate WSDL file based on requested services (uses cache)
  *
  * @param array $requestedServices
  * @param string $endPointUrl
  * @return string
  * @throws \Exception
  */
 public function generate($requestedServices, $endPointUrl)
 {
     /** Sort requested services by names to prevent caching of the same wsdl file more than once. */
     ksort($requestedServices);
     $cacheId = self::WSDL_CACHE_ID . hash('md5', serialize($requestedServices));
     $cachedWsdlContent = $this->_cache->load($cacheId);
     if ($cachedWsdlContent !== false) {
         return $cachedWsdlContent;
     }
     $services = array();
     foreach ($requestedServices as $serviceName) {
         $services[$serviceName] = $this->_apiConfig->getServiceMetadata($serviceName);
     }
     $wsdlContent = $this->_generate($services, $endPointUrl);
     $this->_cache->save($wsdlContent, $cacheId, array(\Magento\Webapi\Model\Cache\Type::CACHE_TAG));
     return $wsdlContent;
 }
示例#5
0
 /**
  * Generate WSDL file based on requested services (uses cache)
  *
  * @param array $requestedServices
  * @param string $endPointUrl
  * @return string
  * @throws \Exception
  */
 public function generate($requestedServices, $endPointUrl)
 {
     /** Sort requested services by names to prevent caching of the same wsdl file more than once. */
     ksort($requestedServices);
     $currentStore = $this->storeManager->getStore();
     $cacheId = self::WSDL_CACHE_ID . hash('md5', serialize($requestedServices) . $currentStore->getCode());
     $cachedWsdlContent = $this->_cache->load($cacheId);
     if ($cachedWsdlContent !== false) {
         return $cachedWsdlContent;
     }
     $services = [];
     foreach ($requestedServices as $serviceName) {
         $services[$serviceName] = $this->_apiConfig->getServiceMetadata($serviceName);
     }
     $wsdlContent = $this->_generate($services, $endPointUrl);
     $this->_cache->save($wsdlContent, $cacheId, [\Magento\Framework\App\Cache\Type\Webapi::CACHE_TAG]);
     return $wsdlContent;
 }
 public function testGetSoapOperation()
 {
     $expectedResult = 'customerAccountManagementV1Activate';
     $soapOperation = $this->_soapConfig->getSoapOperation('Magento\\Customer\\Api\\AccountManagementInterface', 'activate', 'V1');
     $this->assertEquals($expectedResult, $soapOperation);
 }
示例#7
0
 public function testGetSoapOperation()
 {
     $expectedResult = 'moduleFooV1SomeMethod';
     $soapOperation = $this->_soapConfig->getSoapOperation('Magento\\Framework\\Module\\Service\\FooV1Interface', 'someMethod');
     $this->assertEquals($expectedResult, $soapOperation);
 }
示例#8
0
 public function testGetServiceMetadata()
 {
     $expectedResult = ['methods' => ['activate' => ['method' => 'activate', 'inputRequired' => '', 'isSecure' => '', 'resources' => [['Magento_Customer::manage']]]], 'class' => 'Magento\\Customer\\Api\\AccountManagementInterface'];
     $result = $this->_soapConfig->getServiceMetadata('customerAccountManagementV1');
     $this->assertEquals($expectedResult, $result);
 }