Skip to content

Commit

Permalink
Implement certificate connection
Browse files Browse the repository at this point in the history
  • Loading branch information
dfridrich committed Jan 11, 2021
1 parent 427de2c commit b7c8dd8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use Defr\CzechDataBox\DataBox;
$dataBox = new DataBox();
$dataBox->loginWithUsernameAndPassword("login", "heslo", true); // Pro ostrou verzi
$dataBox->loginWithUsernameAndPassword("login", "heslo", false); // Pro verzi s testovacím přístupem
$dataBox->loginWithCertificateAndPassword("certifikat.cer"); // Nebo pouzijte prihlaseni certifikatem

/** @var \Defr\CzechDataBox\DataBoxSimpleApi $simpleApi */
$simpleApi = $dataBox->getSimpleApi();
Expand Down
42 changes: 28 additions & 14 deletions src/DataBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DataBox

/**
* 0 = Heslo
* 1 = Certifikát (zatim neni dodelano).
* 1 = Certifikát
*
* @var int
*/
Expand Down Expand Up @@ -117,6 +117,26 @@ public function loginWithUsernameAndPassword($loginName, $password, $productionM
return $this;
}

/**
* Prihlaseni do DS pomoci certifikatu a hesla (neni povinne).
* Tato medota neudela prihlaseni, ale do instance tridy ulozi potrebne informace.
*
* @param $certificate Cesta k CER souboru
* @param $password
* @param bool|true $productionMode
*
* @return $this
*/
public function loginWithCertificateAndPassword($certFileName, $password, $productionMode = true)
{
$this->productionMode = $productionMode;
$this->loginType = 1;
$this->certFileName = $certFileName;
$this->password = $password;

return $this;
}

/**
* Vyzkousi spojeni s ISDS.
*
Expand Down Expand Up @@ -144,7 +164,7 @@ public function testConnection()
private function getServiceURL($serviceType)
{
$res = 'https://ws1';
if ($this->loginType > 0) {
if (0 !== $this->loginType) {
$res = $res . 'c';
}

Expand All @@ -157,17 +177,11 @@ private function getServiceURL($serviceType)
break;
}

// switch ($this->loginType) {
// case 1:
// $res = $res . 'cert/';
// break;
// case 2:
// $res = $res . 'hspis/';
// break;
// case 2:
// $res = $res . 'certds/';
// break;
// }
switch ($this->loginType) {
case 1:
$res = $res . 'cert/';
break;
}

$res = $res . 'DS/';

Expand Down Expand Up @@ -238,13 +252,13 @@ private function getSoapOptions($service)
{
return [
'login' => $this->loginName,
'local_cert' => $this->certFileName,
'password' => $this->password,
'proxy_host' => $this->proxyAddress,
'proxy_port' => $this->proxyPort,
'proxy_login' => $this->proxyLogin,
'proxy_password' => $this->proxyPassword,
'location' => $this->getServiceURL($service),
// 'cache_wsdl' => WSDL_CACHE_NONE
];
}

Expand Down

0 comments on commit b7c8dd8

Please sign in to comment.