magento-lts
magento-lts copied to clipboard
Access denied when connecting via SOAP
Preconditions (*)
1.OpenMage 20.1.0-rc3 2.PHP 7.4 Apache 2.4
Steps to reproduce (*)
1.Open http://site.loc/api/v2_soap/index in browser 2.
Expected result (*)
1.URL can be opened 2.
Actual result (*)
-
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Body> <SOAP-ENV:Fault> <faultcode>WSDL</faultcode> <faultstring>SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://site.loc/api/v2_soap/index/?wsdl=1' : Premature end of data in tag operation line 374 </faultstring> </SOAP-ENV:Fault> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
I created a new user with and a new role with full access. I checked all the urn and they are all set to the value: urn:OpenMage I add the .htaccess file with this line: php_value default_socket_timeout 6000
I read issue: #1723
I did this test: I created a tes file in php:
<?php
$mage_user = 'user';
$mage_api_key = 'pass';
$mage_url = 'http://site.loc/api/soap/?wsdl';
$ini = ini_set("soap.wsdl_cache_enabled", 0);
$client = new SoapClient( $mage_url ,array('trace' => true));
try {
print_r($client->__getFunctions());
$session_id = $client->login($mage_user, $mage_api_key);
$result = $client->call( $session_id, 'directory_country.list' );
var_dump($result);
} catch (Exception $e) {
var_dump($e->getMessage());
echo "<br>Request Headers:<br>", htmlentities($client->__getLastRequestHeaders()), "<br>";
echo "<br>Request :<br>", htmlentities($client->__getLastRequest()), "<br>";
echo "<br>Response Headers:<br>", htmlentities($client->__getLastResponseHeaders()), "<br>";
echo "<br>Response body:<br>", htmlentities($client->__getLastResponse()), "<br>";
}
result:
Array
(
[0] => anyType call(string $sessionId, string $resourcePath, anyType $args)
[1] => FixedArray multiCall(string $sessionId, FixedArray $calls, anyType $options)
[2] => boolean endSession(string $sessionId)
[3] => string login(string $username, string $apiKey)
[4] => string startSession()
[5] => FixedArray resources(string $sessionId)
[6] => FixedArray globalFaults(string $sessionId)
[7] => FixedArray resourceFaults(string $resourceName, string $sessionId)
)
string(14) "Access denied."
<br>Request Headers:<br>POST /api.php?type=soap HTTP/1.1
Host: site.loc
Connection: Keep-Alive
User-Agent: PHP-SOAP/7.4.33
Content-Type: text/xml; charset=utf-8
SOAPAction: "urn:Action"
Content-Length: 612
<br><br>Request :<br><?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:OpenMage" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:call><sessionId xsi:type="xsd:string">bbdd9f9364a76c80116e5749396b3cd7</sessionId><resourcePath xsi:type="xsd:string">directory_country.list</resourcePath><args xsi:nil="true"/></ns1:call></SOAP-ENV:Body></SOAP-ENV:Envelope>
<br><br>Response Headers:<br>HTTP/1.1 200 OK
Date: Wed, 05 Apr 2023 18:19:47 GMT
Server: Apache/2.4.54 (Debian)
Content-Length: 267
Vary: Accept-Encoding
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: text/xml; charset=UTF-8
<br><br>Response body:<br><?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>2</faultcode><faultstring>Access denied.</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
is it possible that a broken wsdl is cached? https://stackoverflow.com/questions/303488/in-php-how-can-you-clear-a-wsdl-cache
Edit php.ini file, search for soap.wsdl_cache_enabled and set the value to 0 The problem occurs
Access denied is a generic error and there are multiple cases where it would get thrown. Do you have logging enabled? If so check var/log/exception.log
for the full stack trace.
In /var/log/exception.log I don't have any API related errors. I have an error two days ago.
Try updating the line below to add the full error message: https://github.com/OpenMage/magento-lts/blob/6851e17f5f74f82241762b8f1c0779e6f0d54b51/app/code/core/Mage/Api/Model/Server/Handler/Abstract.php#L214
- return $this->_fault('access_denied');
+ return $this->_fault('access_denied', $e->getMessage());
I have inserted several points for the logs. Access Denied occurs on line 259.
I modified like this: ` if (!isset($resources->$resourceName->public) && isset($resources->$resourceName->acl) && !$this->_isAllowed((string)$resources->$resourceName->acl) ) { Mage::log(' Ent 2', null, 'error.log', true); Mage::log((string)$resources->$resourceName, null, 'error.log', true) Mage::log((string)$resources->$resourceName->public, null, 'error.log', true); Mage::log((string)$resources->$resourceName->acl, null, 'error.log', true); return $this->_fault('access_denied'); }
The content of error.log is:`
`2023-04-06T18:00:46+00:00 DEBUG (7): Ent 2
2023-04-06T18:00:46+00:00 DEBUG (7):
2023-04-06T18:00:46+00:00 DEBUG (7):
`
Is it correct that $resources->$resourceName is empty? And why does $resources->$resourceName->acl have a value of directory/country?
I tried now in roles to put ALL and it works. Custom throws me an error
Following steps to reproduce, I got this error:
PHP Fatal error: SOAP-ERROR: Parsing WSDL: Unexpected WSDL element <schema> in /vendor/shardj/zf1-future/library/Zend/Soap/Server.php on line 814'