From ae7393db3d99a7ac223ae917129cccd9f49888e3 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Sun, 27 Jan 2013 04:15:53 +0100 Subject: merged the angularjs branch --- lib/security.php | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 lib/security.php (limited to 'lib/security.php') diff --git a/lib/security.php b/lib/security.php new file mode 100644 index 000000000..99258285c --- /dev/null +++ b/lib/security.php @@ -0,0 +1,104 @@ + +* +* This file is licensed under the Affero General Public License version 3 or later. +* See the COPYING-README file +* +*/ + + +namespace OCA\News; + + +/** + * This class is a simple object with getters and setters and allows + * finegrained controll over security checks + * All security checks are enabled by default + */ +class Security { + + private $csrfCheck; + private $loggedInCheck; + private $appEnabledCheck; + private $isAdminCheck; + private $appName; + + /** + * @param string $appName: the name of the app + */ + public function __construct($appName){ + $this->appName = $appName; + + // enable all checks by default + $this->csrfCheck = true; + $this->loggedInCheck = true; + $this->appEnabledCheck = true; + $this->isAdminCheck = true; + } + + + public function setCSRFCheck($csrfCheck){ + $this->csrfCheck = $csrfCheck; + } + + public function setLoggedInCheck($loggedInCheck){ + $this->loggedInCheck = $loggedInCheck; + } + + public function setAppEnabledCheck($appEnabledCheck){ + $this->appEnabledCheck = $appEnabledCheck; + } + + public function setIsAdminCheck($isAdminCheck){ + $this->isAdminCheck = $isAdminCheck; + } + + + /** + * Runs all security checks + */ + public function runChecks() { + + if($this->loggedInCheck){ + \OCP\JSON::checkLoggedIn(); + } + + if($this->appEnabledCheck){ + \OCP\JSON::checkAppEnabled($this->appName); + } + + if($this->isAdminCheck){ + \OCP\JSON::checkAdminUser(); + } + + } + + + /** + * Runs all the security checks for AJAX requests + */ + public function runAjaxChecks(){ + if($this->csrfCheck){ + \OCP\JSON::callCheck(); + } + + if($this->loggedInCheck){ + \OCP\JSON::checkLoggedIn(); + } + + if($this->appEnabledCheck){ + \OCP\JSON::checkAppEnabled($this->appName); + } + + if($this->isAdminCheck){ + \OCP\JSON::checkAdminUser(); + } + + } + + +} \ No newline at end of file -- cgit v1.2.3