|
|
@@ -590,7 +590,7 @@ class Api_WfsServerBase {
|
|
|
$DBG = (V::get('DBG_XML', '', $_GET) > 0);// TODO: Profiler
|
|
|
$rootTagName = V::get('tag', '', $requestXmlTags[0]);
|
|
|
if ('Transaction' != $rootTagName) {
|
|
|
- throw new Exception("Parse Request xml error #" . __LINE__);
|
|
|
+ throw new Api_WfsException("Parse Request XML Error - Missing Transaction as root xml tag", __LINE__, null, 'TransactionParseError', 'request');
|
|
|
}
|
|
|
|
|
|
// 1. convert request: wfs.transaction.convert-wfs-request.xsl
|
|
|
@@ -649,18 +649,64 @@ class Api_WfsServerBase {
|
|
|
}
|
|
|
}
|
|
|
if (empty($usedSourceNsList)) {
|
|
|
- throw new Exception("Parse Request xml error #" . __LINE__ . ": not implemented");
|
|
|
+ throw new Api_WfsException("Parse Request XML Error - Empty source NS list", __LINE__, null, 'TransactionParseError', 'request');
|
|
|
}
|
|
|
|
|
|
$convertedTransaction = $this->_convertTransactionXml($requestXml, $usedSourceNsList);
|
|
|
if($DBG){echo 'L.' . __LINE__ . ' $convertedTransaction:';print_r($convertedTransaction);echo "\n";}
|
|
|
if (empty($convertedTransaction)) {
|
|
|
- throw new Exception("Parse Request xml error #" . __LINE__ . ": convert Transaction");
|
|
|
+ throw new Api_WfsException("Parse Request XML Error - Empty transaction", __LINE__, null, 'TransactionParseError', 'request');
|
|
|
}
|
|
|
-//echo "\ntags[0]:\n" . json_encode($requestXmlTags[0]) . "\n";
|
|
|
-//echo "\nconvertedTransaction:\n" . $convertedTransaction . "\n";
|
|
|
-//echo "\nsourceNsList:\n" . json_encode($sourceNsList) . "\n";
|
|
|
if (!$this->_validateConvertedTransactionXml($convertedTransaction, $usedSourceNsList)) {
|
|
|
+ // <Transaction version="1.0.0" service="WFS">
|
|
|
+ // <InsertNs0 typeName="TEST_PERMS">
|
|
|
+ // <ID>41</ID>
|
|
|
+ // <ADM_ADMIN_LEVEL>3</ADM_ADMIN_LEVEL>
|
|
|
+ // </InsertNs0>
|
|
|
+ // </Transaction>
|
|
|
+ $transXml = @simplexml_load_string($convertedTransaction);
|
|
|
+ foreach ($transXml->children() as $funcXml) {
|
|
|
+ $funcName = substr($funcXml->getName(), 0, 6);// Insert... , Update... , Delete...
|
|
|
+ if (empty($funcXml['typeName'][0])) throw new Api_WfsException("Missing typeName for function '{$funcName}'", __LINE__, null, 'MissingTypeName', 'request');
|
|
|
+ $typeName = $funcXml['typeName'][0];
|
|
|
+ $acl = $this->getAclFromTypeName("p5_default_db:{$typeName}");
|
|
|
+ $primaryKey = $acl->getPrimaryKeyField();
|
|
|
+ $pkObject = null;
|
|
|
+ foreach ($funcXml->children() as $fieldXml) {
|
|
|
+ if ($primaryKey == $fieldXml->getName()) $pkObject = $fieldXml[0];
|
|
|
+ }
|
|
|
+ if ('Insert' == $funcName && $pkObject) $funcName = 'Update';
|
|
|
+
|
|
|
+ if ('Update' == $funcName) {// check perm W - skip $primaryKey
|
|
|
+ if (!$pkObject) throw new Api_WfsException("Missing primary key ({$primaryKey}) for action Update", __LINE__, null, 'MissingPrimaryKey', 'request');
|
|
|
+ $toUpdateFields = array();
|
|
|
+ foreach ($funcXml->children() as $fieldXml) {
|
|
|
+ if ($primaryKey == $fieldXml->getName()) continue;// skip primary key
|
|
|
+ $toUpdateFields[] = $fieldXml->getName();
|
|
|
+ }
|
|
|
+ if (empty($toUpdateFields)) throw new Api_WfsException("Missing fields to update", __LINE__, null, 'MissingFieldToUpdate', 'request');
|
|
|
+ $oldObject = $acl->getItem($pkObject);
|
|
|
+ if (!$oldObject) throw new Api_WfsException("Object '{$typeName}.{$pkObject}' not exists", __LINE__, null, 'ObjectNotExists', 'request');
|
|
|
+ if (!$acl->canWriteRecord($oldObject) && !$acl->hasPermSuperWrite()) {
|
|
|
+ throw new Api_WfsException("Access Denied to Update object '{$typeName}.{$pkObject}'", __LINE__, null, 'MissingObjectPermUpdate', 'request');
|
|
|
+ }
|
|
|
+ foreach ($toUpdateFields as $fieldName) {
|
|
|
+ $aclIdFld = $acl->getFieldIdByName($fieldName);
|
|
|
+ if (!$acl->isAllowed($aclIdFld, 'W', $oldObject)) {
|
|
|
+ throw new Api_WfsException("Access Denied to Update field '{$fieldName}' in object '{$typeName}.{$pkObject}'", __LINE__, null, 'MissingFieldPermWrite', 'request');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if ('Insert' == $funcName) {// check perm C
|
|
|
+ foreach ($funcXml->children() as $fieldXml) {
|
|
|
+ $aclIdFld = $acl->getFieldIdByName($fieldXml->getName());
|
|
|
+ if (!$acl->isAllowed($aclIdFld, 'C')) {
|
|
|
+ throw new Api_WfsException("Access Denied to Create field '{$fieldName}' in object '{$typeName}.{$pkObject}'", __LINE__, null, 'MissingFieldPermCreate', 'request');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // TODO: Delete, ... ?
|
|
|
+ }
|
|
|
+ }
|
|
|
throw new Exception("Parse Request xml error #" . __LINE__ . ": schema validation failed");
|
|
|
}
|
|
|
|