Skip to content
This repository has been archived by the owner on Jan 10, 2019. It is now read-only.

Multi-Session with different users support #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea/*
library/Vmwarephp/.wsdl_class_map.cache
library/Vmwarephp/.clone_ticket.cache
/nbproject/private/
/nbproject/private/
*.cache
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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":[
{
Expand Down
45 changes: 33 additions & 12 deletions library/Vmwarephp/Extensions/SessionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
}