summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2017-03-28 21:31:50 +0200
committerRobin Appelman <robin@icewind.nl>2017-03-28 21:33:07 +0200
commit6991b79d40cf3f92e57fd7a7a9ea49e2404b090d (patch)
tree40c9142186d08236f49a7b9dbd68b1b1f52c13ba
parent205d5586e84b5ea2b71d582e7bd731ed02583088 (diff)
downloadnextcloud-server-6991b79d40cf3f92e57fd7a7a9ea49e2404b090d.tar.gz
nextcloud-server-6991b79d40cf3f92e57fd7a7a9ea49e2404b090d.zip
serialize the token to json instead of using php's serialize
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r--lib/private/Files/ObjectStore/Swift.php46
1 files changed, 36 insertions, 10 deletions
diff --git a/lib/private/Files/ObjectStore/Swift.php b/lib/private/Files/ObjectStore/Swift.php
index cfb5a654e68..38fb96e3af6 100644
--- a/lib/private/Files/ObjectStore/Swift.php
+++ b/lib/private/Files/ObjectStore/Swift.php
@@ -91,15 +91,7 @@ class Swift implements IObjectStore {
return;
}
- $cachedTokenString = $this->memcache->get('token');
- if ($cachedTokenString) {
- $cachedToken = unserialize($cachedTokenString);
- try {
- $this->client->importCredentials($cachedToken);
- } catch (\Exception $e) {
- $this->client->setTokenObject(new Token());
- }
- }
+ $this->importToken();
/** @var Token $token */
$token = $this->client->getTokenObject();
@@ -107,7 +99,7 @@ class Swift implements IObjectStore {
if (!$token || $token->hasExpired()) {
try {
$this->client->authenticate();
- $this->memcache->set('token', serialize($this->client->exportCredentials()));
+ $this->exportToken();
} catch (ClientErrorResponseException $e) {
$statusCode = $e->getResponse()->getStatusCode();
if ($statusCode == 412) {
@@ -163,6 +155,40 @@ class Swift implements IObjectStore {
}
}
+ private function exportToken() {
+ $export = $this->client->exportCredentials();
+ $export['catalog'] = array_map(function (CatalogItem $item) {
+ return [
+ 'name' => $item->getName(),
+ 'endpoints' => $item->getEndpoints(),
+ 'type' => $item->getType()
+ ];
+ }, $export['catalog']->getItems());
+ $this->memcache->set('token', json_encode($export));
+ }
+
+ private function importToken() {
+ $cachedTokenString = $this->memcache->get('token');
+ if ($cachedTokenString) {
+ $cachedToken = json_decode($cachedTokenString, true);
+ $cachedToken['catalog'] = array_map(function (array $item) {
+ $itemClass = new \stdClass();
+ $itemClass->name = $item['name'];
+ $itemClass->endpoints = array_map(function (array $endpoint) {
+ return (object) $endpoint;
+ }, $item['endpoints']);
+ $itemClass->type = $item['type'];
+
+ return $itemClass;
+ }, $cachedToken['catalog']);
+ try {
+ $this->client->importCredentials($cachedToken);
+ } catch (\Exception $e) {
+ $this->client->setTokenObject(new Token());
+ }
+ }
+ }
+
/**
* @param Catalog $catalog
* @param $name