Changeset 1994
- Timestamp:
- Sep 5, 2011, 2:31:10 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/RestController.groovy
r1992 r1994 334 334 * @param studyToken String The external study id (code) of the target GSCF Study object 335 335 * @param consumer consumer name of the calling module 336 * @param moduleURL URL of the calling module - NOTE: this is used as identifier for the module! 337 * The moduleURL that is passed on from the module should match exactly with the module URL that is specified in GSCF. 338 * Otherwise the module assays will not be visible. 339 * 336 340 * @return list of assays in the study as JSON object list, filtered to only contain assays 337 341 * for the specified module, with 'assayToken' and 'name' for each assay … … 366 370 */ 367 371 def getAssays = { 368 def moduleURL, moduleInet, assayModuleURL, assayModuleInet369 370 372 // Check which user has been logged in 371 373 def user = authenticationService.getRemotelyLoggedInUser( params.consumer, params.token ) … … 383 385 return 384 386 } 385 387 386 388 def assays = [] 387 389 388 390 if( params.studyToken ) { 391 389 392 def study = Study.findByStudyUUID(params.studyToken) 390 393 … … 425 428 426 429 // Create data for all assays 427 moduleURL = new URL(params.moduleURL)428 try {429 moduleInet = InetAddress.getByName(moduleURL.getHost())430 }431 catch(Exception e) {432 moduleInet = moduleURL.host433 }434 435 430 assays.each{ assay -> 436 /** 437 * assay.module.url does not necessarily have to match the moduleURL 438 * completely (e.g. when using a hosts file vs ip), especially when using 439 * localhost, 127.0.01 or a host name that aliasses localhost. 440 * 441 * Therefore we will resolve the host names and compare the resulting ip 442 * addresses and see if they match 443 * 444 * future improvement: do not use the module URL for matching at all. Perhaps 445 * a module identifier or a 'module token' would be better as this is not 446 * url dependant. 447 * 448 * check if: 449 * 1. we've for a module url 450 * 2. we've got an assay 451 * 3. the calling module is the same as the assay's module by checking if: 452 * a. the module urls match, or 453 * b. the (resolved) ip addresses and path part of the module's url match 454 */ 455 if ( 456 assay.module?.url && 457 assay && 458 ( 459 assay.module.url.equals(params.moduleURL) || 460 this.doesModuleMatch(assay, moduleURL, moduleInet) 461 ) 462 ) { 463 def map = [assayToken: assay.giveUUID()] 464 465 assay.giveFields().each { field -> 466 def name = field.name 467 def value = assay.getFieldValue(name) 468 map[name] = value 469 } 470 471 map["parentStudyToken"] = assay.parent.giveUUID() 472 returnList.push(map) 431 if (assay.module?.url && assay.module.url.equals(params.moduleURL)) { 432 if(assay) { 433 def map = [assayToken : assay.giveUUID()] 434 assay.giveFields().each { field -> 435 def name = field.name 436 def value = assay.getFieldValue( name ) 437 map[name] = value 438 } 439 map["parentStudyToken"] = assay.parent.giveUUID() 440 returnList.push( map ) 441 } 473 442 } 474 443 } 475 444 476 445 render returnList as JSON 477 }478 479 def doesModuleMatch = { assay, moduleURL, moduleInet ->480 481 try {482 483 // only resolve hosts if the urls do not match identically484 def assayModuleURL = new URL(assay.module.url)485 def assayModuleInet = InetAddress.getByName(assayModuleURL.getHost())486 487 return (488 moduleInet.hostAddress == assayModuleInet.hostAddress &&489 (moduleURL.path.replaceAll(/[^a-zA-Z0-9]/, "") == assayModuleURL.path.replaceAll(/[^a-zA-Z0-9]/, ""))490 )491 }492 catch (Exception e) {493 // If for some reason an error occurs (e.g. because the hostname is invalid and throws an UnknownHostException)494 // assume the calling module does not equal the assay module considered495 return false496 }497 446 } 498 447
Note: See TracChangeset
for help on using the changeset viewer.