-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We already had the FeaturePolicy header. However this call got renamed to PermisionPolicy. Here we move this over. The old mechanism stays there it just won't get extended. So apps that use the FeaturePolicy will not stop to work. Signed-off-by: Roeland Jago Douma <[email protected]>
- Loading branch information
Showing
13 changed files
with
562 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
lib/private/Security/PermissionPolicy/PermissionPolicy.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2020, Roeland Jago Douma <[email protected]> | ||
* | ||
* @author Roeland Jago Douma <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OC\Security\PermissionPolicy; | ||
|
||
class PermissionPolicy extends \OCP\AppFramework\Http\PermissionPolicy { | ||
public function getAutoplayDomains(): array { | ||
return $this->autoplayDomains; | ||
} | ||
|
||
public function setAutoplayDomains(array $autoplayDomains): void { | ||
$this->autoplayDomains = $autoplayDomains; | ||
} | ||
|
||
public function getCameraDomains(): array { | ||
return $this->cameraDomains; | ||
} | ||
|
||
public function setCameraDomains(array $cameraDomains): void { | ||
$this->cameraDomains = $cameraDomains; | ||
} | ||
|
||
public function getFullscreenDomains(): array { | ||
return $this->fullscreenDomains; | ||
} | ||
|
||
public function setFullscreenDomains(array $fullscreenDomains): void { | ||
$this->fullscreenDomains = $fullscreenDomains; | ||
} | ||
|
||
public function getGeolocationDomains(): array { | ||
return $this->geolocationDomains; | ||
} | ||
|
||
public function setGeolocationDomains(array $geolocationDomains): void { | ||
$this->geolocationDomains = $geolocationDomains; | ||
} | ||
|
||
public function getMicrophoneDomains(): array { | ||
return $this->microphoneDomains; | ||
} | ||
|
||
public function setMicrophoneDomains(array $microphoneDomains): void { | ||
$this->microphoneDomains = $microphoneDomains; | ||
} | ||
|
||
public function getPaymentDomains(): array { | ||
return $this->paymentDomains; | ||
} | ||
|
||
public function setPaymentDomains(array $paymentDomains): void { | ||
$this->paymentDomains = $paymentDomains; | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
lib/private/Security/PermissionPolicy/PermissionPolicyManager.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2020, Roeland Jago Douma <[email protected]> | ||
* | ||
* @author Roeland Jago Douma <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
|
||
namespace OC\Security\PermissionPolicy; | ||
|
||
use OCP\AppFramework\Http\EmptyFeaturePolicy; | ||
use OCP\AppFramework\Http\EmptyPermissionPolicy; | ||
use OCP\EventDispatcher\IEventDispatcher; | ||
use OCP\Security\PermissionPolicy\AddPermissionsPolicyEvent; | ||
|
||
class PermissionPolicyManager { | ||
/** @var EmptyPermissionPolicy[] */ | ||
private $policies = []; | ||
|
||
/** @var IEventDispatcher */ | ||
private $dispatcher; | ||
|
||
public function __construct(IEventDispatcher $dispatcher) { | ||
$this->dispatcher = $dispatcher; | ||
} | ||
|
||
public function addDefaultPolicy(EmptyPermissionPolicy $policy): void { | ||
$this->policies[] = $policy; | ||
} | ||
|
||
public function getDefaultPolicy(): PermissionPolicy { | ||
$event = new AddPermissionsPolicyEvent($this); | ||
$this->dispatcher->dispatchTyped($event); | ||
|
||
$defaultPolicy = new PermissionPolicy(); | ||
foreach ($this->policies as $policy) { | ||
$defaultPolicy = $this->mergePolicies($defaultPolicy, $policy); | ||
} | ||
return $defaultPolicy; | ||
} | ||
|
||
/** | ||
* Merges the first given policy with the second one | ||
* | ||
*/ | ||
public function mergePolicies(PermissionPolicy $defaultPolicy, | ||
EmptyPermissionPolicy $originalPolicy): PermissionPolicy { | ||
foreach ((object)(array)$originalPolicy as $name => $value) { | ||
$setter = 'set' . ucfirst($name); | ||
if (\is_array($value)) { | ||
$getter = 'get' . ucfirst($name); | ||
$currentValues = \is_array($defaultPolicy->$getter()) ? $defaultPolicy->$getter() : []; | ||
$defaultPolicy->$setter(\array_values(\array_unique(\array_merge($currentValues, $value)))); | ||
} elseif (\is_bool($value)) { | ||
$defaultPolicy->$setter($value); | ||
} | ||
} | ||
|
||
return $defaultPolicy; | ||
} | ||
|
||
public function mergeFeaturePolicy(PermissionPolicy $defaultPolicy, EmptyFeaturePolicy $featurePolicy): PermissionPolicy { | ||
foreach ((object)(array)$featurePolicy as $name => $value) { | ||
$setter = 'set' . ucfirst($name); | ||
if (\is_array($value)) { | ||
$getter = 'get' . ucfirst($name); | ||
$currentValues = \is_array($defaultPolicy->$getter()) ? $defaultPolicy->$getter() : []; | ||
$defaultPolicy->$setter(\array_values(\array_unique(\array_merge($currentValues, $value)))); | ||
} elseif (\is_bool($value)) { | ||
$defaultPolicy->$setter($value); | ||
} | ||
} | ||
|
||
return $defaultPolicy; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.