Commit 10a9ac47 authored by Thomas Löffler's avatar Thomas Löffler
Browse files

Adds possibility to use HTTP auth for SOAP requests

parent 82f2078c
Pipeline #1824 passed with stages
in 3 minutes and 35 seconds
...@@ -118,7 +118,7 @@ abstract class AbstractTerBasedController extends \T3o\TerFe2\Controller\Abstrac ...@@ -118,7 +118,7 @@ abstract class AbstractTerBasedController extends \T3o\TerFe2\Controller\Abstrac
// Create connection // Create connection
$wsdl = $this->terSettings['wsdl']; $wsdl = $this->terSettings['wsdl'];
return $this->objectManager->get(\T3o\TerFe2\Service\Ter::class, $wsdl, $this->terAccount['username'], $this->terAccount['password']); return $this->objectManager->get(\T3o\TerFe2\Service\Ter::class, $wsdl, $this->terAccount['username'], $this->terAccount['password'], $this->terAccount['httpAuth']);
} }
} }
...@@ -70,8 +70,10 @@ class SoapProvider extends \T3o\TerFe2\Provider\AbstractProvider ...@@ -70,8 +70,10 @@ class SoapProvider extends \T3o\TerFe2\Provider\AbstractProvider
$username = (empty($this->configuration['username']) ? $this->configuration['username'] : ''); $username = (empty($this->configuration['username']) ? $this->configuration['username'] : '');
$password = (empty($this->configuration['password']) ? $this->configuration['password'] : ''); $password = (empty($this->configuration['password']) ? $this->configuration['password'] : '');
$httpAuth['login'] = $this->configuration['httpAuth']['login'] ?: '';
$httpAuth['password'] = $this->configuration['httpAuth']['password'] ?: '';
$this->soapService = $this->objectManager->get(\T3o\TerFe2\Service\Soap::class); $this->soapService = $this->objectManager->get(\T3o\TerFe2\Service\Soap::class);
$this->soapService->connect($this->configuration['wsdlUrl'], $username, $password); $this->soapService->connect($this->configuration['wsdlUrl'], $username, $password, $httpAuth);
// Set getExtensionsFunc // Set getExtensionsFunc
if (!empty($this->configuration['getExtensionsFunc'])) { if (!empty($this->configuration['getExtensionsFunc'])) {
......
...@@ -41,6 +41,10 @@ class Soap implements \TYPO3\CMS\Core\SingletonInterface ...@@ -41,6 +41,10 @@ class Soap implements \TYPO3\CMS\Core\SingletonInterface
*/ */
protected $authenticationHeader; protected $authenticationHeader;
/**
* @var array
*/
protected $httpAuth = [];
protected protected
$wsdlUrl, $wsdlUrl,
...@@ -55,10 +59,11 @@ class Soap implements \TYPO3\CMS\Core\SingletonInterface ...@@ -55,10 +59,11 @@ class Soap implements \TYPO3\CMS\Core\SingletonInterface
* @param string $username Login with this username * @param string $username Login with this username
* @param string $password Login with this password * @param string $password Login with this password
* @param boolean $returnExceptions Return exception in case of errors * @param boolean $returnExceptions Return exception in case of errors
* @param array $httpAuth HTTP Authentication if needed
* @return \SoapClient * @return \SoapClient
* @throws \Exception * @throws \Exception
*/ */
public function connect($wsdlUrl, $username = '', $password = '', $returnExceptions = FALSE) public function connect($wsdlUrl, $username = '', $password = '', $returnExceptions = FALSE, array $httpAuth = [])
{ {
if (empty($wsdlUrl)) { if (empty($wsdlUrl)) {
...@@ -73,6 +78,7 @@ class Soap implements \TYPO3\CMS\Core\SingletonInterface ...@@ -73,6 +78,7 @@ class Soap implements \TYPO3\CMS\Core\SingletonInterface
$this->username = $username; $this->username = $username;
$this->password = $password; $this->password = $password;
$this->returnExceptions = $returnExceptions; $this->returnExceptions = $returnExceptions;
$this->httpAuth = $httpAuth;
return $this->resetConnection(); return $this->resetConnection();
} }
...@@ -93,12 +99,21 @@ class Soap implements \TYPO3\CMS\Core\SingletonInterface ...@@ -93,12 +99,21 @@ class Soap implements \TYPO3\CMS\Core\SingletonInterface
public function resetConnection() public function resetConnection()
{ {
// Create connection // Create connection
$arrContextOptions = stream_context_create([
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
]);
echo file_get_contents($this->wsdlUrl, false, $arrContextOptions);
$this->soapConnection = new \SoapClient($this->wsdlUrl, array( $this->soapConnection = new \SoapClient($this->wsdlUrl, array(
'trace' => 1, 'trace' => 1,
'exceptions' => (bool)$this->returnExceptions, 'exceptions' => (bool)$this->returnExceptions,
'encoding' => 'UTF-8', 'encoding' => 'UTF-8',
'soap_version' => SOAP_1_2, 'soap_version' => SOAP_1_2,
'cache_wsdl' => WSDL_CACHE_NONE, 'cache_wsdl' => WSDL_CACHE_NONE,
'login' => $this->httpAuth['login'] ?: '',
'password' => $this->httpAuth['password'] ?: ''
)); ));
// Get authentication header // Get authentication header
...@@ -167,13 +182,6 @@ class Soap implements \TYPO3\CMS\Core\SingletonInterface ...@@ -167,13 +182,6 @@ class Soap implements \TYPO3\CMS\Core\SingletonInterface
public function __call($methodName, array $params = array()) public function __call($methodName, array $params = array())
{ {
$this->resetConnection();
// // Check for existing connection
// if (empty($this->soapConnection)) {
// throw new \Exception('Create SOAP connection first');
// }
// Call given method // Call given method
$response = $this->soapConnection->__soapCall( $response = $this->soapConnection->__soapCall(
$methodName, $methodName,
......
...@@ -55,9 +55,13 @@ class Ter ...@@ -55,9 +55,13 @@ class Ter
/** /**
* Load TER connection * Load TER connection
* *
* @param string $wsdlUrl
* @param string $username
* @param string $password
* @param array $httpAuth
* @return void * @return void
*/ */
public function __construct($wsdlUrl, $username, $password) public function __construct($wsdlUrl, $username, $password, array $httpAuth = [])
{ {
$this->wsdlUrl = $wsdlUrl; $this->wsdlUrl = $wsdlUrl;
$this->userData = array( $this->userData = array(
...@@ -66,7 +70,7 @@ class Ter ...@@ -66,7 +70,7 @@ class Ter
); );
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class); $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
$this->soapService = $objectManager->get(\T3o\TerFe2\Service\Soap::class); $this->soapService = $objectManager->get(\T3o\TerFe2\Service\Soap::class);
$this->soapService->connect($this->wsdlUrl, '', '', TRUE); $this->soapService->connect($this->wsdlUrl, '', '', TRUE, $httpAuth);
} }
......
...@@ -51,6 +51,14 @@ plugin.tx_terfe2 { ...@@ -51,6 +51,14 @@ plugin.tx_terfe2 {
# cat=TER Frontend/settings/2020; type=string; label=TER Password: Password to connect TER server # cat=TER Frontend/settings/2020; type=string; label=TER Password: Password to connect TER server
password = password =
httpAuth {
# cat=TER Frontend/settings/2030; type=string; label=HTTP Auth login: Login for HTTP Auth
login =
# cat=TER Frontend/settings/2040; type=string; label=HTTP Auth password: Password for HTTP Auth
password =
}
} }
smallImage { smallImage {
......
...@@ -24,6 +24,10 @@ plugin.tx_terfe2 { ...@@ -24,6 +24,10 @@ plugin.tx_terfe2 {
wsdl = {$plugin.tx_terfe2.settings.terConnection.wsdl} wsdl = {$plugin.tx_terfe2.settings.terConnection.wsdl}
username = {$plugin.tx_terfe2.settings.terConnection.username} username = {$plugin.tx_terfe2.settings.terConnection.username}
password = {$plugin.tx_terfe2.settings.terConnection.password} password = {$plugin.tx_terfe2.settings.terConnection.password}
httpAuth {
login = {$plugin.tx_terfe2.settings.terConnection.httpAuth.login}
password = {$plugin.tx_terfe2.settings.terConnection.httpAuth.password}
}
} }
smallImage { smallImage {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment