AuthLister.php
Go to the documentation of this file.
00001 <?php 00002 00005 00026 class AuthLister extends WebService 00027 { 00029 private $db; 00030 00032 private $conneg; 00033 00035 private $dtdURL; 00036 00038 private $requester_ip = ""; 00039 00041 private $registered_ip = ""; 00042 00044 private $dataset = ""; 00045 00047 private $mode = ""; 00048 00050 private $datasets = array(); 00051 00053 private $webservices = array(); 00054 00056 private $accesses = array(); 00057 00059 private $errorMessenger = 00060 '{ 00061 "ws": "/ws/auth/lister/", 00062 "_200": { 00063 "id": "WS-AUTH-LISTER-200", 00064 "level": "Warning", 00065 "name": "Unknown Listing Mode", 00066 "description": "The mode you specified for the \'mode\' parameter is unknown. Please check the documentation of this web service endpoint for more information" 00067 }, 00068 "_201": { 00069 "id": "WS-AUTH-LISTER-201", 00070 "level": "Warning", 00071 "name": "No Target Dataset URI", 00072 "description": "No target dataset URI defined for this request. A target dataset URI is needed for the mode \'ws\' and \'dataset\'" 00073 }, 00074 "_300": { 00075 "id": "WS-AUTH-LISTER-300", 00076 "level": "Fatal", 00077 "name": "Can\'t get the list of datasets", 00078 "description": "An error occured when we tried to get the list of datasets available to the user" 00079 }, 00080 "_301": { 00081 "id": "WS-AUTH-LISTER-301", 00082 "level": "Fatal", 00083 "name": "Can\'t get the list of web services", 00084 "description": "An error occured when we tried to get the list of web services endpoints registered to this web service network" 00085 }, 00086 "_302": { 00087 "id": "WS-AUTH-LISTER-302", 00088 "level": "Fatal", 00089 "name": "Can\'t get the list of accesses for that dataset", 00090 "description": "An error occured when we tried to get the list of accesses defined for this dataset" 00091 }, 00092 "_303": { 00093 "id": "WS-AUTH-LISTER-303", 00094 "level": "Fatal", 00095 "name": "Can\'t get the list of accesses an datasets available to that user", 00096 "description": "An error occured when we tried to get the list of accesses and datasets accessible to that user" 00097 }, 00098 "_304": { 00099 "id": "WS-AUTH-LISTER-304", 00100 "level": "Fatal", 00101 "name": "Can\'t get access information for this web service", 00102 "description": "An error occured when we tried to get the information for the access to that web service." 00103 } 00104 }'; 00105 00107 public static $supportedSerializations = 00108 array ("application/json", "application/rdf+xml", "application/rdf+n3", "application/*", "text/xml", "text/*", 00109 "*/*"); 00110 00130 function __construct($mode, $dataset, $registered_ip, $requester_ip) 00131 { 00132 parent::__construct(); 00133 00134 $this->db = new DB_Virtuoso($this->db_username, $this->db_password, $this->db_dsn, $this->db_host); 00135 00136 $this->requester_ip = $requester_ip; 00137 $this->mode = $mode; 00138 $this->dataset = $dataset; 00139 00140 if($registered_ip == "") 00141 { 00142 $this->registered_ip = $requester_ip; 00143 } 00144 else 00145 { 00146 $this->registered_ip = $registered_ip; 00147 } 00148 00149 if(strtolower(substr($this->registered_ip, 0, 4)) == "self") 00150 { 00151 $pos = strpos($this->registered_ip, "::"); 00152 00153 if($pos !== FALSE) 00154 { 00155 $account = substr($this->registered_ip, $pos + 2, strlen($this->registered_ip) - ($pos + 2)); 00156 00157 $this->registered_ip = $requester_ip . "::" . $account; 00158 } 00159 else 00160 { 00161 $this->registered_ip = $requester_ip; 00162 } 00163 } 00164 00165 $this->uri = $this->wsf_base_url . "/wsf/ws/auth/lister/"; 00166 $this->title = "Authentication Lister Web Service"; 00167 $this->crud_usage = new CrudUsage(FALSE, TRUE, FALSE, FALSE); 00168 $this->endpoint = $this->wsf_base_url . "/ws/auth/lister/"; 00169 00170 $this->dtdURL = "auth/authLister.dtd"; 00171 00172 $this->errorMessenger = json_decode($this->errorMessenger); 00173 } 00174 00175 function __destruct() 00176 { 00177 parent::__destruct(); 00178 00179 if(isset($this->db)) 00180 { 00181 @$this->db->close(); 00182 } 00183 } 00184 00195 protected function validateQuery() 00196 { 00197 // publicly accessible users) 00198 if($this->mode != "dataset" && $this->mode != "access_user") 00199 { 00200 $ws_av = new AuthValidator($this->requester_ip, $this->wsf_graph, $this->uri); 00201 00202 $ws_av->pipeline_conneg($this->conneg->getAccept(), $this->conneg->getAcceptCharset(), 00203 $this->conneg->getAcceptEncoding(), $this->conneg->getAcceptLanguage()); 00204 00205 $ws_av->process(); 00206 00207 if($ws_av->pipeline_getResponseHeaderStatus() != 200) 00208 { 00209 $this->conneg->setStatus($ws_av->pipeline_getResponseHeaderStatus()); 00210 $this->conneg->setStatusMsg($ws_av->pipeline_getResponseHeaderStatusMsg()); 00211 $this->conneg->setStatusMsgExt($ws_av->pipeline_getResponseHeaderStatusMsgExt()); 00212 $this->conneg->setError($ws_av->pipeline_getError()->id, $ws_av->pipeline_getError()->webservice, 00213 $ws_av->pipeline_getError()->name, $ws_av->pipeline_getError()->description, 00214 $ws_av->pipeline_getError()->debugInfo, $ws_av->pipeline_getError()->level); 00215 return; 00216 } 00217 } 00218 } 00219 00230 public function pipeline_getError() { return ($this->conneg->error); } 00231 00242 public function pipeline_getResultset() 00243 { 00244 $xml = new ProcessorXML(); 00245 00246 // Creation of the RESULTSET 00247 $resultset = $xml->createResultset(); 00248 00249 // Creation of the prefixes elements. 00250 $void = $xml->createPrefix("owl", "http://www.w3.org/2002/07/owl#"); 00251 $resultset->appendChild($void); 00252 $rdf = $xml->createPrefix("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); 00253 $resultset->appendChild($rdf); 00254 $dcterms = $xml->createPrefix("rdfs", "http://www.w3.org/2000/01/rdf-schema#"); 00255 $resultset->appendChild($dcterms); 00256 $dcterms = $xml->createPrefix("wsf", "http://purl.org/ontology/wsf#"); 00257 $resultset->appendChild($dcterms); 00258 00259 if(strtolower($this->mode) != "access_dataset" && strtolower($this->mode) != "access_user") 00260 { 00261 // Creation of the SUBJECT of the RESULTSET 00262 $subject = $xml->createSubject("rdf:Bag", ""); 00263 00264 if(strtolower($this->mode) == "ws") 00265 { 00266 foreach($this->webservices as $ws) 00267 { 00268 // Creation of the RDF:LI predicate 00269 $pred = $xml->createPredicate("rdf:li"); 00270 00271 // Creation of the OBJECT of the predicate 00272 $object = $xml->createObject("wsf:WebService", "$ws"); 00273 00274 $pred->appendChild($object); 00275 $subject->appendChild($pred); 00276 } 00277 } 00278 elseif(strtolower($this->mode) == "dataset") 00279 { 00280 foreach($this->datasets as $dataset) 00281 { 00282 // Creation of the RDF:LI predicate 00283 $pred = $xml->createPredicate("rdf:li"); 00284 00285 // Creation of the OBJECT of the predicate 00286 $object = $xml->createObject("void:Dataset", "$dataset"); 00287 00288 $pred->appendChild($object); 00289 $subject->appendChild($pred); 00290 } 00291 } 00292 00293 $resultset->appendChild($subject); 00294 } 00295 else 00296 { 00297 /* 00298 Array 00299 ( 00300 [0] => Array 00301 ( 00302 [0] => /wsf/access/auth/validator/2 00303 [1] => /wsf/ 00304 [2] => True 00305 [3] => True 00306 [4] => True 00307 [5] => True 00308 [6] => /wsf/ws/auth/lister/ 00309 [7] => /wsf/ws/auth/registrar/ws/ 00310 [8] => /wsf/ws/auth/registrar/access/ 00311 ) 00312 00313 ) 00314 */ 00315 00316 // Creation of the SUBJECT of the RESULTSET 00317 00318 foreach($this->accesses as $access) 00319 { 00320 $subject = $xml->createSubject("wsf:Access", $access[0]); 00321 00322 if(strtolower($this->mode) == "access_user") 00323 { 00324 $pred = $xml->createPredicate("wsf:datasetAccess"); 00325 $object = $xml->createObject("void:Dataset", $access[1]); 00326 $pred->appendChild($object); 00327 $subject->appendChild($pred); 00328 00329 $pred = $xml->createPredicate("wsf:registeredIP"); 00330 $object = $xml->createObjectContent($access[6]); 00331 $pred->appendChild($object); 00332 $subject->appendChild($pred); 00333 } 00334 else 00335 { 00336 $pred = $xml->createPredicate("wsf:registeredIP"); 00337 $object = $xml->createObjectContent($access[1]); 00338 $pred->appendChild($object); 00339 $subject->appendChild($pred); 00340 } 00341 00342 $pred = $xml->createPredicate("wsf:create"); 00343 $object = $xml->createObjectContent($access[2]); 00344 $pred->appendChild($object); 00345 $subject->appendChild($pred); 00346 00347 $pred = $xml->createPredicate("wsf:read"); 00348 $object = $xml->createObjectContent($access[3]); 00349 $pred->appendChild($object); 00350 $subject->appendChild($pred); 00351 00352 $pred = $xml->createPredicate("wsf:update"); 00353 $object = $xml->createObjectContent($access[4]); 00354 $pred->appendChild($object); 00355 $subject->appendChild($pred); 00356 00357 $pred = $xml->createPredicate("wsf:delete"); 00358 $object = $xml->createObjectContent($access[5]); 00359 $pred->appendChild($object); 00360 $subject->appendChild($pred); 00361 00362 $nbWS = count($access) - 7; 00363 00364 for($i = 0; $i < $nbWS; $i++) 00365 { 00366 $pred = $xml->createPredicate("wsf:webServiceAccess"); 00367 $object = $xml->createObject("wsf:WebService", $access[(7 + $i)]); 00368 $pred->appendChild($object); 00369 $subject->appendChild($pred); 00370 } 00371 00372 $resultset->appendChild($subject); 00373 } 00374 } 00375 00376 return ($this->injectDoctype($xml->saveXML($resultset))); 00377 } 00378 00391 public function injectDoctype($xmlDoc) 00392 { 00393 $posHeader = strpos($xmlDoc, '"?>') + 3; 00394 $xmlDoc = substr($xmlDoc, 0, $posHeader) 00395 . "\n<!DOCTYPE resultset PUBLIC \"-//Structured Dynamics LLC//Auth Lister DTD 0.1//EN\" \"" . $this->dtdBaseURL 00396 . $this->dtdURL . "\">" . substr($xmlDoc, $posHeader, strlen($xmlDoc) - $posHeader); 00397 00398 return ($xmlDoc); 00399 } 00400 00419 public function ws_conneg($accept, $accept_charset, $accept_encoding, $accept_language) 00420 { 00421 $this->conneg = 00422 new Conneg($accept, $accept_charset, $accept_encoding, $accept_language, AuthLister::$supportedSerializations); 00423 00424 // Check for errors 00425 if(strtolower($this->mode) != "ws" && strtolower($this->mode) != "dataset" 00426 && strtolower($this->mode) != "access_dataset" && strtolower($this->mode) != "access_user") 00427 { 00428 $this->conneg->setStatus(400); 00429 $this->conneg->setStatusMsg("Bad Request"); 00430 $this->conneg->setStatusMsgExt("Unknown listing type"); 00431 $this->conneg->setError($this->errorMessenger->_200->id, $this->errorMessenger->ws, 00432 $this->errorMessenger->_200->name, $this->errorMessenger->_200->description, odbc_errormsg(), 00433 $this->errorMessenger->_200->level); 00434 return; 00435 } 00436 00437 // Check for errors 00438 if(strtolower($this->mode) != "access_dataset" && $dataset = "") 00439 { 00440 $this->conneg->setStatus(400); 00441 $this->conneg->setStatusMsg("Bad Request"); 00442 $this->conneg->setStatusMsgExt($this->errorMessenger->_201->name); 00443 $this->conneg->setError($this->errorMessenger->_201->id, $this->errorMessenger->ws, 00444 $this->errorMessenger->_201->name, $this->errorMessenger->_201->description, odbc_errormsg(), 00445 $this->errorMessenger->_201->level); 00446 return; 00447 } 00448 } 00449 00468 public function pipeline_conneg($accept, $accept_charset, $accept_encoding, $accept_language) 00469 { $this->ws_conneg($accept, $accept_charset, $accept_encoding, $accept_language); } 00470 00481 public function pipeline_getResponseHeaderStatus() { return $this->conneg->getStatus(); } 00482 00493 public function pipeline_getResponseHeaderStatusMsg() { return $this->conneg->getStatusMsg(); } 00494 00507 public function pipeline_getResponseHeaderStatusMsgExt() { return $this->conneg->getStatusMsgExt(); } 00508 00519 public function pipeline_serialize() 00520 { 00521 00522 $rdf_part = ""; 00523 00524 switch($this->conneg->getMime()) 00525 { 00526 case "application/json": 00527 $json_part = ""; 00528 $xml = new ProcessorXML(); 00529 $xml->loadXML($this->pipeline_getResultset()); 00530 00531 $subjects = $xml->getSubjects(); 00532 00533 foreach($subjects as $subject) 00534 { 00535 $subjectURI = $xml->getURI($subject); 00536 $subjectType = $xml->getType($subject); 00537 00538 $json_part .= " { \n"; 00539 $json_part .= " \"uri\": \"" . parent::jsonEncode($subjectURI) . "\", \n"; 00540 $json_part .= " \"type\": \"" . parent::jsonEncode($subjectType) . "\", \n"; 00541 00542 $predicates = $xml->getPredicates($subject); 00543 00544 $nbPredicates = 0; 00545 00546 foreach($predicates as $predicate) 00547 { 00548 $objects = $xml->getObjects($predicate); 00549 00550 foreach($objects as $object) 00551 { 00552 $nbPredicates++; 00553 00554 if($nbPredicates == 1) 00555 { 00556 $json_part .= " \"predicate\": [ \n"; 00557 } 00558 00559 $objectType = $xml->getType($object); 00560 $predicateType = $xml->getType($predicate); 00561 00562 if($objectType == "rdfs:Literal") 00563 { 00564 $objectValue = $xml->getContent($object); 00565 00566 $json_part .= " { \n"; 00567 $json_part .= " \"" . parent::jsonEncode($predicateType) . "\": \"" 00568 . parent::jsonEncode($objectValue) . "\" \n"; 00569 $json_part .= " },\n"; 00570 } 00571 else 00572 { 00573 $objectURI = $xml->getURI($object); 00574 $rdf_part .= " <$predicateType> <$objectURI> ;\n"; 00575 00576 $json_part .= " { \n"; 00577 $json_part .= " \"" . parent::jsonEncode($predicateType) . "\": { \n"; 00578 $json_part .= " \"uri\": \"" . parent::jsonEncode($objectURI) . "\" \n"; 00579 $json_part .= " } \n"; 00580 $json_part .= " },\n"; 00581 } 00582 } 00583 } 00584 00585 if(strlen($json_part) > 0) 00586 { 00587 $json_part = substr($json_part, 0, strlen($json_part) - 2) . "\n"; 00588 } 00589 00590 if($nbPredicates > 0) 00591 { 00592 $json_part .= " ]\n"; 00593 } 00594 00595 $json_part .= " },\n"; 00596 } 00597 00598 if(strlen($json_part) > 0) 00599 { 00600 $json_part = substr($json_part, 0, strlen($json_part) - 2) . "\n"; 00601 } 00602 00603 return ($json_part); 00604 break; 00605 00606 case "application/rdf+n3": 00607 00608 $xml = new ProcessorXML(); 00609 $xml->loadXML($this->pipeline_getResultset()); 00610 00611 if(strtolower($this->mode) != "access_dataset" && strtolower($this->mode) != "access_user") 00612 { 00613 $subjects = $xml->getSubjectsByType("rdf:Bag"); 00614 00615 foreach($subjects as $subject) 00616 { 00617 $predicates = $xml->getPredicatesByType($subject, "rdf:li"); 00618 00619 foreach($predicates as $predicate) 00620 { 00621 if(strtolower($this->mode) == "dataset") 00622 { 00623 $objects = $xml->getObjectsByType($predicate, "void:Dataset"); 00624 } 00625 else 00626 { 00627 $objects = $xml->getObjectsByType($predicate, "wsf:WebService"); 00628 } 00629 00630 foreach($objects as $object) 00631 { 00632 $rdf_part .= " rdf:li <" . $xml->getURI($object) . "> ;\n"; 00633 } 00634 } 00635 } 00636 00637 if(strlen($rdf_part) > 0) 00638 { 00639 $rdf_part = substr($rdf_part, 0, strlen($rdf_part) - 2) . ".\n"; 00640 } 00641 } 00642 else 00643 { 00644 $xml = new ProcessorXML(); 00645 $xml->loadXML($this->pipeline_getResultset()); 00646 00647 $accesses = $xml->getSubjectsByType("wsf:Access"); 00648 00649 foreach($accesses as $access) 00650 { 00651 $access_uri = $xml->getURI($access); 00652 00653 $rdf_part .= "<$access_uri> a wsf:Access ;\n"; 00654 00655 // Get webServiceAccess 00656 $predicates = $xml->getPredicatesByType($access, "wsf:datasetAccess"); 00657 $objects = $xml->getObjectsByType($predicates->item(0), "void:Dataset"); 00658 00659 $rdf_part .= "wsf:datasetAccess <" . $xml->getURI($objects->item(0)) . "> ;\n"; 00660 00661 00662 // Get crud 00663 $predicates = $xml->getPredicatesByType($access, "wsf:create"); 00664 $objects = $xml->getObjectsByType($predicates->item(0), "rdfs:Literal"); 00665 $rdf_part .= "wsf:create \"" . $xml->getContent($objects->item(0)) . "\" ;\n"; 00666 00667 $predicates = $xml->getPredicatesByType($access, "wsf:read"); 00668 $objects = $xml->getObjectsByType($predicates->item(0), "rdfs:Literal"); 00669 $rdf_part .= "wsf:read \"" . $xml->getContent($objects->item(0)) . "\" ;\n"; 00670 00671 $predicates = $xml->getPredicatesByType($access, "wsf:update"); 00672 $objects = $xml->getObjectsByType($predicates->item(0), "rdfs:Literal"); 00673 $rdf_part .= "wsf:update \"" . $xml->getContent($objects->item(0)) . "\" ;\n"; 00674 00675 $predicates = $xml->getPredicatesByType($access, "wsf:delete"); 00676 $objects = $xml->getObjectsByType($predicates->item(0), "rdfs:Literal"); 00677 $rdf_part .= "wsf:delete \"" . $xml->getContent($objects->item(0)) . "\" ;\n"; 00678 00679 // Get webServiceAccess(es) 00680 $webservices = $xml->getXPath('//predicate/object[attribute::type="wsf:WebService"]', $access); 00681 00682 foreach($webservices as $element) 00683 { 00684 $rdf_part .= "wsf:webServiceAccess <" . $xml->getURI($element) . "> ;\n"; 00685 } 00686 00687 if(strlen($rdf_part) > 0) 00688 { 00689 $rdf_part = substr($rdf_part, 0, strlen($rdf_part) - 2) . ".\n"; 00690 } 00691 } 00692 } 00693 00694 return ($rdf_part); 00695 break; 00696 00697 case "application/rdf+xml": 00698 00699 $xml = new ProcessorXML(); 00700 $xml->loadXML($this->pipeline_getResultset()); 00701 00702 if(strtolower($this->mode) != "access_dataset" && strtolower($this->mode) != "access_user") 00703 { 00704 $subjects = $xml->getSubjectsByType("rdf:Bag"); 00705 00706 foreach($subjects as $subject) 00707 { 00708 $predicates = $xml->getPredicatesByType($subject, "rdf:li"); 00709 00710 foreach($predicates as $predicate) 00711 { 00712 if(strtolower($this->mode) == "dataset") 00713 { 00714 $objects = $xml->getObjectsByType($predicate, "void:Dataset"); 00715 } 00716 else 00717 { 00718 $objects = $xml->getObjectsByType($predicate, "wsf:WebService"); 00719 } 00720 00721 foreach($objects as $object) 00722 { 00723 $rdf_part .= " <rdf:li rdf:resource=\"" . $this->xmlEncode($xml->getURI($object)) . "\" />\n"; 00724 } 00725 } 00726 } 00727 } 00728 else 00729 { 00730 $xml = new ProcessorXML(); 00731 $xml->loadXML($this->pipeline_getResultset()); 00732 00733 $accesses = $xml->getSubjectsByType("wsf:Access"); 00734 00735 foreach($accesses as $access) 00736 { 00737 $access_uri = $xml->getURI($access); 00738 00739 $rdf_part .= "<wsf:Access rdf:about=\"$access_uri\">\n"; 00740 00741 // Get webServiceAccess 00742 $predicates = $xml->getPredicatesByType($access, "wsf:datasetAccess"); 00743 $objects = $xml->getObjectsByType($predicates->item(0), "void:Dataset"); 00744 00745 $rdf_part .= "<wsf:datasetAccess rdf:resource=\"" . $this->xmlEncode($xml->getURI($objects->item(0))) . "\" />\n"; 00746 00747 00748 // Get crud 00749 $predicates = $xml->getPredicatesByType($access, "wsf:create"); 00750 $objects = $xml->getObjectsByType($predicates->item(0), "rdfs:Literal"); 00751 $rdf_part .= "<wsf:create>" . $xml->getContent($objects->item(0)) . "</wsf:create>\n"; 00752 00753 $predicates = $xml->getPredicatesByType($access, "wsf:read"); 00754 $objects = $xml->getObjectsByType($predicates->item(0), "rdfs:Literal"); 00755 $rdf_part .= "<wsf:read>" . $xml->getContent($objects->item(0)) . "</wsf:read>\n"; 00756 00757 $predicates = $xml->getPredicatesByType($access, "wsf:update"); 00758 $objects = $xml->getObjectsByType($predicates->item(0), "rdfs:Literal"); 00759 $rdf_part .= "<wsf:update>" . $xml->getContent($objects->item(0)) . "</wsf:update>\n"; 00760 00761 $predicates = $xml->getPredicatesByType($access, "wsf:delete"); 00762 $objects = $xml->getObjectsByType($predicates->item(0), "rdfs:Literal"); 00763 $rdf_part .= "<wsf:delete>" . $xml->getContent($objects->item(0)) . "</wsf:delete>\n"; 00764 00765 // Get webServiceAccess(es) 00766 $webservices = $xml->getXPath('//predicate/object[attribute::type="wsf:WebService"]', $access); 00767 00768 foreach($webservices as $element) 00769 { 00770 $rdf_part .= "<wsf:webServiceAccess rdf:resource=\"" . $xml->getURI($element) . "\" />\n"; 00771 } 00772 00773 $rdf_part .= "</wsf:Access>\n"; 00774 } 00775 } 00776 00777 return ($rdf_part); 00778 break; 00779 } 00780 } 00781 00790 public function pipeline_serialize_reification() { return ""; } 00791 00802 public function ws_serialize() 00803 { 00804 switch($this->conneg->getMime()) 00805 { 00806 case "application/rdf+n3": 00807 $rdf_document = ""; 00808 $rdf_document .= "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n"; 00809 $rdf_document .= "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n"; 00810 $rdf_document .= "@prefix owl: <http://www.w3.org/2002/07/owl#> .\n"; 00811 $rdf_document .= "@prefix void: <http://rdfs.org/ns/void#> .\n"; 00812 $rdf_document .= "@prefix wsf: <http://purl.org/ontology/wsf#> .\n"; 00813 00814 if(strtolower($this->mode) != "access_dataset" && strtolower($this->mode) != "access_user") 00815 { 00816 $rdf_document .= "_:bnode0 rdf:type rdf:Bag ;\n"; 00817 } 00818 00819 $rdf_document .= $this->pipeline_serialize(); 00820 00821 $rdf_document = substr($rdf_document, 0, strlen($rdf_document) - 2) . ".\n"; 00822 00823 return $rdf_document; 00824 break; 00825 00826 case "application/rdf+xml": 00827 $rdf_document = ""; 00828 $rdf_document .= "<?xml version=\"1.0\"?>\n"; 00829 $rdf_document 00830 .= "<rdf:RDF xmlns:bibo=\"http://purl.org/ontology/bibo/\" xmlns:void=\"http://rdfs.org/ns/void#\" xmlns:wsf=\"http://purl.org/ontology/wsf#\" xmlns:owl=\"http://www.w3.org/2002/07/owl#\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema#\" xmlns:rdfs=\"http://www.w3.org/2000/01/rdf-schema#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n\n"; 00831 00832 if(strtolower($this->mode) != "access_dataset" && strtolower($this->mode) != "access_user") 00833 { 00834 $rdf_document .= "<rdf:Bag>\n"; 00835 } 00836 00837 $rdf_document .= $this->pipeline_serialize(); 00838 00839 if(strtolower($this->mode) != "access_dataset" && strtolower($this->mode) != "access_user") 00840 { 00841 $rdf_document .= "</rdf:Bag>\n\n"; 00842 } 00843 00844 $rdf_document .= "</rdf:RDF>"; 00845 00846 return $rdf_document; 00847 break; 00848 00849 case "application/json": 00850 $json_document = ""; 00851 $json_document .= "{\n"; 00852 00853 $json_document .= " \"prefixes\": [ \n"; 00854 $json_document .= " {\n"; 00855 $json_document .= " \"rdf\": \"http://www.w3.org/1999/02/22-rdf-syntax-ns#\",\n"; 00856 $json_document .= " \"owl\": \"http://www.w3.org/2002/07/owl#\",\n"; 00857 $json_document .= " \"rdfs\": \"http://www.w3.org/2000/01/rdf-schema#\",\n"; 00858 $json_document .= " \"wsf\": \"http://purl.org/ontology/wsf#\"\n"; 00859 $json_document .= " } \n"; 00860 $json_document .= " ],\n"; 00861 00862 $json_document .= " \"resultset\": {\n"; 00863 $json_document .= " \"subject\": [\n"; 00864 $json_document .= $this->pipeline_serialize(); 00865 $json_document .= " ]\n"; 00866 $json_document .= " }\n"; 00867 $json_document .= "}"; 00868 00869 return ($json_document); 00870 break; 00871 00872 case "text/xml": 00873 return $this->pipeline_getResultset(); 00874 break; 00875 } 00876 } 00877 00890 public function ws_respond($content) 00891 { 00892 // First send the header of the request 00893 $this->conneg->respond(); 00894 00895 // second, send the content of the request 00896 00897 // Make sure there is no error. 00898 if($this->conneg->getStatus() == 200) 00899 { 00900 echo $content; 00901 } 00902 00903 $this->__destruct(); 00904 } 00905 00906 00917 public function process() 00918 { 00919 // Make sure there was no conneg error prior to this process call 00920 if($this->conneg->getStatus() == 200) 00921 { 00922 $this->validateQuery(); 00923 00924 // If the query is still valid 00925 if($this->conneg->getStatus() == 200) 00926 { 00927 if(strtolower($this->mode) == "dataset") 00928 { 00929 $query = 00930 " select distinct ?dataset 00931 from <" . $this->wsf_graph 00932 . "> 00933 where 00934 { 00935 { 00936 ?access <http://purl.org/ontology/wsf#registeredIP> \"$this->registered_ip\" ; 00937 <http://purl.org/ontology/wsf#datasetAccess> ?dataset . 00938 } 00939 UNION 00940 { 00941 ?access <http://purl.org/ontology/wsf#registeredIP> \"0.0.0.0\" ; 00942 <http://purl.org/ontology/wsf#create> ?create ; 00943 <http://purl.org/ontology/wsf#read> ?read ; 00944 <http://purl.org/ontology/wsf#update> ?update ; 00945 <http://purl.org/ontology/wsf#delete> ?delete ; 00946 <http://purl.org/ontology/wsf#datasetAccess> ?dataset . 00947 filter( str(?create) = \"True\" or str(?read) = \"True\" or str(?update) = \"True\" or str(?delete) = \"True\"). 00948 } 00949 }"; 00950 00951 $resultset = 00952 @$this->db->query($this->db->build_sparql_query(str_replace(array ("\n", "\r", "\t"), " ", $query), array(), 00953 FALSE)); 00954 00955 if(odbc_error()) 00956 { 00957 $this->conneg->setStatus(500); 00958 $this->conneg->setStatusMsg("Internal Error"); 00959 $this->conneg->setStatusMsgExt($this->errorMessenger->_300->name); 00960 $this->conneg->setError($this->errorMessenger->_300->id, $this->errorMessenger->ws, 00961 $this->errorMessenger->_300->name, $this->errorMessenger->_300->description, odbc_errormsg(), 00962 $this->errorMessenger->_300->level); 00963 return; 00964 } 00965 00966 while(odbc_fetch_row($resultset)) 00967 { 00968 $dataset = odbc_result($resultset, 1); 00969 00970 array_push($this->datasets, $dataset); 00971 } 00972 } 00973 elseif(strtolower($this->mode) == "ws") 00974 { 00975 $query = 00976 " select distinct ?ws from <" . $this->wsf_graph 00977 . "> 00978 where 00979 { 00980 ?wsf a <http://purl.org/ontology/wsf#WebServiceFramework> ; 00981 <http://purl.org/ontology/wsf#hasWebService> ?ws . 00982 }"; 00983 00984 $resultset = 00985 @$this->db->query($this->db->build_sparql_query(str_replace(array ("\n", "\r", "\t"), " ", $query), array(), 00986 FALSE)); 00987 00988 if(odbc_error()) 00989 { 00990 $this->conneg->setStatus(500); 00991 $this->conneg->setStatusMsg("Internal Error"); 00992 $this->conneg->setStatusMsgExt($this->errorMessenger->_301->name); 00993 $this->conneg->setError($this->errorMessenger->_301->id, $this->errorMessenger->ws, 00994 $this->errorMessenger->_301->name, $this->errorMessenger->_301->description, odbc_errormsg(), 00995 $this->errorMessenger->_301->level); 00996 return; 00997 } 00998 00999 while(odbc_fetch_row($resultset)) 01000 { 01001 $ws = odbc_result($resultset, 1); 01002 01003 array_push($this->webservices, $ws); 01004 } 01005 } 01006 else 01007 { 01008 if(strtolower($this->mode) == "access_user") 01009 { 01010 $query = " select ?access ?datasetAccess ?create ?read ?update ?delete ?registeredIP 01011 from <" . $this->wsf_graph 01012 . "> 01013 where 01014 { 01015 { 01016 ?access a <http://purl.org/ontology/wsf#Access> ; 01017 <http://purl.org/ontology/wsf#registeredIP> \"$this->registered_ip\" ; 01018 <http://purl.org/ontology/wsf#create> ?create ; 01019 <http://purl.org/ontology/wsf#read> ?read ; 01020 <http://purl.org/ontology/wsf#update> ?update ; 01021 <http://purl.org/ontology/wsf#delete> ?delete ; 01022 <http://purl.org/ontology/wsf#datasetAccess> ?datasetAccess ; 01023 <http://purl.org/ontology/wsf#registeredIP> ?registeredIP . 01024 } 01025 union 01026 { 01027 ?access a <http://purl.org/ontology/wsf#Access> ; 01028 <http://purl.org/ontology/wsf#registeredIP> \"0.0.0.0\" ; 01029 <http://purl.org/ontology/wsf#create> ?create ; 01030 <http://purl.org/ontology/wsf#read> ?read ; 01031 <http://purl.org/ontology/wsf#update> ?update ; 01032 <http://purl.org/ontology/wsf#delete> ?delete ; 01033 <http://purl.org/ontology/wsf#datasetAccess> ?datasetAccess ; 01034 <http://purl.org/ontology/wsf#registeredIP> ?registeredIP . 01035 01036 filter( str(?create) = \"True\" or str(?read) = \"True\" or str(?update) = \"True\" or str(?delete) = \"True\"). 01037 } 01038 }"; 01039 } 01040 else // access_dataset 01041 { 01042 $query = " select ?access ?registeredIP ?create ?read ?update ?delete 01043 from <" . $this->wsf_graph 01044 . "> 01045 where 01046 { 01047 ?access a <http://purl.org/ontology/wsf#Access> ; 01048 <http://purl.org/ontology/wsf#registeredIP> ?registeredIP ; 01049 <http://purl.org/ontology/wsf#create> ?create ; 01050 <http://purl.org/ontology/wsf#read> ?read ; 01051 <http://purl.org/ontology/wsf#update> ?update ; 01052 <http://purl.org/ontology/wsf#delete> ?delete ; 01053 <http://purl.org/ontology/wsf#datasetAccess> <$this->dataset> . 01054 }"; 01055 } 01056 01057 $resultset = 01058 @$this->db->query($this->db->build_sparql_query(str_replace(array ("\n", "\r", "\t"), " ", $query), array(), 01059 FALSE)); 01060 01061 if(odbc_error()) 01062 { 01063 $this->conneg->setStatus(500); 01064 $this->conneg->setStatusMsg("Internal Error"); 01065 01066 if(strtolower($this->mode) == "access_user") 01067 { 01068 $this->conneg->setStatusMsgExt($this->errorMessenger->_302->name); 01069 $this->conneg->setError($this->errorMessenger->_302->id, $this->errorMessenger->ws, 01070 $this->errorMessenger->_302->name, $this->errorMessenger->_302->description, odbc_errormsg(), 01071 $this->errorMessenger->_302->level); 01072 } 01073 else 01074 { 01075 $this->conneg->setStatusMsgExt($this->errorMessenger->_303->name); 01076 $this->conneg->setError($this->errorMessenger->_303->id, $this->errorMessenger->ws, 01077 $this->errorMessenger->_303->name, $this->errorMessenger->_303->description, odbc_errormsg(), 01078 $this->errorMessenger->_303->level); 01079 } 01080 01081 return; 01082 } 01083 01084 while(odbc_fetch_row($resultset)) 01085 { 01086 $lastElement = ""; 01087 01088 if(strtolower($this->mode) == "access_user") 01089 { 01090 $lastElement = odbc_result($resultset, 7); 01091 } 01092 01093 array_push($this->accesses, 01094 array (odbc_result($resultset, 1), odbc_result($resultset, 2), odbc_result($resultset, 3), 01095 odbc_result($resultset, 4), odbc_result($resultset, 5), odbc_result($resultset, 6), $lastElement)); 01096 } 01097 01098 foreach($this->accesses as $key => $access) 01099 { 01100 $query = "select ?webServiceAccess from <" . $this->wsf_graph . "> 01101 { 01102 <" . $access[0] . "> <http://purl.org/ontology/wsf#webServiceAccess> ?webServiceAccess . 01103 }"; 01104 01105 $resultset = 01106 @$this->db->query($this->db->build_sparql_query(str_replace(array ("\n", "\r", "\t"), " ", $query), 01107 array(), FALSE)); 01108 01109 if(odbc_error()) 01110 { 01111 $this->conneg->setStatus(500); 01112 $this->conneg->setStatusMsg("Internal Error"); 01113 $this->conneg->setStatusMsgExt($this->errorMessenger->_304->name); 01114 $this->conneg->setError($this->errorMessenger->_304->id, $this->errorMessenger->ws, 01115 $this->errorMessenger->_304->name, $this->errorMessenger->_304->description, odbc_errormsg(), 01116 $this->errorMessenger->_304->level); 01117 return; 01118 } 01119 01120 while(odbc_fetch_row($resultset)) 01121 { 01122 array_push($this->accesses[$key], odbc_result($resultset, 1)); 01123 } 01124 } 01125 } 01126 } 01127 } 01128 } 01129 } 01130 01132 01133 ?>
