@Test public void testRightResolver() { try { wiki.add(new MockDocument(docRefResolver.resolve("wikiY:SpaceX.DocY"), "wikiY:XWiki.UserY")); Right[] rights = {ADMIN, PROGRAM }; DocumentReference[] groups = { uResolver.resolve("GroupX", "wikiY"), uResolver.resolve("SpaceY.GroupY") }; DocumentReference[] users = { uResolver.resolve("UserX", "wikiY") }; RightsObject o = new MockRightsObject(new HashSet(asList(rights)), ALLOW, new HashSet(asList(users)), new HashSet(asList(groups))); final DocumentReference doc = docRefResolver.resolve("wikiY:SpaceX.DocY"); DocumentReference userX = uResolver.resolve("UserX", "wikiY"); DocumentReference userY = uResolver.resolve("UserY", "wikiY"); RightCacheKey key = new RightCacheKey() { public EntityReference getEntityReference() { return doc; }}; List<Collection<RightsObject>> docLevel = new LinkedList(); docLevel.add(new LinkedList()); docLevel.add(new LinkedList()); Collection<RightsObject> pageRights = new LinkedList(); pageRights.add(o); docLevel.add(pageRights); AccessLevel level = resolver.resolve(userX, doc, key, new LinkedList(), docLevel); assertTrue(level.equals(AccessLevel.DEFAULT_ACCESS_LEVEL)); level = resolver.resolve(userY, doc, key, asList(groups), docLevel); AccessLevel delete = AccessLevel.DEFAULT_ACCESS_LEVEL.clone(); delete.allow(DELETE); assertTrue(level.equals(delete)); level = resolver.resolve(userY, doc, key, new LinkedList(), docLevel); assertTrue(level.equals(delete)); List<Collection<RightsObject>> spaceLevel = new LinkedList(); spaceLevel.add(new LinkedList()); Collection<RightsObject> spaceRights = new LinkedList(); spaceRights.add(o); spaceLevel.add(spaceRights); spaceLevel.add(new LinkedList()); level = resolver.resolve(userX, doc, key, new LinkedList(), spaceLevel); AccessLevel expected = AccessLevel.DEFAULT_ACCESS_LEVEL.clone(); expected.allow(ADMIN); expected.allow(DELETE); assertTrue(level.equals(expected)); level = resolver.resolve(userY, doc, key, asList(groups), spaceLevel); assertTrue(level.equals(expected)); level = resolver.resolve(userY, doc, key, new LinkedList(), spaceLevel); assertTrue(level.equals(delete)); List<Collection<RightsObject>> wikiLevel = new LinkedList(); Collection<RightsObject> wikiRights = new LinkedList(); wikiRights.add(o); wikiLevel.add(wikiRights); wikiLevel.add(new LinkedList()); wikiLevel.add(new LinkedList()); level = resolver.resolve(userX, doc, key, new LinkedList(), wikiLevel); expected.allow(PROGRAM); assertTrue(level.equals(expected)); level = resolver.resolve(userY, doc, key, asList(groups), wikiLevel); assertTrue(level.equals(expected)); level = resolver.resolve(userY, doc, key, new LinkedList(), wikiLevel); assertTrue(level.equals(delete)); } catch (Exception e) { LOG.error("Caught exception!", e); assert false; } }
@Override public AccessLevel resolve(DocumentReference user, EntityReference entity, RightCacheKey entityKey, Collection<DocumentReference> groups, List<Collection<RightsObject>> rightsObjects) { AccessLevel accessLevel = new AccessLevel(); if (isSuperAdmin(user)) { for (Right right : Right.values()) { accessLevel.allow(right); } return accessLevel.getExistingInstance(); } if (isCreator(user, entity)) { accessLevel.allow(DELETE); } if (isWikiOwner(user, entity)) { accessLevel.allow(ADMIN); } ListIterator<Collection<RightsObject>> iterator = rightsObjects.listIterator(rightsObjects.size()); EntityReference ref = entityKey.getEntityReference(); while (iterator.hasPrevious() && ref != null) { resolve(user, groups, iterator.previous(), ref, accessLevel); ref = ref.getParent(); } assert (!iterator.hasPrevious() && ref == null); postProcess(user, entity, accessLevel); return accessLevel.getExistingInstance(); }
DefaultRightResolver extends AbstractRightResolver { @Override public AccessLevel resolve(DocumentReference user, EntityReference entity, RightCacheKey entityKey, Collection<DocumentReference> groups, List<Collection<RightsObject>> rightsObjects) { AccessLevel accessLevel = new AccessLevel(); if (isSuperAdmin(user)) { for (Right right : Right.values()) { accessLevel.allow(right); } return accessLevel.getExistingInstance(); } if (isCreator(user, entity)) { accessLevel.allow(DELETE); } if (isWikiOwner(user, entity)) { accessLevel.allow(ADMIN); } ListIterator<Collection<RightsObject>> iterator = rightsObjects.listIterator(rightsObjects.size()); EntityReference ref = entityKey.getEntityReference(); while (iterator.hasPrevious() && ref != null) { resolve(user, groups, iterator.previous(), ref, accessLevel); ref = ref.getParent(); } assert (!iterator.hasPrevious() && ref == null); postProcess(user, entity, accessLevel); return accessLevel.getExistingInstance(); } }
DefaultRightResolver extends AbstractRightResolver { @Override public AccessLevel resolve(DocumentReference user, EntityReference entity, RightCacheKey entityKey, Collection<DocumentReference> groups, List<Collection<RightsObject>> rightsObjects) { AccessLevel accessLevel = new AccessLevel(); if (isSuperAdmin(user)) { for (Right right : Right.values()) { accessLevel.allow(right); } return accessLevel.getExistingInstance(); } if (isCreator(user, entity)) { accessLevel.allow(DELETE); } if (isWikiOwner(user, entity)) { accessLevel.allow(ADMIN); } ListIterator<Collection<RightsObject>> iterator = rightsObjects.listIterator(rightsObjects.size()); EntityReference ref = entityKey.getEntityReference(); while (iterator.hasPrevious() && ref != null) { resolve(user, groups, iterator.previous(), ref, accessLevel); ref = ref.getParent(); } assert (!iterator.hasPrevious() && ref == null); postProcess(user, entity, accessLevel); return accessLevel.getExistingInstance(); }  }
DefaultRightResolver extends AbstractRightResolver { @Override public AccessLevel resolve(DocumentReference user, EntityReference entity, RightCacheKey entityKey, Collection<DocumentReference> groups, List<Collection<RightsObject>> rightsObjects) { AccessLevel accessLevel = new AccessLevel(); if (isSuperAdmin(user)) { for (Right right : Right.values()) { accessLevel.allow(right); } return accessLevel.getExistingInstance(); } if (isCreator(user, entity)) { accessLevel.allow(DELETE); } if (isWikiOwner(user, entity)) { accessLevel.allow(ADMIN); } ListIterator<Collection<RightsObject>> iterator = rightsObjects.listIterator(rightsObjects.size()); EntityReference ref = entityKey.getEntityReference(); while (iterator.hasPrevious() && ref != null) { resolve(user, groups, iterator.previous(), ref, accessLevel); ref = ref.getParent(); } assert (!iterator.hasPrevious() && ref == null); postProcess(user, entity, accessLevel); return accessLevel.getExistingInstance(); }  @Override AccessLevel resolve(DocumentReference user,
                               EntityReference entity,
                               RightCacheKey entityKey,
                               Collection<DocumentReference> groups,
                               List<Collection<RightsObject>> rightsObjects); }
DefaultRightResolver extends AbstractRightResolver { @Override public AccessLevel resolve(DocumentReference user, EntityReference entity, RightCacheKey entityKey, Collection<DocumentReference> groups, List<Collection<RightsObject>> rightsObjects) { AccessLevel accessLevel = new AccessLevel(); if (isSuperAdmin(user)) { for (Right right : Right.values()) { accessLevel.allow(right); } return accessLevel.getExistingInstance(); } if (isCreator(user, entity)) { accessLevel.allow(DELETE); } if (isWikiOwner(user, entity)) { accessLevel.allow(ADMIN); } ListIterator<Collection<RightsObject>> iterator = rightsObjects.listIterator(rightsObjects.size()); EntityReference ref = entityKey.getEntityReference(); while (iterator.hasPrevious() && ref != null) { resolve(user, groups, iterator.previous(), ref, accessLevel); ref = ref.getParent(); } assert (!iterator.hasPrevious() && ref == null); postProcess(user, entity, accessLevel); return accessLevel.getExistingInstance(); }  @Override AccessLevel resolve(DocumentReference user,
                               EntityReference entity,
                               RightCacheKey entityKey,
                               Collection<DocumentReference> groups,
                               List<Collection<RightsObject>> rightsObjects);  }