diff --git a/.gitignore b/.gitignore index f92a8e4..f6f563b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea/* library/Vmwarephp/.wsdl_class_map.cache library/Vmwarephp/.clone_ticket.cache -/nbproject/private/ \ No newline at end of file +/nbproject/private/ +*.cache diff --git a/composer.json b/composer.json index 34dc5a5..164ab0c 100644 --- a/composer.json +++ b/composer.json @@ -1,9 +1,9 @@ { - "name":"wirehive/vmwarephp", + "name":"wladikz/vmwarephp", "type":"library", "description":"Vmware vSphere bindings for PHP", "keywords":["vmware", "php", "vsphere", "bindings", "vsphere sdk", "vmware php"], - "homepage":"https://github.com/Wirehive/vmwarephp", + "homepage":"https://github.com/wladikz/vmwarephp", "license":"BSD-3-Clause", "authors":[ { diff --git a/library/Vmwarephp/Extensions/SessionManager.php b/library/Vmwarephp/Extensions/SessionManager.php index 97e273e..c856ace 100644 --- a/library/Vmwarephp/Extensions/SessionManager.php +++ b/library/Vmwarephp/Extensions/SessionManager.php @@ -5,17 +5,25 @@ class SessionManager extends \Vmwarephp\ManagedObject { private $cloneTicketFile; private $session; - - function acquireSession($userName, $password) { - if ($this->session) { - return $this->session; - } - try { - $this->session = $this->acquireSessionUsingCloneTicket(); - } catch (\Exception $e) { - $this->session = $this->acquireANewSession($userName, $password); - } - return $this->session; + private $userName; + + function acquireSession($userName, $password) { + if (empty($this->userName)) { + $this->userName=$userName; + } + if ($this->userName === $userName) { + if ($this->session) { + return $this->session; + } + try { + $this->session = $this->acquireSessionUsingCloneTicket(); + } catch (\Exception $e) { + $this->session = $this->acquireANewSession($userName, $password); + } + } else { + $this->session = $this->acquireANewSession($userName, $password); + } + return $this->session; } private function acquireSessionUsingCloneTicket() { @@ -47,8 +55,21 @@ private function readCloneTicket() { private function getCloneTicketFile() { if (!$this->cloneTicketFile) { - $this->cloneTicketFile = __DIR__ . '/../.clone_ticket.cache'; + $this->cloneTicketFile = __DIR__ . '/../.' . $this->getUserNameForFileName() .'_clone_ticket.cache'; } return $this->cloneTicketFile; } + private function getUserNameForFileName() { + if (empty($this->userName)) { + throw new Exception('UserName is Empty'); + } + if (strpos($this->userName, "\\") !== FALSE) { + $tmpUser= explode("\\", $this->userName)[1]; + } elseif (strpos($this->userName, "@") !== FALSE) { + $tmpUser= explode("@", $this->userName)[0]; + } else { + $tmpUser= $this->userName; + } + return $tmpUser; + } }