@@ -32,17 +32,17 @@ |
||
| 32 | 32 | |
| 33 | 33 | class LimitFilter implements XmlDeserializable { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @param Reader $reader |
|
| 37 | - * @throws BadRequest |
|
| 38 | - * @return int |
|
| 39 | - */ |
|
| 40 | - public static function xmlDeserialize(Reader $reader) { |
|
| 41 | - $value = $reader->parseInnerTree(); |
|
| 42 | - if (!is_int($value) && !is_string($value)) { |
|
| 43 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}limit has illegal value'); |
|
| 44 | - } |
|
| 35 | + /** |
|
| 36 | + * @param Reader $reader |
|
| 37 | + * @throws BadRequest |
|
| 38 | + * @return int |
|
| 39 | + */ |
|
| 40 | + public static function xmlDeserialize(Reader $reader) { |
|
| 41 | + $value = $reader->parseInnerTree(); |
|
| 42 | + if (!is_int($value) && !is_string($value)) { |
|
| 43 | + throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}limit has illegal value'); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - return (int)$value; |
|
| 47 | - } |
|
| 46 | + return (int)$value; |
|
| 47 | + } |
|
| 48 | 48 | } |
@@ -40,9 +40,9 @@ |
||
| 40 | 40 | public static function xmlDeserialize(Reader $reader) { |
| 41 | 41 | $value = $reader->parseInnerTree(); |
| 42 | 42 | if (!is_int($value) && !is_string($value)) { |
| 43 | - throw new BadRequest('The {' . SearchPlugin::NS_Nextcloud . '}limit has illegal value'); |
|
| 43 | + throw new BadRequest('The {'.SearchPlugin::NS_Nextcloud.'}limit has illegal value'); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - return (int)$value; |
|
| 46 | + return (int) $value; |
|
| 47 | 47 | } |
| 48 | 48 | } |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | use OCP\WorkflowEngine\IManager; |
| 29 | 29 | |
| 30 | 30 | class Admin extends ASettings { |
| 31 | - public function getScope(): int { |
|
| 32 | - return IManager::SCOPE_ADMIN; |
|
| 33 | - } |
|
| 31 | + public function getScope(): int { |
|
| 32 | + return IManager::SCOPE_ADMIN; |
|
| 33 | + } |
|
| 34 | 34 | } |
@@ -32,17 +32,17 @@ |
||
| 32 | 32 | * Amazon S3 access key authentication |
| 33 | 33 | */ |
| 34 | 34 | class AccessKey extends AuthMechanism { |
| 35 | - public const SCHEME_AMAZONS3_ACCESSKEY = 'amazons3_accesskey'; |
|
| 35 | + public const SCHEME_AMAZONS3_ACCESSKEY = 'amazons3_accesskey'; |
|
| 36 | 36 | |
| 37 | - public function __construct(IL10N $l) { |
|
| 38 | - $this |
|
| 39 | - ->setIdentifier('amazons3::accesskey') |
|
| 40 | - ->setScheme(self::SCHEME_AMAZONS3_ACCESSKEY) |
|
| 41 | - ->setText($l->t('Access key')) |
|
| 42 | - ->addParameters([ |
|
| 43 | - new DefinitionParameter('key', $l->t('Access key')), |
|
| 44 | - (new DefinitionParameter('secret', $l->t('Secret key'))) |
|
| 45 | - ->setType(DefinitionParameter::VALUE_PASSWORD), |
|
| 46 | - ]); |
|
| 47 | - } |
|
| 37 | + public function __construct(IL10N $l) { |
|
| 38 | + $this |
|
| 39 | + ->setIdentifier('amazons3::accesskey') |
|
| 40 | + ->setScheme(self::SCHEME_AMAZONS3_ACCESSKEY) |
|
| 41 | + ->setText($l->t('Access key')) |
|
| 42 | + ->addParameters([ |
|
| 43 | + new DefinitionParameter('key', $l->t('Access key')), |
|
| 44 | + (new DefinitionParameter('secret', $l->t('Secret key'))) |
|
| 45 | + ->setType(DefinitionParameter::VALUE_PASSWORD), |
|
| 46 | + ]); |
|
| 47 | + } |
|
| 48 | 48 | } |
@@ -30,11 +30,11 @@ |
||
| 30 | 30 | use Sabre\DAV\IFile; |
| 31 | 31 | |
| 32 | 32 | abstract class AbstractTrashFile extends AbstractTrash implements IFile, ITrash { |
| 33 | - public function put($data) { |
|
| 34 | - throw new Forbidden(); |
|
| 35 | - } |
|
| 33 | + public function put($data) { |
|
| 34 | + throw new Forbidden(); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - public function setName($name) { |
|
| 38 | - throw new Forbidden(); |
|
| 39 | - } |
|
| 37 | + public function setName($name) { |
|
| 38 | + throw new Forbidden(); |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -60,7 +60,7 @@ |
||
| 60 | 60 | $ns = '{http://nextcloud.com/ns}'; |
| 61 | 61 | |
| 62 | 62 | if ($node instanceof Card) { |
| 63 | - $propFind->handle($ns . 'has-photo', function () use ($node) { |
|
| 63 | + $propFind->handle($ns.'has-photo', function() use ($node) { |
|
| 64 | 64 | $vcard = Reader::read($node->get()); |
| 65 | 65 | return $vcard instanceof VCard |
| 66 | 66 | && $vcard->PHOTO |
@@ -18,69 +18,69 @@ |
||
| 18 | 18 | |
| 19 | 19 | class HasPhotoPlugin extends ServerPlugin { |
| 20 | 20 | |
| 21 | - /** @var Server */ |
|
| 22 | - protected $server; |
|
| 21 | + /** @var Server */ |
|
| 22 | + protected $server; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Initializes the plugin and registers event handlers |
|
| 26 | - * |
|
| 27 | - * @param Server $server |
|
| 28 | - * @return void |
|
| 29 | - */ |
|
| 30 | - public function initialize(Server $server) { |
|
| 31 | - $server->on('propFind', [$this, 'propFind']); |
|
| 32 | - } |
|
| 24 | + /** |
|
| 25 | + * Initializes the plugin and registers event handlers |
|
| 26 | + * |
|
| 27 | + * @param Server $server |
|
| 28 | + * @return void |
|
| 29 | + */ |
|
| 30 | + public function initialize(Server $server) { |
|
| 31 | + $server->on('propFind', [$this, 'propFind']); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Adds all CardDAV-specific properties |
|
| 36 | - * |
|
| 37 | - * @param PropFind $propFind |
|
| 38 | - * @param INode $node |
|
| 39 | - * @return void |
|
| 40 | - */ |
|
| 41 | - public function propFind(PropFind $propFind, INode $node) { |
|
| 42 | - $ns = '{http://nextcloud.com/ns}'; |
|
| 34 | + /** |
|
| 35 | + * Adds all CardDAV-specific properties |
|
| 36 | + * |
|
| 37 | + * @param PropFind $propFind |
|
| 38 | + * @param INode $node |
|
| 39 | + * @return void |
|
| 40 | + */ |
|
| 41 | + public function propFind(PropFind $propFind, INode $node) { |
|
| 42 | + $ns = '{http://nextcloud.com/ns}'; |
|
| 43 | 43 | |
| 44 | - if ($node instanceof Card) { |
|
| 45 | - $propFind->handle($ns . 'has-photo', function () use ($node) { |
|
| 46 | - $vcard = Reader::read($node->get()); |
|
| 47 | - return $vcard instanceof VCard |
|
| 48 | - && $vcard->PHOTO |
|
| 49 | - // Either the PHOTO is a url (doesn't start with data:) or the mimetype has to start with image/ |
|
| 50 | - && (!str_starts_with($vcard->PHOTO->getValue(), 'data:') |
|
| 51 | - || str_starts_with($vcard->PHOTO->getValue(), 'data:image/')) |
|
| 52 | - ; |
|
| 53 | - }); |
|
| 54 | - } |
|
| 55 | - } |
|
| 44 | + if ($node instanceof Card) { |
|
| 45 | + $propFind->handle($ns . 'has-photo', function () use ($node) { |
|
| 46 | + $vcard = Reader::read($node->get()); |
|
| 47 | + return $vcard instanceof VCard |
|
| 48 | + && $vcard->PHOTO |
|
| 49 | + // Either the PHOTO is a url (doesn't start with data:) or the mimetype has to start with image/ |
|
| 50 | + && (!str_starts_with($vcard->PHOTO->getValue(), 'data:') |
|
| 51 | + || str_starts_with($vcard->PHOTO->getValue(), 'data:image/')) |
|
| 52 | + ; |
|
| 53 | + }); |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Returns a plugin name. |
|
| 59 | - * |
|
| 60 | - * Using this name other plugins will be able to access other plugins |
|
| 61 | - * using \Sabre\DAV\Server::getPlugin |
|
| 62 | - * |
|
| 63 | - * @return string |
|
| 64 | - */ |
|
| 65 | - public function getPluginName() { |
|
| 66 | - return 'vcard-has-photo'; |
|
| 67 | - } |
|
| 57 | + /** |
|
| 58 | + * Returns a plugin name. |
|
| 59 | + * |
|
| 60 | + * Using this name other plugins will be able to access other plugins |
|
| 61 | + * using \Sabre\DAV\Server::getPlugin |
|
| 62 | + * |
|
| 63 | + * @return string |
|
| 64 | + */ |
|
| 65 | + public function getPluginName() { |
|
| 66 | + return 'vcard-has-photo'; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Returns a bunch of meta-data about the plugin. |
|
| 71 | - * |
|
| 72 | - * Providing this information is optional, and is mainly displayed by the |
|
| 73 | - * Browser plugin. |
|
| 74 | - * |
|
| 75 | - * The description key in the returned array may contain html and will not |
|
| 76 | - * be sanitized. |
|
| 77 | - * |
|
| 78 | - * @return array |
|
| 79 | - */ |
|
| 80 | - public function getPluginInfo() { |
|
| 81 | - return [ |
|
| 82 | - 'name' => $this->getPluginName(), |
|
| 83 | - 'description' => 'Return a boolean stating if the vcard have a photo property set or not.' |
|
| 84 | - ]; |
|
| 85 | - } |
|
| 69 | + /** |
|
| 70 | + * Returns a bunch of meta-data about the plugin. |
|
| 71 | + * |
|
| 72 | + * Providing this information is optional, and is mainly displayed by the |
|
| 73 | + * Browser plugin. |
|
| 74 | + * |
|
| 75 | + * The description key in the returned array may contain html and will not |
|
| 76 | + * be sanitized. |
|
| 77 | + * |
|
| 78 | + * @return array |
|
| 79 | + */ |
|
| 80 | + public function getPluginInfo() { |
|
| 81 | + return [ |
|
| 82 | + 'name' => $this->getPluginName(), |
|
| 83 | + 'description' => 'Return a boolean stating if the vcard have a photo property set or not.' |
|
| 84 | + ]; |
|
| 85 | + } |
|
| 86 | 86 | } |
@@ -35,6 +35,6 @@ |
||
| 35 | 35 | */ |
| 36 | 36 | protected function getTableName(bool $includePrefix = true) { |
| 37 | 37 | $p = $includePrefix ? '*PREFIX*' : ''; |
| 38 | - return $p . 'ldap_user_mapping'; |
|
| 38 | + return $p.'ldap_user_mapping'; |
|
| 39 | 39 | } |
| 40 | 40 | } |
@@ -22,48 +22,48 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class UserMapping extends AbstractMapping { |
| 24 | 24 | |
| 25 | - protected const PROV_API_REGEX = '/\/ocs\/v[1-9].php\/cloud\/(groups|users)/'; |
|
| 25 | + protected const PROV_API_REGEX = '/\/ocs\/v[1-9].php\/cloud\/(groups|users)/'; |
|
| 26 | 26 | |
| 27 | - public function __construct( |
|
| 28 | - IDBConnection $dbc, |
|
| 29 | - ICacheFactory $cacheFactory, |
|
| 30 | - IAppConfig $config, |
|
| 31 | - bool $isCLI, |
|
| 32 | - private IAssertion $assertion, |
|
| 33 | - ) { |
|
| 34 | - parent::__construct($dbc, $cacheFactory, $config, $isCLI); |
|
| 35 | - } |
|
| 27 | + public function __construct( |
|
| 28 | + IDBConnection $dbc, |
|
| 29 | + ICacheFactory $cacheFactory, |
|
| 30 | + IAppConfig $config, |
|
| 31 | + bool $isCLI, |
|
| 32 | + private IAssertion $assertion, |
|
| 33 | + ) { |
|
| 34 | + parent::__construct($dbc, $cacheFactory, $config, $isCLI); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @throws HintException |
|
| 39 | - */ |
|
| 40 | - public function map($fdn, $name, $uuid): bool { |
|
| 41 | - try { |
|
| 42 | - $this->assertion->createUserIsLegit(); |
|
| 43 | - } catch (HintException $e) { |
|
| 44 | - static $isProvisioningApi = null; |
|
| 37 | + /** |
|
| 38 | + * @throws HintException |
|
| 39 | + */ |
|
| 40 | + public function map($fdn, $name, $uuid): bool { |
|
| 41 | + try { |
|
| 42 | + $this->assertion->createUserIsLegit(); |
|
| 43 | + } catch (HintException $e) { |
|
| 44 | + static $isProvisioningApi = null; |
|
| 45 | 45 | |
| 46 | - if ($isProvisioningApi === null) { |
|
| 47 | - $request = Server::get(IRequest::class); |
|
| 48 | - $isProvisioningApi = \preg_match(self::PROV_API_REGEX, $request->getRequestUri()) === 1; |
|
| 49 | - } |
|
| 50 | - if ($isProvisioningApi) { |
|
| 51 | - // only throw when prov API is being used, since functionality |
|
| 52 | - // should not break for end users (e.g. when sharing). |
|
| 53 | - // On direct API usage, e.g. on users page, this is desired. |
|
| 54 | - throw $e; |
|
| 55 | - } |
|
| 56 | - return false; |
|
| 57 | - } |
|
| 58 | - return parent::map($fdn, $name, $uuid); |
|
| 59 | - } |
|
| 46 | + if ($isProvisioningApi === null) { |
|
| 47 | + $request = Server::get(IRequest::class); |
|
| 48 | + $isProvisioningApi = \preg_match(self::PROV_API_REGEX, $request->getRequestUri()) === 1; |
|
| 49 | + } |
|
| 50 | + if ($isProvisioningApi) { |
|
| 51 | + // only throw when prov API is being used, since functionality |
|
| 52 | + // should not break for end users (e.g. when sharing). |
|
| 53 | + // On direct API usage, e.g. on users page, this is desired. |
|
| 54 | + throw $e; |
|
| 55 | + } |
|
| 56 | + return false; |
|
| 57 | + } |
|
| 58 | + return parent::map($fdn, $name, $uuid); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * returns the DB table name which holds the mappings |
|
| 63 | - * @return string |
|
| 64 | - */ |
|
| 65 | - protected function getTableName(bool $includePrefix = true) { |
|
| 66 | - $p = $includePrefix ? '*PREFIX*' : ''; |
|
| 67 | - return $p . 'ldap_user_mapping'; |
|
| 68 | - } |
|
| 61 | + /** |
|
| 62 | + * returns the DB table name which holds the mappings |
|
| 63 | + * @return string |
|
| 64 | + */ |
|
| 65 | + protected function getTableName(bool $includePrefix = true) { |
|
| 66 | + $p = $includePrefix ? '*PREFIX*' : ''; |
|
| 67 | + return $p . 'ldap_user_mapping'; |
|
| 68 | + } |
|
| 69 | 69 | } |
@@ -29,12 +29,12 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class GroupMapping extends AbstractMapping { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * returns the DB table name which holds the mappings |
|
| 34 | - * @return string |
|
| 35 | - */ |
|
| 36 | - protected function getTableName(bool $includePrefix = true) { |
|
| 37 | - $p = $includePrefix ? '*PREFIX*' : ''; |
|
| 38 | - return $p . 'ldap_group_mapping'; |
|
| 39 | - } |
|
| 32 | + /** |
|
| 33 | + * returns the DB table name which holds the mappings |
|
| 34 | + * @return string |
|
| 35 | + */ |
|
| 36 | + protected function getTableName(bool $includePrefix = true) { |
|
| 37 | + $p = $includePrefix ? '*PREFIX*' : ''; |
|
| 38 | + return $p . 'ldap_group_mapping'; |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -35,6 +35,6 @@ |
||
| 35 | 35 | */ |
| 36 | 36 | protected function getTableName(bool $includePrefix = true) { |
| 37 | 37 | $p = $includePrefix ? '*PREFIX*' : ''; |
| 38 | - return $p . 'ldap_group_mapping'; |
|
| 38 | + return $p.'ldap_group_mapping'; |
|
| 39 | 39 | } |
| 40 | 40 | } |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | * @return string |
| 108 | 108 | */ |
| 109 | 109 | protected function getUserCacheKey($uid) { |
| 110 | - return 'user-' . $uid . '-lastSeenOn'; |
|
| 110 | + return 'user-'.$uid.'-lastSeenOn'; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | * @return string |
| 116 | 116 | */ |
| 117 | 117 | protected function getGroupCacheKey($gid) { |
| 118 | - return 'group-' . $gid . '-lastSeenOn'; |
|
| 118 | + return 'group-'.$gid.'-lastSeenOn'; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | if ($key === null) { |
| 179 | 179 | return $prefix; |
| 180 | 180 | } |
| 181 | - return $prefix . hash('sha256', $key); |
|
| 181 | + return $prefix.hash('sha256', $key); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
@@ -17,191 +17,191 @@ |
||
| 17 | 17 | * @template T |
| 18 | 18 | */ |
| 19 | 19 | abstract class Proxy { |
| 20 | - /** @var array<string,Access> */ |
|
| 21 | - private static array $accesses = []; |
|
| 22 | - private ?bool $isSingleBackend = null; |
|
| 23 | - private ?ICache $cache = null; |
|
| 24 | - |
|
| 25 | - /** @var T[] */ |
|
| 26 | - protected array $backends = []; |
|
| 27 | - /** @var ?T */ |
|
| 28 | - protected $refBackend = null; |
|
| 29 | - |
|
| 30 | - protected bool $isSetUp = false; |
|
| 31 | - |
|
| 32 | - public function __construct( |
|
| 33 | - private Helper $helper, |
|
| 34 | - private ILDAPWrapper $ldap, |
|
| 35 | - private AccessFactory $accessFactory, |
|
| 36 | - ) { |
|
| 37 | - $memcache = Server::get(ICacheFactory::class); |
|
| 38 | - if ($memcache->isAvailable()) { |
|
| 39 | - $this->cache = $memcache->createDistributed(); |
|
| 40 | - } |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - protected function setup(): void { |
|
| 44 | - if ($this->isSetUp) { |
|
| 45 | - return; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - $serverConfigPrefixes = $this->helper->getServerConfigurationPrefixes(true); |
|
| 49 | - foreach ($serverConfigPrefixes as $configPrefix) { |
|
| 50 | - $this->backends[$configPrefix] = $this->newInstance($configPrefix); |
|
| 51 | - |
|
| 52 | - if (is_null($this->refBackend)) { |
|
| 53 | - $this->refBackend = $this->backends[$configPrefix]; |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - $this->isSetUp = true; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @return T |
|
| 62 | - */ |
|
| 63 | - abstract protected function newInstance(string $configPrefix): object; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @return T |
|
| 67 | - */ |
|
| 68 | - public function getBackend(string $configPrefix): object { |
|
| 69 | - $this->setup(); |
|
| 70 | - return $this->backends[$configPrefix]; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - private function addAccess(string $configPrefix): void { |
|
| 74 | - $userMap = Server::get(UserMapping::class); |
|
| 75 | - $groupMap = Server::get(GroupMapping::class); |
|
| 76 | - |
|
| 77 | - $connector = new Connection($this->ldap, $configPrefix); |
|
| 78 | - $access = $this->accessFactory->get($connector); |
|
| 79 | - $access->setUserMapper($userMap); |
|
| 80 | - $access->setGroupMapper($groupMap); |
|
| 81 | - self::$accesses[$configPrefix] = $access; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - protected function getAccess(string $configPrefix): Access { |
|
| 85 | - if (!isset(self::$accesses[$configPrefix])) { |
|
| 86 | - $this->addAccess($configPrefix); |
|
| 87 | - } |
|
| 88 | - return self::$accesses[$configPrefix]; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @param string $uid |
|
| 93 | - * @return string |
|
| 94 | - */ |
|
| 95 | - protected function getUserCacheKey($uid) { |
|
| 96 | - return 'user-' . $uid . '-lastSeenOn'; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @param string $gid |
|
| 101 | - * @return string |
|
| 102 | - */ |
|
| 103 | - protected function getGroupCacheKey($gid) { |
|
| 104 | - return 'group-' . $gid . '-lastSeenOn'; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @param string $id |
|
| 109 | - * @param string $method |
|
| 110 | - * @param array $parameters |
|
| 111 | - * @param bool $passOnWhen |
|
| 112 | - * @return mixed |
|
| 113 | - */ |
|
| 114 | - abstract protected function callOnLastSeenOn($id, $method, $parameters, $passOnWhen); |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @param string $id |
|
| 118 | - * @param string $method |
|
| 119 | - * @param array $parameters |
|
| 120 | - * @return mixed |
|
| 121 | - */ |
|
| 122 | - abstract protected function walkBackends($id, $method, $parameters); |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @param string $id |
|
| 126 | - * @return Access |
|
| 127 | - */ |
|
| 128 | - abstract public function getLDAPAccess($id); |
|
| 129 | - |
|
| 130 | - abstract protected function activeBackends(): int; |
|
| 131 | - |
|
| 132 | - protected function isSingleBackend(): bool { |
|
| 133 | - if ($this->isSingleBackend === null) { |
|
| 134 | - $this->isSingleBackend = $this->activeBackends() === 1; |
|
| 135 | - } |
|
| 136 | - return $this->isSingleBackend; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Takes care of the request to the User backend |
|
| 141 | - * |
|
| 142 | - * @param string $id |
|
| 143 | - * @param string $method string, the method of the user backend that shall be called |
|
| 144 | - * @param array $parameters an array of parameters to be passed |
|
| 145 | - * @param bool $passOnWhen |
|
| 146 | - * @return mixed the result of the specified method |
|
| 147 | - */ |
|
| 148 | - protected function handleRequest($id, $method, $parameters, $passOnWhen = false) { |
|
| 149 | - if (!$this->isSingleBackend()) { |
|
| 150 | - $result = $this->callOnLastSeenOn($id, $method, $parameters, $passOnWhen); |
|
| 151 | - } |
|
| 152 | - if (!isset($result) || $result === $passOnWhen) { |
|
| 153 | - $result = $this->walkBackends($id, $method, $parameters); |
|
| 154 | - } |
|
| 155 | - return $result; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * @param string|null $key |
|
| 160 | - * @return string |
|
| 161 | - */ |
|
| 162 | - private function getCacheKey($key) { |
|
| 163 | - $prefix = 'LDAP-Proxy-'; |
|
| 164 | - if ($key === null) { |
|
| 165 | - return $prefix; |
|
| 166 | - } |
|
| 167 | - return $prefix . hash('sha256', $key); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * @param string $key |
|
| 172 | - * @return mixed|null |
|
| 173 | - */ |
|
| 174 | - public function getFromCache($key) { |
|
| 175 | - if ($this->cache === null) { |
|
| 176 | - return null; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - $key = $this->getCacheKey($key); |
|
| 180 | - $value = $this->cache->get($key); |
|
| 181 | - if ($value === null) { |
|
| 182 | - return null; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - return json_decode(base64_decode($value)); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * @param string $key |
|
| 190 | - * @param mixed $value |
|
| 191 | - */ |
|
| 192 | - public function writeToCache($key, $value) { |
|
| 193 | - if ($this->cache === null) { |
|
| 194 | - return; |
|
| 195 | - } |
|
| 196 | - $key = $this->getCacheKey($key); |
|
| 197 | - $value = base64_encode(json_encode($value)); |
|
| 198 | - $this->cache->set($key, $value, 2592000); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - public function clearCache() { |
|
| 202 | - if ($this->cache === null) { |
|
| 203 | - return; |
|
| 204 | - } |
|
| 205 | - $this->cache->clear($this->getCacheKey(null)); |
|
| 206 | - } |
|
| 20 | + /** @var array<string,Access> */ |
|
| 21 | + private static array $accesses = []; |
|
| 22 | + private ?bool $isSingleBackend = null; |
|
| 23 | + private ?ICache $cache = null; |
|
| 24 | + |
|
| 25 | + /** @var T[] */ |
|
| 26 | + protected array $backends = []; |
|
| 27 | + /** @var ?T */ |
|
| 28 | + protected $refBackend = null; |
|
| 29 | + |
|
| 30 | + protected bool $isSetUp = false; |
|
| 31 | + |
|
| 32 | + public function __construct( |
|
| 33 | + private Helper $helper, |
|
| 34 | + private ILDAPWrapper $ldap, |
|
| 35 | + private AccessFactory $accessFactory, |
|
| 36 | + ) { |
|
| 37 | + $memcache = Server::get(ICacheFactory::class); |
|
| 38 | + if ($memcache->isAvailable()) { |
|
| 39 | + $this->cache = $memcache->createDistributed(); |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + protected function setup(): void { |
|
| 44 | + if ($this->isSetUp) { |
|
| 45 | + return; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + $serverConfigPrefixes = $this->helper->getServerConfigurationPrefixes(true); |
|
| 49 | + foreach ($serverConfigPrefixes as $configPrefix) { |
|
| 50 | + $this->backends[$configPrefix] = $this->newInstance($configPrefix); |
|
| 51 | + |
|
| 52 | + if (is_null($this->refBackend)) { |
|
| 53 | + $this->refBackend = $this->backends[$configPrefix]; |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + $this->isSetUp = true; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @return T |
|
| 62 | + */ |
|
| 63 | + abstract protected function newInstance(string $configPrefix): object; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @return T |
|
| 67 | + */ |
|
| 68 | + public function getBackend(string $configPrefix): object { |
|
| 69 | + $this->setup(); |
|
| 70 | + return $this->backends[$configPrefix]; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + private function addAccess(string $configPrefix): void { |
|
| 74 | + $userMap = Server::get(UserMapping::class); |
|
| 75 | + $groupMap = Server::get(GroupMapping::class); |
|
| 76 | + |
|
| 77 | + $connector = new Connection($this->ldap, $configPrefix); |
|
| 78 | + $access = $this->accessFactory->get($connector); |
|
| 79 | + $access->setUserMapper($userMap); |
|
| 80 | + $access->setGroupMapper($groupMap); |
|
| 81 | + self::$accesses[$configPrefix] = $access; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + protected function getAccess(string $configPrefix): Access { |
|
| 85 | + if (!isset(self::$accesses[$configPrefix])) { |
|
| 86 | + $this->addAccess($configPrefix); |
|
| 87 | + } |
|
| 88 | + return self::$accesses[$configPrefix]; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @param string $uid |
|
| 93 | + * @return string |
|
| 94 | + */ |
|
| 95 | + protected function getUserCacheKey($uid) { |
|
| 96 | + return 'user-' . $uid . '-lastSeenOn'; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @param string $gid |
|
| 101 | + * @return string |
|
| 102 | + */ |
|
| 103 | + protected function getGroupCacheKey($gid) { |
|
| 104 | + return 'group-' . $gid . '-lastSeenOn'; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @param string $id |
|
| 109 | + * @param string $method |
|
| 110 | + * @param array $parameters |
|
| 111 | + * @param bool $passOnWhen |
|
| 112 | + * @return mixed |
|
| 113 | + */ |
|
| 114 | + abstract protected function callOnLastSeenOn($id, $method, $parameters, $passOnWhen); |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @param string $id |
|
| 118 | + * @param string $method |
|
| 119 | + * @param array $parameters |
|
| 120 | + * @return mixed |
|
| 121 | + */ |
|
| 122 | + abstract protected function walkBackends($id, $method, $parameters); |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @param string $id |
|
| 126 | + * @return Access |
|
| 127 | + */ |
|
| 128 | + abstract public function getLDAPAccess($id); |
|
| 129 | + |
|
| 130 | + abstract protected function activeBackends(): int; |
|
| 131 | + |
|
| 132 | + protected function isSingleBackend(): bool { |
|
| 133 | + if ($this->isSingleBackend === null) { |
|
| 134 | + $this->isSingleBackend = $this->activeBackends() === 1; |
|
| 135 | + } |
|
| 136 | + return $this->isSingleBackend; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Takes care of the request to the User backend |
|
| 141 | + * |
|
| 142 | + * @param string $id |
|
| 143 | + * @param string $method string, the method of the user backend that shall be called |
|
| 144 | + * @param array $parameters an array of parameters to be passed |
|
| 145 | + * @param bool $passOnWhen |
|
| 146 | + * @return mixed the result of the specified method |
|
| 147 | + */ |
|
| 148 | + protected function handleRequest($id, $method, $parameters, $passOnWhen = false) { |
|
| 149 | + if (!$this->isSingleBackend()) { |
|
| 150 | + $result = $this->callOnLastSeenOn($id, $method, $parameters, $passOnWhen); |
|
| 151 | + } |
|
| 152 | + if (!isset($result) || $result === $passOnWhen) { |
|
| 153 | + $result = $this->walkBackends($id, $method, $parameters); |
|
| 154 | + } |
|
| 155 | + return $result; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * @param string|null $key |
|
| 160 | + * @return string |
|
| 161 | + */ |
|
| 162 | + private function getCacheKey($key) { |
|
| 163 | + $prefix = 'LDAP-Proxy-'; |
|
| 164 | + if ($key === null) { |
|
| 165 | + return $prefix; |
|
| 166 | + } |
|
| 167 | + return $prefix . hash('sha256', $key); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * @param string $key |
|
| 172 | + * @return mixed|null |
|
| 173 | + */ |
|
| 174 | + public function getFromCache($key) { |
|
| 175 | + if ($this->cache === null) { |
|
| 176 | + return null; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + $key = $this->getCacheKey($key); |
|
| 180 | + $value = $this->cache->get($key); |
|
| 181 | + if ($value === null) { |
|
| 182 | + return null; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + return json_decode(base64_decode($value)); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * @param string $key |
|
| 190 | + * @param mixed $value |
|
| 191 | + */ |
|
| 192 | + public function writeToCache($key, $value) { |
|
| 193 | + if ($this->cache === null) { |
|
| 194 | + return; |
|
| 195 | + } |
|
| 196 | + $key = $this->getCacheKey($key); |
|
| 197 | + $value = base64_encode(json_encode($value)); |
|
| 198 | + $this->cache->set($key, $value, 2592000); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + public function clearCache() { |
|
| 202 | + if ($this->cache === null) { |
|
| 203 | + return; |
|
| 204 | + } |
|
| 205 | + $this->cache->clear($this->getCacheKey(null)); |
|
| 206 | + } |
|
| 207 | 207 | } |
@@ -29,22 +29,22 @@ |
||
| 29 | 29 | use OCP\IInitialStateService; |
| 30 | 30 | |
| 31 | 31 | class InitialState implements IInitialState { |
| 32 | - /** @var IInitialStateService */ |
|
| 33 | - private $state; |
|
| 32 | + /** @var IInitialStateService */ |
|
| 33 | + private $state; |
|
| 34 | 34 | |
| 35 | - /** @var string */ |
|
| 36 | - private $appName; |
|
| 35 | + /** @var string */ |
|
| 36 | + private $appName; |
|
| 37 | 37 | |
| 38 | - public function __construct(IInitialStateService $state, string $appName) { |
|
| 39 | - $this->state = $state; |
|
| 40 | - $this->appName = $appName; |
|
| 41 | - } |
|
| 38 | + public function __construct(IInitialStateService $state, string $appName) { |
|
| 39 | + $this->state = $state; |
|
| 40 | + $this->appName = $appName; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public function provideInitialState(string $key, $data): void { |
|
| 44 | - $this->state->provideInitialState($this->appName, $key, $data); |
|
| 45 | - } |
|
| 43 | + public function provideInitialState(string $key, $data): void { |
|
| 44 | + $this->state->provideInitialState($this->appName, $key, $data); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - public function provideLazyInitialState(string $key, \Closure $closure): void { |
|
| 48 | - $this->state->provideLazyInitialState($this->appName, $key, $closure); |
|
| 49 | - } |
|
| 47 | + public function provideLazyInitialState(string $key, \Closure $closure): void { |
|
| 48 | + $this->state->provideLazyInitialState($this->appName, $key, $closure); |
|
| 49 | + } |
|
| 50 | 50 | } |