/components/client/test/ome/client/itests/sec/ReadSecurityTest.java

https://github.com/jianguo11/openmicroscopy · Java · 894 lines · 660 code · 128 blank · 106 comment · 41 complexity · fdd66d8f4ed20deff5d045cd2aa3b8f1 MD5 · raw file

  1. /*
  2. * $Id$
  3. *
  4. * Copyright 2006 University of Dundee. All rights reserved.
  5. * Use is subject to license terms supplied in LICENSE.txt
  6. */
  7. package ome.client.itests.sec;
  8. import ome.conditions.SecurityViolation;
  9. import ome.model.acquisition.Instrument;
  10. import ome.model.containers.Dataset;
  11. import ome.model.containers.Project;
  12. import ome.model.containers.ProjectDatasetLink;
  13. import ome.model.core.Image;
  14. import ome.model.core.Pixels;
  15. import ome.model.display.Thumbnail;
  16. import ome.parameters.Parameters;
  17. import ome.system.ServiceFactory;
  18. import org.testng.annotations.Test;
  19. @Test(groups = { "ticket:200", "security", "integration" })
  20. public class ReadSecurityTest extends AbstractPermissionsTest {
  21. /**
  22. * due to permission restrictions, certain user combinations will not be
  23. * able to even create the needed test instances. this provides a check for
  24. * that.
  25. */
  26. boolean canCreate;
  27. // ~ single
  28. // =========================================================================
  29. @Override
  30. public void testSingleProject_U() throws Exception {
  31. ownsfA = u;
  32. ownerA = user;
  33. groupA = user_other_group;
  34. // RW_xx_xx : should not be readable by anyone but user.
  35. permsA = RW_xx_xx;
  36. canCreate = true;
  37. single(u, true);
  38. single(o, false);
  39. single(w, false);
  40. single(p, true);
  41. single(r, true);
  42. // RW_RW_xx : now let's up the readability
  43. permsA = RW_RW_xx;
  44. canCreate = true;
  45. single(u, true);
  46. single(o, true);
  47. single(w, false);
  48. single(p, true);
  49. single(r, true);
  50. // RW_RW_RW : now let's up the readability one more time
  51. permsA = RW_RW_RW;
  52. canCreate = true;
  53. single(u, true);
  54. single(o, true);
  55. single(w, true);
  56. single(p, true);
  57. single(r, true);
  58. // xx_xx_xx : and if we make it invisible
  59. permsA = xx_xx_xx;
  60. canCreate = true;
  61. single(u, false);
  62. single(o, false);
  63. single(w, false);
  64. single(p, true);
  65. single(r, true);
  66. }
  67. // don't need to test for OTHER because OTHER and USER are symmetric.
  68. @Override
  69. public void testSingleProject_W() throws Exception {
  70. ownsfA = w;
  71. ownerA = world;
  72. groupA = common_group;
  73. // RW_xx_xx : should not be readable by anyone but world.
  74. permsA = RW_xx_xx;
  75. canCreate = true;
  76. single(u, false);
  77. single(o, false);
  78. single(w, true);
  79. single(p, false);
  80. single(r, true);
  81. // RW_RW_xx : now let's up the readability
  82. permsA = RW_RW_xx;
  83. canCreate = true;
  84. single(u, true);
  85. single(o, true);
  86. single(w, true);
  87. single(p, true);
  88. single(r, true);
  89. // RW_RW_RW : now let's up the readability one more time
  90. permsA = RW_RW_RW;
  91. canCreate = true;
  92. single(u, true);
  93. single(o, true);
  94. single(w, true);
  95. single(p, true);
  96. single(r, true);
  97. // xx_xx_xx : and if we make it invisible
  98. permsA = xx_xx_xx;
  99. canCreate = true;
  100. single(u, false);
  101. single(o, false);
  102. single(w, false);
  103. single(p, false);
  104. single(r, true);
  105. }
  106. // don't need to test PI because acts just like a group member
  107. @Override
  108. public void testSingleProject_R() throws Exception {
  109. ownsfA = r;
  110. ownerA = root;
  111. groupA = system_group;
  112. // RW_xx_xx : should not be readable by anyone but world.
  113. permsA = RW_xx_xx;
  114. canCreate = true;
  115. single(u, false);
  116. single(o, false);
  117. single(w, false);
  118. single(p, false);
  119. single(r, true);
  120. // RW_RW_xx : now let's up the readability
  121. permsA = RW_RW_xx;
  122. canCreate = true;
  123. single(u, false);
  124. single(o, false);
  125. single(w, false);
  126. single(p, false);
  127. single(r, true);
  128. // RW_RW_RW : now let's up the readability one more time
  129. permsA = RW_RW_RW;
  130. canCreate = true;
  131. single(u, true);
  132. single(o, true);
  133. single(w, true);
  134. single(p, true);
  135. single(r, true);
  136. // xx_xx_xx : and if we make it invisible
  137. permsA = xx_xx_xx;
  138. canCreate = true;
  139. single(u, false);
  140. single(o, false);
  141. single(w, false);
  142. single(p, false);
  143. single(r, true);
  144. }
  145. /**
  146. * performs various types of Omero lookups for a particular user proxied by
  147. * a {@link ServiceFactory}. If ok is true, then the lookups should
  148. * succeed.
  149. */
  150. protected void single(ServiceFactory sf, boolean ok) {
  151. createProject(ownsfA, permsA, groupA);
  152. verifyDetails(prj, ownerA, groupA, permsA);
  153. Project t;
  154. try {
  155. t = sf.getQueryService().find(Project.class, prj.getId());
  156. assertNotNull(t);
  157. } catch (SecurityViolation e) {
  158. if (ok) {
  159. throw e;
  160. }
  161. }
  162. String q = "select p from Project p where p.id = :id";
  163. Parameters param = new Parameters().addId(prj.getId());
  164. t = sf.getQueryService().findByQuery(q, param);
  165. if (ok) {
  166. assertNotNull(t);
  167. } else {
  168. assertNull(t);
  169. }
  170. }
  171. // ~ bidirectional one-to-many
  172. // =========================================================================
  173. @Override
  174. public void test_U_Pixels_And_U_Thumbnails() throws Exception {
  175. ownsfA = ownsfB = u;
  176. ownerA = ownerB = user;
  177. groupA = groupB = user_other_group;
  178. // RW_RW_RW / RW_RW_RW
  179. permsA = RW_RW_RW;
  180. permsB = RW_RW_RW;
  181. canCreate = true;
  182. oneToMany(u, true, true);
  183. oneToMany(o, true, true);
  184. oneToMany(w, true, true);
  185. oneToMany(p, true, true);
  186. oneToMany(r, true, true);
  187. // RW_RW_RW / RW_RW_xx : now lets lower visibility
  188. // thumbnail readable by other but not by world
  189. permsA = RW_RW_RW;
  190. permsB = RW_RW_xx;
  191. canCreate = true;
  192. oneToMany(u, true, true);
  193. oneToMany(o, true, true);
  194. oneToMany(w, true, false);
  195. oneToMany(p, true, true);
  196. oneToMany(r, true, true);
  197. // RW_RW_RW / RW_xx_xx
  198. permsA = RW_RW_RW;
  199. permsB = RW_xx_xx;
  200. canCreate = true;
  201. oneToMany(u, true, true);
  202. oneToMany(o, true, false);
  203. oneToMany(w, true, false);
  204. oneToMany(p, true, true);
  205. oneToMany(r, true, true);
  206. // RW_RW_RW / xx_xx_xx
  207. permsA = RW_RW_RW;
  208. permsB = xx_xx_xx;
  209. canCreate = true;
  210. oneToMany(u, true, false);
  211. oneToMany(o, true, false);
  212. oneToMany(w, true, false);
  213. oneToMany(p, true, true);
  214. oneToMany(r, true, true);
  215. // RW_RW_xx / RW_RW_xx
  216. permsA = RW_RW_xx;
  217. permsB = RW_RW_xx;
  218. canCreate = true;
  219. oneToMany(u, true, true);
  220. oneToMany(o, true, true);
  221. oneToMany(w, false, false);
  222. oneToMany(p, true, true);
  223. oneToMany(r, true, true);
  224. // RW_xx_xx / RW_xx_xx
  225. permsA = RW_xx_xx;
  226. permsB = RW_xx_xx;
  227. canCreate = true;
  228. oneToMany(u, true, true);
  229. oneToMany(o, false, false);
  230. oneToMany(w, false, false);
  231. oneToMany(p, true, true);
  232. oneToMany(r, true, true);
  233. // xx_xx_xx / xx_xx_xx
  234. permsA = xx_xx_xx;
  235. permsB = xx_xx_xx;
  236. canCreate = false;
  237. oneToMany(u, false, false);
  238. oneToMany(o, false, false);
  239. oneToMany(w, false, false);
  240. oneToMany(p, true, true);
  241. oneToMany(r, true, true);
  242. }
  243. @Override
  244. public void test_O_Pixels_And_U_Thumbnails() throws Exception {
  245. ownsfA = o;
  246. ownerA = other;
  247. groupA = user_other_group;
  248. ownsfB = u;
  249. ownerB = user;
  250. groupB = user_other_group;
  251. // RW_RW_RW / RW_RW_RW
  252. permsA = RW_RW_RW;
  253. permsB = RW_RW_RW;
  254. canCreate = true;
  255. oneToMany(u, true, true);
  256. oneToMany(o, true, true);
  257. oneToMany(w, true, true);
  258. oneToMany(p, true, true);
  259. oneToMany(r, true, true);
  260. // RW_RW_RW / RW_RW_xx : now lets lower visibility
  261. // thumbnail readable by other but not by world
  262. permsA = RW_RW_RW;
  263. permsB = RW_RW_xx;
  264. canCreate = true;
  265. oneToMany(u, true, true);
  266. oneToMany(o, true, true);
  267. oneToMany(w, true, false);
  268. oneToMany(p, true, true);
  269. oneToMany(r, true, true);
  270. // RW_RW_RW / RW_xx_xx
  271. permsA = RW_RW_RW;
  272. permsB = RW_xx_xx;
  273. canCreate = true;
  274. oneToMany(u, true, true);
  275. oneToMany(o, true, false);
  276. oneToMany(w, true, false);
  277. oneToMany(p, true, true);
  278. oneToMany(r, true, true);
  279. // RW_RW_RW / xx_xx_xx
  280. permsA = RW_RW_RW;
  281. permsB = xx_xx_xx;
  282. canCreate = true;
  283. oneToMany(u, true, false);
  284. oneToMany(o, true, false);
  285. oneToMany(w, true, false);
  286. oneToMany(p, true, true);
  287. oneToMany(r, true, true);
  288. // RW_xx_xx / RW_xx_xx
  289. permsA = RW_xx_xx;
  290. permsB = RW_xx_xx;
  291. canCreate = false;
  292. oneToMany(u, false, false);
  293. oneToMany(o, true, false);
  294. oneToMany(w, false, false);
  295. oneToMany(p, true, true);
  296. oneToMany(r, true, true);
  297. // xx_xx_xx / xx_xx_xx
  298. permsA = xx_xx_xx;
  299. permsB = xx_xx_xx;
  300. canCreate = false;
  301. oneToMany(u, false, false);
  302. oneToMany(o, false, false);
  303. oneToMany(w, false, false);
  304. oneToMany(p, true, true);
  305. oneToMany(r, true, true);
  306. }
  307. @Override
  308. public void test_U_Pixels_And_O_Thumbnails() throws Exception {
  309. ownsfA = u;
  310. ownerA = user;
  311. groupA = user_other_group;
  312. ownsfB = o;
  313. ownerB = other;
  314. groupB = user_other_group;
  315. // RW_RW_RW / RW_RW_RW
  316. permsA = RW_RW_RW;
  317. permsB = RW_RW_RW;
  318. canCreate = true;
  319. oneToMany(u, true, true);
  320. oneToMany(o, true, true);
  321. oneToMany(w, true, true);
  322. oneToMany(p, true, true);
  323. oneToMany(r, true, true);
  324. // RW_RW_RW / RW_RW_xx
  325. permsA = RW_RW_RW;
  326. permsB = RW_RW_xx;
  327. canCreate = true;
  328. oneToMany(u, true, true);
  329. oneToMany(o, true, true);
  330. oneToMany(w, true, false);
  331. oneToMany(p, true, true);
  332. oneToMany(r, true, true);
  333. // xx_xx_xx / RW_RW_RW
  334. permsA = xx_xx_xx;
  335. permsB = RW_RW_RW;
  336. canCreate = false;
  337. oneToMany(u, false, true);
  338. oneToMany(o, false, true);
  339. oneToMany(w, false, true);
  340. oneToMany(p, true, true);
  341. oneToMany(r, true, true);
  342. }
  343. @Override
  344. public void test_U_Pixels_And_R_Thumbnails() throws Exception {
  345. ownsfA = u;
  346. ownerA = user;
  347. groupA = user_other_group;
  348. ownsfB = r;
  349. ownerB = root;
  350. groupB = system_group;
  351. // RW_RW_RW / RW_RW_RW
  352. permsA = RW_RW_RW;
  353. permsB = RW_RW_RW;
  354. canCreate = true;
  355. oneToMany(u, true, true);
  356. oneToMany(o, true, true);
  357. oneToMany(w, true, true);
  358. oneToMany(p, true, true);
  359. oneToMany(r, true, true);
  360. // RW_RW_RW / RW_RW_xx
  361. permsA = RW_RW_RW;
  362. permsB = RW_RW_xx;
  363. canCreate = true;
  364. oneToMany(u, true, false);
  365. oneToMany(o, true, false);
  366. oneToMany(w, true, false);
  367. oneToMany(p, true, false);
  368. oneToMany(r, true, true);
  369. // RW_RW_RW / RW_xx_xx
  370. permsA = RW_RW_RW;
  371. permsB = RW_xx_xx;
  372. canCreate = true;
  373. oneToMany(u, true, false);
  374. oneToMany(o, true, false);
  375. oneToMany(w, true, false);
  376. oneToMany(p, true, false);
  377. oneToMany(r, true, true);
  378. // RW_xx_xx / RW_xx_xx
  379. permsA = RW_xx_xx;
  380. permsB = RW_xx_xx;
  381. canCreate = true;
  382. oneToMany(u, true, false);
  383. oneToMany(o, false, false);
  384. oneToMany(w, false, false);
  385. oneToMany(p, true, false);
  386. oneToMany(r, true, true);
  387. // xx_xx_xx / xx_xx_xx
  388. permsA = xx_xx_xx;
  389. permsB = xx_xx_xx;
  390. canCreate = true;
  391. oneToMany(u, false, false);
  392. oneToMany(o, false, false);
  393. oneToMany(w, false, false);
  394. oneToMany(p, true, false);
  395. oneToMany(r, true, true);
  396. }
  397. /**
  398. * performs various types of Omero lookups for a particular user proxied by
  399. * a {@link ServiceFactory}. If pix_ok is true, then the lookups should
  400. * succeed for the top-level pixel, and if tb_ok is true, then that pixel
  401. * should contain a single thumbnail.
  402. */
  403. protected void oneToMany(ServiceFactory sf, boolean pix_ok, boolean tb_ok) {
  404. createPixels(ownsfA, groupA, permsA);
  405. verifyDetails(pix, ownerA, groupA, permsA);
  406. try {
  407. createThumbnail(ownsfB, groupB, permsB, pix);
  408. verifyDetails(tb, ownerB, groupB, permsB);
  409. if (!canCreate) {
  410. fail("secvio!");
  411. }
  412. pix = tb.getPixels();
  413. String outerJoin = "select p from Pixels p left outer join fetch p.thumbnails where p.id = :id";
  414. String innerJoin = "select p from Pixels p join fetch p.thumbnails where p.id = :id";
  415. Parameters params = new Parameters().addId(pix.getId());
  416. Pixels test = sf.getQueryService().findByQuery(outerJoin, params);
  417. if (pix_ok) {
  418. assertNotNull(test);
  419. if (tb_ok) {
  420. assertTrue(test.sizeOfThumbnails() > 0);
  421. } else {
  422. assertTrue(test.sizeOfThumbnails() == 0); // TODO should
  423. // it be null?
  424. }
  425. } else {
  426. assertNull(test);
  427. }
  428. outerJoin = "select t from Thumbnail t left outer join fetch t.pixels where t.id = :id";
  429. innerJoin = "select t from Thumbnail t join fetch t.pixels where t.id = :id";
  430. params = new Parameters().addId(tb.getId());
  431. Thumbnail test2 = sf.getQueryService().findByQuery(outerJoin,
  432. params);
  433. if (tb_ok) {
  434. assertNotNull(test2);
  435. if (pix_ok) {
  436. assertNotNull(test2.getPixels());
  437. } else {
  438. fail("should not be possible (null)");
  439. }
  440. } else {
  441. assertNull(test2);
  442. }
  443. } catch (SecurityViolation sv) {
  444. if (canCreate) {
  445. throw sv;
  446. }
  447. }
  448. }
  449. // ~ many-to-one
  450. // =========================================================================
  451. public void test_U_Thumbnails_And_U_Pixels() throws Exception {
  452. ownsfA = ownsfB = u;
  453. ownerA = ownerB = user;
  454. groupA = groupB = user_other_group;
  455. // RW_RW_RW / RW_RW_RW : readable by all
  456. permsA = RW_RW_RW;
  457. permsB = RW_RW_RW;
  458. canCreate = true;
  459. manyToOne(u, true, true);
  460. manyToOne(o, true, true);
  461. manyToOne(w, true, true);
  462. manyToOne(p, true, true);
  463. manyToOne(r, true, true);
  464. // RW_RW_xx / RW_RW_RW
  465. permsA = RW_RW_xx;
  466. permsB = RW_RW_RW;
  467. canCreate = true;
  468. manyToOne(u, true, true);
  469. manyToOne(o, true, true);
  470. manyToOne(w, false, false);
  471. manyToOne(p, true, true);
  472. manyToOne(r, true, true);
  473. // RW_xx_xx / RW_RW_RW
  474. permsA = RW_xx_xx;
  475. permsB = RW_RW_RW;
  476. canCreate = true;
  477. manyToOne(u, true, true);
  478. manyToOne(o, false, true);
  479. manyToOne(w, false, false);
  480. manyToOne(p, true, true);
  481. manyToOne(r, true, true);
  482. // RW_xx_xx / RW_xx_xx
  483. permsA = RW_xx_xx;
  484. permsB = RW_RW_RW;
  485. canCreate = true;
  486. manyToOne(u, true, true);
  487. manyToOne(o, false, true);
  488. manyToOne(w, false, false);
  489. manyToOne(p, true, true);
  490. manyToOne(r, true, true);
  491. // RW_RW_RW / xx_xx_xx
  492. permsA = RW_RW_RW;
  493. permsB = xx_xx_xx;
  494. canCreate = false;
  495. manyToOne(u, true, false);
  496. manyToOne(o, true, false);
  497. manyToOne(w, true, false);
  498. manyToOne(p, true, true);
  499. manyToOne(r, true, true);
  500. }
  501. public void test_O_Thumbnails_And_U_Pixels() throws Exception {
  502. ownsfA = o;
  503. ownerA = other;
  504. groupA = user_other_group;
  505. ownsfB = u;
  506. ownerB = user;
  507. groupB = user_other_group;
  508. // RW_RW_RW / RW_RW_RW
  509. permsA = RW_RW_RW;
  510. permsB = RW_RW_RW;
  511. canCreate = true;
  512. manyToOne(u, true, true);
  513. manyToOne(o, true, true);
  514. manyToOne(w, true, true);
  515. manyToOne(p, true, true);
  516. manyToOne(r, true, true);
  517. // RW_RW_xx / RW_RW_RW
  518. permsA = RW_RW_xx;
  519. permsB = RW_RW_RW;
  520. canCreate = true;
  521. manyToOne(u, true, true);
  522. manyToOne(o, true, true);
  523. manyToOne(w, false, false);
  524. manyToOne(p, true, true);
  525. manyToOne(r, true, true);
  526. // RW_RW_RW / xx_xx_xx
  527. permsA = RW_RW_RW;
  528. permsB = xx_xx_xx;
  529. canCreate = false;
  530. manyToOne(u, true, false);
  531. manyToOne(o, true, false);
  532. manyToOne(w, true, false);
  533. manyToOne(p, true, true);
  534. manyToOne(r, true, true);
  535. }
  536. /**
  537. * performs various types of Omero lookups for a particular user proxied by
  538. * a {@link ServiceFactory}. If pix_ok is true, then the lookups should
  539. * succeed for the top-level pixel, and if tb_ok is true, then that pixel
  540. * should contain a single thumbnail.
  541. */
  542. protected void manyToOne(ServiceFactory sf, boolean tb_ok, boolean pix_ok) {
  543. createPixels(ownsfB, groupB, permsB);
  544. verifyDetails(pix, ownerB, groupB, permsB);
  545. try {
  546. createThumbnail(ownsfA, groupA, permsA, pix);
  547. verifyDetails(tb, ownerA, groupA, permsA);
  548. if (!canCreate) {
  549. fail("secvio!");
  550. }
  551. pix = tb.getPixels();
  552. String outerJoin = "select t from Thumbnail t left outer join fetch t.pixels where t.id = :id";
  553. String innerJoin = "select t from Thumbnail t join fetch t.pixels where t.id = :id";
  554. Parameters params = new Parameters().addId(tb.getId());
  555. try {
  556. Thumbnail test = sf.getQueryService().findByQuery(outerJoin,
  557. params);
  558. if (tb_ok) {
  559. assertNotNull(test);
  560. if (pix_ok) {
  561. assertNotNull(test.getPixels());
  562. } else {
  563. assertNull(test.getPixels()); // TODO should it be
  564. // null?
  565. }
  566. } else {
  567. assertNull(test);
  568. }
  569. } catch (SecurityViolation sv) {
  570. if (tb_ok && pix_ok) {
  571. throw sv;
  572. }
  573. }
  574. } catch (SecurityViolation sv) {
  575. if (canCreate) {
  576. throw sv;
  577. }
  578. }
  579. }
  580. // ~ unidirectional many-to-one
  581. // =========================================================================
  582. @Override
  583. public void test_U_Instrument_And_U_Microscope() throws Exception {
  584. ownsfA = ownsfB = u;
  585. ownerA = ownerB = user;
  586. groupA = groupB = user_other_group;
  587. // RW_RW_RW / RW_RW_RW
  588. permsA = RW_RW_RW;
  589. permsB = RW_RW_RW;
  590. canCreate = true;
  591. uniManyOne(u, true, true);
  592. }
  593. protected void uniManyOne(ServiceFactory sf, boolean instr_ok,
  594. boolean micro_ok) {
  595. createMicroscope(ownsfB, groupB, permsB);
  596. verifyDetails(micro, ownerB, groupB, permsB);
  597. try {
  598. createInstrument(ownsfA, groupA, permsA, micro);
  599. verifyDetails(instr, ownerA, groupA, permsA);
  600. if (!canCreate) {
  601. fail("secvio!");
  602. }
  603. } catch (SecurityViolation sv) {
  604. if (canCreate) {
  605. throw sv;
  606. }
  607. }
  608. String outerJoin = "select i from Instrument i left outer join fetch i.microscope where i.id = :id";
  609. String innerJoin = "select p from Instrument i join fetch i.microscope where i.id = :id";
  610. Parameters params = new Parameters().addId(instr.getId());
  611. Instrument test = sf.getQueryService().findByQuery(outerJoin, params);
  612. if (instr_ok) {
  613. assertNotNull(test);
  614. if (micro_ok) {
  615. assertNotNull(test.getMicroscope());
  616. } else {
  617. fail("should not be possibe (null)");
  618. }
  619. } else {
  620. assertNull(test);
  621. }
  622. }
  623. // ~ many-to-many
  624. // =========================================================================
  625. @Override
  626. public void test_U_Projects_U_Datasets_U_Link() throws Exception {
  627. ownsfA = ownsfB = ownsfC = u;
  628. ownerA = ownerB = ownerC = user;
  629. groupA = groupB = groupC = user_other_group;
  630. // RW_RW_RW / RW_RW_RW / RW_RW_RW
  631. permsA = permsB = permsC = RW_RW_RW;
  632. canCreate = true;
  633. manyToMany(u, true, true);
  634. manyToMany(o, true, true);
  635. manyToMany(w, true, true);
  636. manyToMany(p, true, true);
  637. manyToMany(r, true, true);
  638. // RW_RW_RW / RW_RW_xx / RW_RW_RW
  639. permsA = RW_RW_RW;
  640. permsB = RW_RW_xx;
  641. permsC = RW_RW_RW;
  642. canCreate = true;
  643. manyToMany(u, true, true);
  644. manyToMany(o, true, true);
  645. manyToMany(w, true, false);
  646. manyToMany(p, true, true);
  647. manyToMany(r, true, true);
  648. // RW_RW_RW / RW_xx_xx / RW_RW_RW
  649. permsA = RW_RW_RW;
  650. permsB = RW_xx_xx;
  651. permsC = RW_RW_RW;
  652. canCreate = true;
  653. manyToMany(u, true, true);
  654. manyToMany(o, true, false);
  655. manyToMany(w, true, false);
  656. manyToMany(p, true, true);
  657. manyToMany(r, true, true);
  658. }
  659. /**
  660. * performs various types of Omero lookups for a particular user proxied by
  661. * a {@link ServiceFactory}. If prj_ok is true, then the lookups should
  662. * succeed for the top-level project, and if ds_ok is true, then that
  663. * project should contain a single linked dataset.
  664. */
  665. protected void manyToMany(ServiceFactory sf, boolean prj_ok, boolean ds_ok) {
  666. prj = new Project();
  667. prj.setName("links");
  668. prj.getDetails().setPermissions(permsA);
  669. prj.getDetails().setGroup(groupA);
  670. Dataset ds = new Dataset();
  671. ds.setName("links");
  672. ds.getDetails().setPermissions(permsB);
  673. ds.getDetails().setGroup(groupB);
  674. prj = ownsfA.getUpdateService().saveAndReturnObject(prj);
  675. ds = ownsfB.getUpdateService().saveAndReturnObject(ds);
  676. link = new ProjectDatasetLink();
  677. link.link(prj, ds);
  678. link.getDetails().setPermissions(permsC);
  679. link.getDetails().setGroup(groupC);
  680. link = ownsfC.getUpdateService().saveAndReturnObject(link);
  681. // RW_RW_RW / RW_RW_RW
  682. verifyDetails(prj, ownerA, groupA, permsA);
  683. verifyDetails(ds, ownerB, groupB, permsB);
  684. verifyDetails(link, ownerC, groupC, permsC);
  685. String outerJoin = "select p from Project p "
  686. + " left outer join fetch p.datasetLinks pdl "
  687. + " left outer join fetch pdl.child ds " + " where p.id = :id";
  688. Parameters params = new Parameters().addId(prj.getId());
  689. try {
  690. Project test = sf.getQueryService().findByQuery(outerJoin, params);
  691. if (prj_ok) {
  692. assertNotNull(test);
  693. if (ds_ok) {
  694. assertNotNull(test.linkedDatasetList().size() == 1);
  695. } else {
  696. assertTrue(test.linkedDatasetList().size() == 0); // TODO
  697. // should
  698. // it be
  699. // null?
  700. }
  701. } else {
  702. assertNull(test);
  703. }
  704. } catch (SecurityViolation sv) {
  705. if (prj_ok && ds_ok) {
  706. throw sv;
  707. }
  708. }
  709. }
  710. // ~ Special: "tag" (e.g. Image/Pixels)
  711. // =========================================================================
  712. @Override
  713. @Test
  714. public void test_U_Image_U_Pixels() throws Exception {
  715. ownsfA = ownsfB = u;
  716. ownerA = ownerB = user;
  717. groupA = groupB = user_other_group;
  718. // RW_RW_RW / RW_RW_RW
  719. permsA = RW_RW_RW;
  720. permsB = RW_RW_RW;
  721. imagePixels(u, true, true);
  722. imagePixels(o, true, true);
  723. imagePixels(w, true, true);
  724. imagePixels(p, true, true);
  725. imagePixels(r, true, true);
  726. // RW_RW_RW / RW_RW_xx
  727. permsA = RW_RW_RW;
  728. permsB = RW_RW_xx;
  729. imagePixels(u, true, true);
  730. imagePixels(o, true, true);
  731. imagePixels(w, true, false);
  732. imagePixels(p, true, true);
  733. imagePixels(r, true, true);
  734. // RW_RW_RW / RW_xx_xx
  735. permsA = RW_RW_RW;
  736. permsB = RW_xx_xx;
  737. imagePixels(u, true, true);
  738. imagePixels(o, true, false);
  739. imagePixels(w, true, false);
  740. imagePixels(p, true, true);
  741. imagePixels(r, true, true);
  742. }
  743. protected void imagePixels(ServiceFactory sf, boolean img_ok, boolean pix_ok) {
  744. createPixels(ownsfB, groupB, permsB);
  745. createImage(ownsfA, groupA, permsA, pix);
  746. // RW_RW_RW / RW_RW_RW
  747. verifyDetails(img, ownerA, groupA, permsA);
  748. verifyDetails(pix, ownerB, groupB, permsB);
  749. String outerJoin = "select i from Image i "
  750. + "left outer join fetch i.pixels " + "where i.id = :id";
  751. Parameters params = new Parameters().addId(img.getId());
  752. Image test = sf.getQueryService().findByQuery(outerJoin, params);
  753. if (img_ok) {
  754. assertNotNull(test);
  755. if (pix_ok) {
  756. assertNotNull(test.getPrimaryPixels());
  757. assertTrue(test.sizeOfPixels() > 0);
  758. } else {
  759. assertTrue(test.sizeOfPixels() == 0); // TODO should it be
  760. // null?
  761. }
  762. } else {
  763. assertNull(test);
  764. }
  765. }
  766. }