diff --git a/src/Jaspersoft/Client/Client.php b/src/Jaspersoft/Client/Client.php index 94759eb..9e1c57d 100644 --- a/src/Jaspersoft/Client/Client.php +++ b/src/Jaspersoft/Client/Client.php @@ -21,6 +21,7 @@ class Client protected $username; protected $password; protected $orgId; + protected $authToken; protected $repositoryService; protected $userService; protected $organizationService; @@ -36,12 +37,13 @@ class Client protected $logCollectorService; protected $serverService; - public function __construct($serverUrl, $username, $password, $orgId = null) + public function __construct($serverUrl, $username, $password, $orgId = null, $authToken = null) { $this->serverUrl = $serverUrl; $this->username = $username; $this->password = $password; $this->orgId = $orgId; + $this->authToken = $authToken; $this->restReq = new RESTRequest(); if (!empty($this->orgId)) { @@ -51,6 +53,10 @@ public function __construct($serverUrl, $username, $password, $orgId = null) } $this->restReq->setPassword($this->password); $this->restUrl2 = $this->serverUrl . BASE_REST2_URL; + if($authToken !== null) + { + $this->restReq->setAuthToken($authToken); + } } public function repositoryService() @@ -173,6 +179,11 @@ public function serverService() return $this->serverService; } + public function setAuthToken($token) + { + $this->authToken = $token; + $this->restReq->setAuthToken($token); + } /** * Set the amount of time cURL is permitted to wait for a response to a request before timing out. diff --git a/src/Jaspersoft/Dto/Report/InputControl.php b/src/Jaspersoft/Dto/Report/InputControl.php index ce4717a..68902a4 100644 --- a/src/Jaspersoft/Dto/Report/InputControl.php +++ b/src/Jaspersoft/Dto/Report/InputControl.php @@ -45,14 +45,16 @@ public static function createFromJSON($json) { $data_array = json_decode($json, true); $result = array(); - foreach($data_array['inputControlState'] as $k) { - $temp = @new self($k['uri'], $k['id'], $k['value'], $k['error']); - if (!empty($k['options'])) { - foreach ($k['options'] as $o) { - @$temp->addOption($o['label'], $o['value'], $o['selected']); + if(isset($data_array['inputControlState'])) { + foreach ($data_array['inputControlState'] as $k) { + $temp = @new self($k['uri'], $k['id'], $k['value'], $k['error']); + if (!empty($k['options'])) { + foreach ($k['options'] as $o) { + @$temp->addOption($o['label'], $o['value'], $o['selected']); + } } + $result[] = $temp; } - $result[] = $temp; } return $result; } diff --git a/src/Jaspersoft/Tool/RESTRequest.php b/src/Jaspersoft/Tool/RESTRequest.php index 2ad536a..47e8c72 100644 --- a/src/Jaspersoft/Tool/RESTRequest.php +++ b/src/Jaspersoft/Tool/RESTRequest.php @@ -37,6 +37,7 @@ public function __construct ($url = null, $verb = 'GET', $request_body = null) $this->curl_timeout = 30; $this->curl_handle = curl_init(); $this->curl_cookiejar = null; + $this->auth_token = null; if ($this->request_body !== null) { @@ -284,6 +285,8 @@ protected function setCurlOpts (&$curlHandle) $this->headers[] = "Content-Type: " . $this->content_type; if (!empty($this->accept_type)) $this->headers[] = "Accept: " . $this->accept_type; + if ($this->auth_token !== null) + $this->headers[] = "pp: " . $this->auth_token; if (!empty($this->headers)) curl_setopt($curlHandle, CURLOPT_HTTPHEADER, $this->headers); } @@ -292,7 +295,8 @@ protected function setAuth (&$curlHandle) { if ($this->username !== null && $this->password !== null) { - if (empty($this->curl_cookiejar)) { + curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array('Authorization')); + if (empty($this->curl_cookiejar)) { $this->curl_cookiejar = tempnam(sys_get_temp_dir(), "jrscookies_"); } curl_setopt($curlHandle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); @@ -376,6 +380,10 @@ public function setVerb ($verb) { $this->verb = $verb; } + public function setAuthToken ($auth_token) + { + $this->auth_token = $auth_token; + } public function closeCurlHandle($close_cookies = false) { if (is_resource($this->curl_handle)) {