Commit 3c3cb2f578c92590352900fdb75525892b18336b
1 parent
6e4eb47e
Fix problems with CMISSpaces browsing of KT repo via AtomPub
Committed by: Paul Barrett
Showing
4 changed files
with
238 additions
and
153 deletions
lib/api/ktcmis/ktcmis.inc.php
| ... | ... | @@ -69,12 +69,22 @@ class KTCMISBase { |
| 69 | 69 | static protected $ktapi; |
| 70 | 70 | static protected $session; |
| 71 | 71 | |
| 72 | -// public function __construct($username = null, $password = null) | |
| 73 | -// { | |
| 74 | -// $this->startSession($username, $password); | |
| 75 | -// } | |
| 72 | + public function __construct(&$ktapi = null, $username = null, $password = null) | |
| 73 | + { | |
| 74 | + // TODO confirm KTAPI instance active??? shouldn't really be responsibility of this code | |
| 75 | + if (is_null($ktapi) && (!is_null($username) && !is_null($password))) { | |
| 76 | +// echo ":WGHWTWGWGHW"; | |
| 77 | + $this->startSession($username, $password); | |
| 78 | + } | |
| 79 | + else { | |
| 80 | + self::$ktapi = $ktapi; | |
| 81 | + self::$session = self::$ktapi->get_session(); | |
| 82 | + } | |
| 83 | + } | |
| 76 | 84 | |
| 77 | - // TODO try to pick up existing session if possible, i.e. if the $session value is not empty | |
| 85 | + // TODO this probably does not belong here??? probably should require all auth external, handled by transport protocol. | |
| 86 | + // perhaps simple refusal to execute without valid session? | |
| 87 | + // NOTE left in to allow transport protocol to delegate auth to this level, but not actually used in any code at present | |
| 78 | 88 | public function startSession($username, $password) |
| 79 | 89 | { |
| 80 | 90 | // echo $username." :: ".$password."<BR>"; |
| ... | ... | @@ -103,6 +113,13 @@ class KTCMISBase { |
| 103 | 113 | return self::$session; |
| 104 | 114 | } |
| 105 | 115 | |
| 116 | + public function setInterface(&$ktapi = null) | |
| 117 | + { | |
| 118 | + if (!is_null($ktapi)) { | |
| 119 | + self::$ktapi = $ktapi; | |
| 120 | + } | |
| 121 | + } | |
| 122 | + | |
| 106 | 123 | public function getInterface() |
| 107 | 124 | { |
| 108 | 125 | return self::$ktapi; |
| ... | ... | @@ -263,10 +280,12 @@ class KTNavigationService extends KTCMISBase { |
| 263 | 280 | |
| 264 | 281 | protected $NavigationService; |
| 265 | 282 | |
| 266 | - public function __construct() | |
| 283 | + public function __construct(&$ktapi = null, $username = null, $password = null) | |
| 267 | 284 | { |
| 285 | + parent::__construct($ktapi, $username, $password); | |
| 268 | 286 | // instantiate underlying CMIS service |
| 269 | 287 | $this->NavigationService = new CMISNavigationService(); |
| 288 | + $this->setInterface(); | |
| 270 | 289 | } |
| 271 | 290 | |
| 272 | 291 | public function startSession($username, $password) |
| ... | ... | @@ -276,8 +295,9 @@ class KTNavigationService extends KTCMISBase { |
| 276 | 295 | return self::$session; |
| 277 | 296 | } |
| 278 | 297 | |
| 279 | - public function setInterface() | |
| 298 | + public function setInterface(&$ktapi = null) | |
| 280 | 299 | { |
| 300 | + parent::setInterface($ktapi); | |
| 281 | 301 | $this->NavigationService->setInterface(self::$ktapi); |
| 282 | 302 | } |
| 283 | 303 | |
| ... | ... | @@ -455,10 +475,12 @@ class KTObjectService extends KTCMISBase { |
| 455 | 475 | |
| 456 | 476 | protected $ObjectService; |
| 457 | 477 | |
| 458 | - public function __construct() | |
| 478 | + public function __construct(&$ktapi = null, $username = null, $password = null) | |
| 459 | 479 | { |
| 480 | + parent::__construct($ktapi, $username, $password); | |
| 460 | 481 | // instantiate underlying CMIS service |
| 461 | 482 | $this->ObjectService = new CMISObjectService(); |
| 483 | + $this->setInterface(); | |
| 462 | 484 | } |
| 463 | 485 | |
| 464 | 486 | public function startSession($username, $password) |
| ... | ... | @@ -468,8 +490,9 @@ class KTObjectService extends KTCMISBase { |
| 468 | 490 | return self::$session; |
| 469 | 491 | } |
| 470 | 492 | |
| 471 | - public function setInterface() | |
| 493 | + public function setInterface(&$ktapi = null) | |
| 472 | 494 | { |
| 495 | + parent::setInterface($ktapi); | |
| 473 | 496 | $this->ObjectService->setInterface(self::$ktapi); |
| 474 | 497 | } |
| 475 | 498 | ... | ... |
webservice/atompub/cmis/KT_cmis_atom_server.services.inc.php
| ... | ... | @@ -18,16 +18,16 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { |
| 18 | 18 | public function GET_action() |
| 19 | 19 | { |
| 20 | 20 | $RepositoryService = new RepositoryService(); |
| 21 | - try { | |
| 22 | - $RepositoryService->startSession(self::$authData['username'], self::$authData['password']); | |
| 23 | - } | |
| 24 | - catch (Exception $e) | |
| 25 | - { | |
| 26 | - $this->headers[] = 'WWW-Authenticate: Basic realm="KnowledgeTree Secure Area"'; | |
| 27 | - $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_NOT_AUTHENTICATED, $e->getMessage()); | |
| 28 | - $this->responseFeed = $feed; | |
| 29 | - return null; | |
| 30 | - } | |
| 21 | +// try { | |
| 22 | +// $RepositoryService->startSession(self::$authData['username'], self::$authData['password']); | |
| 23 | +// } | |
| 24 | +// catch (Exception $e) | |
| 25 | +// { | |
| 26 | +// $this->headers[] = 'WWW-Authenticate: Basic realm="KnowledgeTree Secure Area"'; | |
| 27 | +// $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_NOT_AUTHENTICATED, $e->getMessage()); | |
| 28 | +// $this->responseFeed = $feed; | |
| 29 | +// return null; | |
| 30 | +// } | |
| 31 | 31 | |
| 32 | 32 | $repositories = $RepositoryService->getRepositories(); |
| 33 | 33 | $repositoryId = $repositories[0]['repositoryId']; |
| ... | ... | @@ -43,24 +43,24 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { |
| 43 | 43 | } |
| 44 | 44 | else if ($this->params[0] == 'path') |
| 45 | 45 | { |
| 46 | - $ktapi =& $RepositoryService->getInterface(); | |
| 46 | + $ktapi =& KT_cmis_atom_service_helper::getKt(); | |
| 47 | 47 | $folderId = KT_cmis_atom_service_helper::getFolderId($this->params, $ktapi); |
| 48 | 48 | } |
| 49 | 49 | else |
| 50 | 50 | { |
| 51 | 51 | $folderId = $this->params[0]; |
| 52 | - $ObjectService = new ObjectService(); | |
| 53 | - | |
| 54 | - try { | |
| 55 | - $ObjectService->startSession(self::$authData['username'], self::$authData['password']); | |
| 56 | - } | |
| 57 | - catch (Exception $e) | |
| 58 | - { | |
| 59 | - $this->headers[] = 'WWW-Authenticate: Basic realm="KnowledgeTree Secure Area"'; | |
| 60 | - $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_NOT_AUTHENTICATED, $e->getMessage()); | |
| 61 | - $this->responseFeed = $feed; | |
| 62 | - return null; | |
| 63 | - } | |
| 52 | + $ObjectService = new ObjectService(KT_cmis_atom_service_helper::getKt()); | |
| 53 | + | |
| 54 | +// try { | |
| 55 | +// $ObjectService->startSession(self::$authData['username'], self::$authData['password']); | |
| 56 | +// } | |
| 57 | +// catch (Exception $e) | |
| 58 | +// { | |
| 59 | +// $this->headers[] = 'WWW-Authenticate: Basic realm="KnowledgeTree Secure Area"'; | |
| 60 | +// $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_NOT_AUTHENTICATED, $e->getMessage()); | |
| 61 | +// $this->responseFeed = $feed; | |
| 62 | +// return null; | |
| 63 | +// } | |
| 64 | 64 | |
| 65 | 65 | $cmisEntry = $ObjectService->getProperties($repositoryId, $folderId, false, false); |
| 66 | 66 | $folderName = $cmisEntry['properties']['Name']['value']; |
| ... | ... | @@ -69,35 +69,35 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { |
| 69 | 69 | |
| 70 | 70 | if (!empty($this->params[1]) && (($this->params[1] == 'children') || ($this->params[1] == 'descendants'))) |
| 71 | 71 | { |
| 72 | - $NavigationService = new NavigationService(); | |
| 73 | - | |
| 74 | - try { | |
| 75 | - $NavigationService->startSession(self::$authData['username'], self::$authData['password']); | |
| 76 | - } | |
| 77 | - catch (Exception $e) | |
| 78 | - { | |
| 79 | - $this->headers[] = 'WWW-Authenticate: Basic realm="KnowledgeTree Secure Area"'; | |
| 80 | - $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_NOT_AUTHENTICATED, $e->getMessage()); | |
| 81 | - $this->responseFeed = $feed; | |
| 82 | - return null; | |
| 83 | - } | |
| 72 | + $NavigationService = new NavigationService(KT_cmis_atom_service_helper::getKt()); | |
| 73 | + | |
| 74 | +// try { | |
| 75 | +// $NavigationService->startSession(self::$authData['username'], self::$authData['password']); | |
| 76 | +// } | |
| 77 | +// catch (Exception $e) | |
| 78 | +// { | |
| 79 | +// $this->headers[] = 'WWW-Authenticate: Basic realm="KnowledgeTree Secure Area"'; | |
| 80 | +// $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_NOT_AUTHENTICATED, $e->getMessage()); | |
| 81 | +// $this->responseFeed = $feed; | |
| 82 | +// return null; | |
| 83 | +// } | |
| 84 | 84 | |
| 85 | 85 | $feed = $this->getFolderChildrenFeed($NavigationService, $repositoryId, $folderId, $folderName, $this->params[1]); |
| 86 | 86 | } |
| 87 | 87 | else |
| 88 | 88 | { |
| 89 | - $ObjectService = new ObjectService(); | |
| 90 | - | |
| 91 | - try { | |
| 92 | - $ObjectService->startSession(self::$authData['username'], self::$authData['password']); | |
| 93 | - } | |
| 94 | - catch (Exception $e) | |
| 95 | - { | |
| 96 | - $this->headers[] = 'WWW-Authenticate: Basic realm="KnowledgeTree Secure Area"'; | |
| 97 | - $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_NOT_AUTHENTICATED, $e->getMessage()); | |
| 98 | - $this->responseFeed = $feed; | |
| 99 | - return null; | |
| 100 | - } | |
| 89 | + $ObjectService = new ObjectService(KT_cmis_atom_service_helper::getKt()); | |
| 90 | + | |
| 91 | +// try { | |
| 92 | +// $ObjectService->startSession(self::$authData['username'], self::$authData['password']); | |
| 93 | +// } | |
| 94 | +// catch (Exception $e) | |
| 95 | +// { | |
| 96 | +// $this->headers[] = 'WWW-Authenticate: Basic realm="KnowledgeTree Secure Area"'; | |
| 97 | +// $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_NOT_AUTHENTICATED, $e->getMessage()); | |
| 98 | +// $this->responseFeed = $feed; | |
| 99 | +// return null; | |
| 100 | +// } | |
| 101 | 101 | |
| 102 | 102 | $feed = $this->getFolderFeed($ObjectService, $repositoryId, $folderId); |
| 103 | 103 | } |
| ... | ... | @@ -110,16 +110,16 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { |
| 110 | 110 | { |
| 111 | 111 | $RepositoryService = new RepositoryService(); |
| 112 | 112 | |
| 113 | - try { | |
| 114 | - $RepositoryService->startSession(self::$authData['username'], self::$authData['password']); | |
| 115 | - } | |
| 116 | - catch (Exception $e) | |
| 117 | - { | |
| 118 | - $this->headers[] = 'WWW-Authenticate: Basic realm="KnowledgeTree Secure Area"'; | |
| 119 | - $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_NOT_AUTHENTICATED, $e->getMessage()); | |
| 120 | - $this->responseFeed = $feed; | |
| 121 | - return null; | |
| 122 | - } | |
| 113 | +// try { | |
| 114 | +// $RepositoryService->startSession(self::$authData['username'], self::$authData['password']); | |
| 115 | +// } | |
| 116 | +// catch (Exception $e) | |
| 117 | +// { | |
| 118 | +// $this->headers[] = 'WWW-Authenticate: Basic realm="KnowledgeTree Secure Area"'; | |
| 119 | +// $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_NOT_AUTHENTICATED, $e->getMessage()); | |
| 120 | +// $this->responseFeed = $feed; | |
| 121 | +// return null; | |
| 122 | +// } | |
| 123 | 123 | |
| 124 | 124 | $repositories = $RepositoryService->getRepositories(); |
| 125 | 125 | $repositoryId = $repositories[0]['repositoryId']; |
| ... | ... | @@ -158,18 +158,18 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { |
| 158 | 158 | [0]['@children']['cmis:properties'] |
| 159 | 159 | [0]['@children']); |
| 160 | 160 | |
| 161 | - $ObjectService = new ObjectService(); | |
| 161 | + $ObjectService = new ObjectService(KT_cmis_atom_service_helper::getKt()); | |
| 162 | 162 | |
| 163 | - try { | |
| 164 | - $ObjectService->startSession(self::$authData['username'], self::$authData['password']); | |
| 165 | - } | |
| 166 | - catch (Exception $e) | |
| 167 | - { | |
| 168 | - $this->headers[] = 'WWW-Authenticate: Basic realm="KnowledgeTree Secure Area"'; | |
| 169 | - $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_NOT_AUTHENTICATED, $e->getMessage()); | |
| 170 | - $this->responseFeed = $feed; | |
| 171 | - return null; | |
| 172 | - } | |
| 163 | +// try { | |
| 164 | +// $ObjectService->startSession(self::$authData['username'], self::$authData['password']); | |
| 165 | +// } | |
| 166 | +// catch (Exception $e) | |
| 167 | +// { | |
| 168 | +// $this->headers[] = 'WWW-Authenticate: Basic realm="KnowledgeTree Secure Area"'; | |
| 169 | +// $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_NOT_AUTHENTICATED, $e->getMessage()); | |
| 170 | +// $this->responseFeed = $feed; | |
| 171 | +// return null; | |
| 172 | +// } | |
| 173 | 173 | |
| 174 | 174 | if ($type == 'folder') |
| 175 | 175 | $newObjectId = $ObjectService->createFolder($repositoryId, ucwords($cmisObjectProperties['ObjectTypeId']), $properties, $folderId); |
| ... | ... | @@ -187,18 +187,18 @@ class KT_cmis_atom_service_folder extends KT_cmis_atom_service { |
| 187 | 187 | } |
| 188 | 188 | else |
| 189 | 189 | { |
| 190 | - $NavigationService = new NavigationService(); | |
| 191 | - | |
| 192 | - try { | |
| 193 | - $NavigationService->startSession(self::$authData['username'], self::$authData['password']); | |
| 194 | - } | |
| 195 | - catch (Exception $e) | |
| 196 | - { | |
| 197 | - $this->headers[] = 'WWW-Authenticate: Basic realm="KnowledgeTree Secure Area"'; | |
| 198 | - $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_NOT_AUTHENTICATED, $e->getMessage()); | |
| 199 | - $this->responseFeed = $feed; | |
| 200 | - return null; | |
| 201 | - } | |
| 190 | + $NavigationService = new NavigationService(KT_cmis_atom_service_helper::getKt()); | |
| 191 | + | |
| 192 | +// try { | |
| 193 | +// $NavigationService->startSession(self::$authData['username'], self::$authData['password']); | |
| 194 | +// } | |
| 195 | +// catch (Exception $e) | |
| 196 | +// { | |
| 197 | +// $this->headers[] = 'WWW-Authenticate: Basic realm="KnowledgeTree Secure Area"'; | |
| 198 | +// $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_NOT_AUTHENTICATED, $e->getMessage()); | |
| 199 | +// $this->responseFeed = $feed; | |
| 200 | +// return null; | |
| 201 | +// } | |
| 202 | 202 | |
| 203 | 203 | $cmisEntry = $ObjectService->getProperties($repositoryId, $folderId, false, false); |
| 204 | 204 | $feed = $this->getFolderChildrenFeed($NavigationService, $repositoryId, $folderId, $cmisEntry['properties']['Name']['value']); |
| ... | ... | @@ -292,16 +292,16 @@ class KT_cmis_atom_service_types extends KT_cmis_atom_service { |
| 292 | 292 | { |
| 293 | 293 | $RepositoryService = new RepositoryService(); |
| 294 | 294 | |
| 295 | - try { | |
| 296 | - $RepositoryService->startSession(self::$authData['username'], self::$authData['password']); | |
| 297 | - } | |
| 298 | - catch (Exception $e) | |
| 299 | - { | |
| 300 | - $this->headers[] = 'WWW-Authenticate: Basic realm="KnowledgeTree Secure Area"'; | |
| 301 | - $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_NOT_AUTHENTICATED, $e->getMessage()); | |
| 302 | - $this->responseFeed = $feed; | |
| 303 | - return null; | |
| 304 | - } | |
| 295 | +// try { | |
| 296 | +// $RepositoryService->startSession(self::$authData['username'], self::$authData['password']); | |
| 297 | +// } | |
| 298 | +// catch (Exception $e) | |
| 299 | +// { | |
| 300 | +// $this->headers[] = 'WWW-Authenticate: Basic realm="KnowledgeTree Secure Area"'; | |
| 301 | +// $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_NOT_AUTHENTICATED, $e->getMessage()); | |
| 302 | +// $this->responseFeed = $feed; | |
| 303 | +// return null; | |
| 304 | +// } | |
| 305 | 305 | |
| 306 | 306 | // fetch repository id |
| 307 | 307 | $repositories = $RepositoryService->getRepositories(); |
| ... | ... | @@ -329,16 +329,16 @@ class KT_cmis_atom_service_type extends KT_cmis_atom_service { |
| 329 | 329 | { |
| 330 | 330 | $RepositoryService = new RepositoryService(); |
| 331 | 331 | |
| 332 | - try { | |
| 333 | - $RepositoryService->startSession(self::$authData['username'], self::$authData['password']); | |
| 334 | - } | |
| 335 | - catch (Exception $e) | |
| 336 | - { | |
| 337 | - $this->headers[] = 'WWW-Authenticate: Basic realm="KnowledgeTree Secure Area"'; | |
| 338 | - $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_NOT_AUTHENTICATED, $e->getMessage()); | |
| 339 | - $this->responseFeed = $feed; | |
| 340 | - return null; | |
| 341 | - } | |
| 332 | +// try { | |
| 333 | +// $RepositoryService->startSession(self::$authData['username'], self::$authData['password']); | |
| 334 | +// } | |
| 335 | +// catch (Exception $e) | |
| 336 | +// { | |
| 337 | +// $this->headers[] = 'WWW-Authenticate: Basic realm="KnowledgeTree Secure Area"'; | |
| 338 | +// $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_NOT_AUTHENTICATED, $e->getMessage()); | |
| 339 | +// $this->responseFeed = $feed; | |
| 340 | +// return null; | |
| 341 | +// } | |
| 342 | 342 | |
| 343 | 343 | // fetch repository id |
| 344 | 344 | $repositories = $RepositoryService->getRepositories(); |
| ... | ... | @@ -432,18 +432,18 @@ class KT_cmis_atom_service_checkedout extends KT_cmis_atom_service { |
| 432 | 432 | public function GET_action() |
| 433 | 433 | { |
| 434 | 434 | $RepositoryService = new RepositoryService(); |
| 435 | - $NavigationService = new NavigationService(); | |
| 436 | - | |
| 437 | - try { | |
| 438 | - $NavigationService->startSession(self::$authData['username'], self::$authData['password']); | |
| 439 | - } | |
| 440 | - catch (Exception $e) | |
| 441 | - { | |
| 442 | - $this->headers[] = 'WWW-Authenticate: Basic realm="KnowledgeTree Secure Area"'; | |
| 443 | - $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_NOT_AUTHENTICATED, $e->getMessage()); | |
| 444 | - $this->responseFeed = $feed; | |
| 445 | - return null; | |
| 446 | - } | |
| 435 | + $NavigationService = new NavigationService(KT_cmis_atom_service_helper::getKt()); | |
| 436 | + | |
| 437 | +// try { | |
| 438 | +// $NavigationService->startSession(self::$authData['username'], self::$authData['password']); | |
| 439 | +// } | |
| 440 | +// catch (Exception $e) | |
| 441 | +// { | |
| 442 | +// $this->headers[] = 'WWW-Authenticate: Basic realm="KnowledgeTree Secure Area"'; | |
| 443 | +// $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_NOT_AUTHENTICATED, $e->getMessage()); | |
| 444 | +// $this->responseFeed = $feed; | |
| 445 | +// return null; | |
| 446 | +// } | |
| 447 | 447 | |
| 448 | 448 | $repositories = $RepositoryService->getRepositories(); |
| 449 | 449 | $repositoryId = $repositories[0]['repositoryId']; |
| ... | ... | @@ -491,19 +491,18 @@ class KT_cmis_atom_service_document extends KT_cmis_atom_service { |
| 491 | 491 | public function GET_action() |
| 492 | 492 | { |
| 493 | 493 | $RepositoryService = new RepositoryService(); |
| 494 | - | |
| 495 | - $ObjectService = new ObjectService(); | |
| 496 | - | |
| 497 | - try { | |
| 498 | - $ObjectService->startSession(self::$authData['username'], self::$authData['password']); | |
| 499 | - } | |
| 500 | - catch (Exception $e) | |
| 501 | - { | |
| 502 | - $this->headers[] = 'WWW-Authenticate: Basic realm="KnowledgeTree Secure Area"'; | |
| 503 | - $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_NOT_AUTHENTICATED, $e->getMessage()); | |
| 504 | - $this->responseFeed = $feed; | |
| 505 | - return null; | |
| 506 | - } | |
| 494 | + $ObjectService = new ObjectService(KT_cmis_atom_service_helper::getKt()); | |
| 495 | + | |
| 496 | +// try { | |
| 497 | +// $ObjectService->startSession(self::$authData['username'], self::$authData['password']); | |
| 498 | +// } | |
| 499 | +// catch (Exception $e) | |
| 500 | +// { | |
| 501 | +// $this->headers[] = 'WWW-Authenticate: Basic realm="KnowledgeTree Secure Area"'; | |
| 502 | +// $feed = KT_cmis_atom_service_helper::getErrorFeed($this, self::STATUS_NOT_AUTHENTICATED, $e->getMessage()); | |
| 503 | +// $this->responseFeed = $feed; | |
| 504 | +// return null; | |
| 505 | +// } | |
| 507 | 506 | |
| 508 | 507 | $repositories = $RepositoryService->getRepositories(); |
| 509 | 508 | $repositoryId = $repositories[0]['repositoryId']; | ... | ... |
webservice/atompub/cmis/KT_cmis_atom_service_helper.inc.php
| ... | ... | @@ -2,6 +2,8 @@ |
| 2 | 2 | |
| 3 | 3 | class KT_cmis_atom_service_helper { |
| 4 | 4 | |
| 5 | + protected static $kt = null; | |
| 6 | + | |
| 5 | 7 | /** |
| 6 | 8 | * Creates an AtomPub entry for a CMIS entry and adds it to the supplied feed |
| 7 | 9 | * |
| ... | ... | @@ -148,7 +150,7 @@ class KT_cmis_atom_service_helper { |
| 148 | 150 | $feedElement = $feed->newElement('cmis:' . strtolower($type['typeId']) . 'Type'); |
| 149 | 151 | foreach($type as $property => $value) |
| 150 | 152 | { |
| 151 | - $feed->newField($property, CMISUtil::boolToString($value), $feedElement); | |
| 153 | + $feed->newField('cmis:' . $property, CMISUtil::boolToString($value), $feedElement); | |
| 152 | 154 | } |
| 153 | 155 | |
| 154 | 156 | $entry->appendChild($feedElement); |
| ... | ... | @@ -173,7 +175,7 @@ class KT_cmis_atom_service_helper { |
| 173 | 175 | * @param array $path |
| 174 | 176 | * @param object $ktapi KTAPI instance |
| 175 | 177 | */ |
| 176 | - // TODO make this much more efficient than this messy method | |
| 178 | + // TODO make this much more efficient than this method | |
| 177 | 179 | static public function getFolderId($path, &$ktapi) |
| 178 | 180 | { |
| 179 | 181 | // lose first item |
| ... | ... | @@ -224,6 +226,64 @@ class KT_cmis_atom_service_helper { |
| 224 | 226 | return null; |
| 225 | 227 | } |
| 226 | 228 | |
| 229 | + /** | |
| 230 | + * Log in to KT easily | |
| 231 | + * | |
| 232 | + * @param string $username | |
| 233 | + * @param string $password | |
| 234 | + * @param string $ip | |
| 235 | + * @return object Containing the status_code of the login and session id | |
| 236 | + */ | |
| 237 | + function login($username, $password, $ip=null){ | |
| 238 | + $kt = self::getKt(); | |
| 239 | + | |
| 240 | + $session = $kt->start_session($username,$password, $ip); | |
| 241 | + if (PEAR::isError($session)){ | |
| 242 | + $response['status_code']=KT_atom_server_FAILURE; | |
| 243 | + $response['session_id']=''; | |
| 244 | + }else{ | |
| 245 | + $session= $session->get_session(); | |
| 246 | + $response['status_code'] = KT_atom_server_SUCCESS; | |
| 247 | + $response['session_id'] = $session; | |
| 248 | + } | |
| 249 | + return $response; | |
| 250 | + } | |
| 251 | + | |
| 252 | + | |
| 253 | + /** | |
| 254 | + * Log out of KT using the session id | |
| 255 | + * | |
| 256 | + * @param string $session_id | |
| 257 | + * @return object Containing the status_code of the logout attempt | |
| 258 | + */ | |
| 259 | + function logout($session_id){ | |
| 260 | + $kt = self::getKt(); | |
| 261 | + $session = $kt->get_active_session($session_id, null); | |
| 262 | + | |
| 263 | + if (PEAR::isError($session)){ | |
| 264 | + $response['status_code']=KT_atom_server_FAILURE; | |
| 265 | + }else{ | |
| 266 | + $session->logout(); | |
| 267 | + $response['status_code'] = KT_atom_server_SUCCESS; | |
| 268 | + } | |
| 269 | + return $response; | |
| 270 | + } | |
| 271 | + | |
| 272 | + /** | |
| 273 | + * Get the KT singleton instance | |
| 274 | + * | |
| 275 | + * @return object | |
| 276 | + */ | |
| 277 | + public static function getKt() | |
| 278 | + { | |
| 279 | + if(!isset(self::$kt)) | |
| 280 | + { | |
| 281 | + self::$kt = new KTAPI(); | |
| 282 | + self::$kt->get_active_session(session_id()); | |
| 283 | + } | |
| 284 | + return self::$kt; | |
| 285 | + } | |
| 286 | + | |
| 227 | 287 | } |
| 228 | 288 | |
| 229 | 289 | ?> | ... | ... |
webservice/atompub/cmis/index.php
| ... | ... | @@ -40,6 +40,7 @@ |
| 40 | 40 | */ |
| 41 | 41 | |
| 42 | 42 | require_once('../../../config/dmsDefaults.php'); |
| 43 | +require_once(KT_DIR . '/ktapi/ktapi.inc.php'); | |
| 43 | 44 | |
| 44 | 45 | define('KT_APP_BASE_URI', "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/?/'); |
| 45 | 46 | define('KT_APP_SYSTEM_URI', "http://".$_SERVER['HTTP_HOST']); |
| ... | ... | @@ -50,12 +51,6 @@ define('CMIS_APP_BASE_URI', trim(KT_APP_BASE_URI, '/')); |
| 50 | 51 | define('CMIS_APP_SYSTEM_URI', KT_APP_SYSTEM_URI); |
| 51 | 52 | define('CMIS_ATOM_LIB_FOLDER', trim(KT_ATOM_LIB_FOLDER, '/') . '/cmis/'); |
| 52 | 53 | |
| 53 | -// fetch username and password for auth; note that this apparently only works when PHP is run as an apache module | |
| 54 | -// TODO method to fetch username and password when running PHP as CGI, if possible | |
| 55 | -// HTTP Basic Auth: | |
| 56 | -//$username = $_SERVER['PHP_AUTH_USER']; | |
| 57 | -//$password = $_SERVER['PHP_AUTH_PW']; | |
| 58 | - | |
| 59 | 54 | /** |
| 60 | 55 | * Includes |
| 61 | 56 | */ |
| ... | ... | @@ -67,15 +62,21 @@ include_once(CMIS_ATOM_LIB_FOLDER.'KT_cmis_atom_serviceDoc.inc.php'); / |
| 67 | 62 | include_once(CMIS_ATOM_LIB_FOLDER.'KT_cmis_atom_service.inc.php'); //Containing the servicedoc class allowing easy ServiceDocument generation |
| 68 | 63 | |
| 69 | 64 | include_once('KT_cmis_atom_server.services.inc.php'); |
| 65 | + | |
| 66 | +KT_cmis_atom_service_helper::login('admin', 'admin'); | |
| 67 | + | |
| 70 | 68 | //Start the AtomPubProtocol Routing Engine |
| 71 | 69 | $APP = new KT_cmis_atom_server(); |
| 72 | 70 | |
| 73 | -// FIXME HACK! this should not happen every time, ONLY on a service doc request | |
| 74 | -// CMIS service document setup | |
| 75 | -$APP->initServiceDocument(); | |
| 76 | -// FIXME HACK! this should not happen every time, ONLY on a service doc request | |
| 77 | -// User defined title tag | |
| 78 | -$APP->addWorkspaceTag('dms','atom:title',$APP->repositoryInfo['repositoryName']); | |
| 71 | +$queryArray = split('/', trim($_SERVER['QUERY_STRING'], '/')); | |
| 72 | +$workspace = strtolower(trim($queryArray[0])); | |
| 73 | +if ($workspace == 'servicedocument') | |
| 74 | +{ | |
| 75 | + // CMIS service document setup | |
| 76 | + $APP->initServiceDocument(); | |
| 77 | + // User defined title tag | |
| 78 | + $APP->addWorkspaceTag('dms','atom:title',$APP->repositoryInfo['repositoryName']); | |
| 79 | +} | |
| 79 | 80 | |
| 80 | 81 | /** |
| 81 | 82 | * Register Services |
| ... | ... | @@ -102,11 +103,13 @@ $APP->registerService('dms', 'types', 'KT_cmis_atom_service_types', 'Object Type |
| 102 | 103 | // FIXME HACK! this should not happen every time, ONLY on a specific request, should NOT appear in service document as this is not definable at that time; |
| 103 | 104 | // SHOULD be appearing in types listing feed |
| 104 | 105 | // NOTE $requestParams is meaningless if not actually requesting this service, so not a good way to register the service really |
| 105 | -$queryArray=split('/',trim($_SERVER['QUERY_STRING'],'/')); | |
| 106 | -$requestParams=array_slice($queryArray,2); | |
| 107 | -$APP->registerService('dms', 'type', 'KT_cmis_atom_service_type', 'Object Type Collection', explode('/', $requestParams), 'types-descendants'); | |
| 108 | -// FIXME HACK! see above, this one for documents | |
| 109 | -$APP->registerService('dms', 'document', 'KT_cmis_atom_service_document', 'Object Type Collection', explode('/', $requestParams), 'types-descendants'); | |
| 106 | +if ($workspace != 'servicedocument') | |
| 107 | +{ | |
| 108 | + // should check this per workspace??? | |
| 109 | + $APP->registerService('dms', 'type', 'KT_cmis_atom_service_type', 'Object Type Collection', explode('/', $requestParams), 'types-descendants'); | |
| 110 | + // FIXME HACK! see above, this one for documents | |
| 111 | + $APP->registerService('dms', 'document', 'KT_cmis_atom_service_document', 'Object Type Collection', explode('/', $requestParams), 'types-descendants'); | |
| 112 | +} | |
| 110 | 113 | |
| 111 | 114 | //Execute the current url/header request |
| 112 | 115 | $APP->execute(); | ... | ... |