From 55ea64f24e9226937077c3e202f6fcd1aa0e8b96 Mon Sep 17 00:00:00 2001 From: Karl Burkhart Date: Wed, 21 Mar 2012 08:56:45 +0000 Subject: [PATCH] =?UTF-8?q?=C3=BCberpr=C3=BCfung=20ob=20ein=20user=20auf?= =?UTF-8?q?=20webservice=20zugreifen=20darf=20implementiert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/webservicerecht.class.php | 122 ++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100755 include/webservicerecht.class.php diff --git a/include/webservicerecht.class.php b/include/webservicerecht.class.php new file mode 100755 index 000000000..870532023 --- /dev/null +++ b/include/webservicerecht.class.php @@ -0,0 +1,122 @@ +. + */ + +require_once(dirname(__FILE__).'/basis_db.class.php'); +require_once(dirname(__FILE__).'/benutzerberechtigung.class.php'); + +class webservicerecht extends basis_db +{ + public $webservicerecht_id; // Serial + public $berechtigung_kurzbz; // FK varchar(32) + public $methode; // varchar(64) + public $attribut; // varchar(256) + public $insertamum; // text + public $insertvon; // timestampt + public $updateamum; // varchar(32) + public $updatevon; // timestampt + + public $new; // boolean + public $result = array(); // webservicelog object array + + /** + * Konstruktor - Laedt optional einen DS + * @param $webservicerecht_id + */ + public function __construct($webservicerecht_id=null) + { + parent::__construct(); + + if(!is_null($webservicerecht_id)) + $this->load($webservicerecht_id); + } + + /** + * Überprüft ob ein User die Berechtigung für eine Methode zum lesen besitzt + * true wenn user lesen darf, false wenn nicht + * + * @param $user + * @param $methode + */ + public function isUserAuthorized($user, $methode) + { + $berechtigung = new benutzerberechtigung(); + $berechtigung->getBerechtigungen($user); + $berechtigungArray = array(); + + foreach ($berechtigung->berechtigungen as $recht) + $berechtigungArray[] = $recht->berechtigung_kurzbz; + + $qry = "SELECT 1 from system.tbl_webservicerecht where methode = ".$this->db_add_param($methode)." + AND berechtigung_kurzbz IN (".$this->implode4SQL($berechtigungArray).');'; + + if($result = $this->db_query($qry)) + { + if($this->db_num_rows($result) == 0 ) + { + return false; + } + } + else + return false; + + return true; + + } + + /** + * Löscht alle Attribute für die ein User keine Berechtiung hat + * + * @param $user + * @param $methode + * @param $objec + * + */ + public function clearResponse($user, $methode, $object) + { + $berechtigung = new benutzerberechtigung(); + $berechtigung->getBerechtigungen($user); + $berechtigungArray = array(); + $attributArray = array(); + + foreach ($berechtigung->berechtigungen as $recht) + $berechtigungArray[] = $recht->berechtigung_kurzbz; + + $qry = "SELECT attribut from system.tbl_webservicerecht where methode = ".$this->db_add_param($methode)." + AND berechtigung_kurzbz IN (".$this->implode4SQL($berechtigungArray).');'; + + if($result = $this->db_query($qry)) + { + while($row = $this->db_fetch_object($result)) + { + $attributArray[] = $row->attribut; + } + } + + $helpObject = new foobar(); + + for($i = 0; $i$attributArray[$i] = $object->$attributArray[$i]; + } + + return $helpObject; + } +} +class foobar{}; \ No newline at end of file