@Test public void getAccessLevelWithExceptions() throws ComponentLookupException, XWikiException { when(this.xwiki.getGroupService(this.context)).thenThrow(new XWikiException()); Assert.assertSame(NO_ACCESS, this.mocker.getComponentUnderTest().getAccessLevel(this.entity, OTHER_USER)); }
@Nonnull @Override public AccessLevel getAccessLevel(@Nullable final PrimaryEntity entity, @Nullable final EntityReference userOrGroup) { AccessLevel result = resolveAccessLevel(NONE); if (entity == null || userOrGroup == null) { return result; } try { final Owner ownerObj = getOwner(entity); final EntityReference owner = ownerObj == null ? null : ownerObj.getUser(); final Collection<Collaborator> collaborators = getCollaborators(entity); final Set<DocumentReference> processedEntities = new HashSet<>(); final Queue<DocumentReference> entitiesToCheck = new LinkedList<>(); entitiesToCheck.add((DocumentReference) userOrGroup); AccessLevel currentItemAccess; DocumentReference currentItem; final XWikiContext context = this.xcontextProvider.get(); final XWikiGroupService groupService = context.getWiki().getGroupService(context); while (!entitiesToCheck.isEmpty()) { currentItem = entitiesToCheck.poll(); currentItemAccess = getAccessLevel(currentItem, owner, collaborators); if (currentItemAccess.compareTo(result) > 0) { result = currentItemAccess; } processedEntities.add(currentItem); final Collection<DocumentReference> groups = groupService.getAllGroupsReferencesForMember(currentItem, 0, 0, context); groups.removeAll(processedEntities); entitiesToCheck.addAll(groups); } } catch (final XWikiException ex) { this.logger.warn("Failed to compute access level for [{}] on [{}]: {}", userOrGroup, entity.getId(), ex.getMessage()); } return result; }
DefaultEntityAccessManager implements EntityAccessManager { @Nonnull @Override public AccessLevel getAccessLevel(@Nullable final PrimaryEntity entity, @Nullable final EntityReference userOrGroup) { AccessLevel result = resolveAccessLevel(NONE); if (entity == null || userOrGroup == null) { return result; } try { final Owner ownerObj = getOwner(entity); final EntityReference owner = ownerObj == null ? null : ownerObj.getUser(); final Collection<Collaborator> collaborators = getCollaborators(entity); final Set<DocumentReference> processedEntities = new HashSet<>(); final Queue<DocumentReference> entitiesToCheck = new LinkedList<>(); entitiesToCheck.add((DocumentReference) userOrGroup); AccessLevel currentItemAccess; DocumentReference currentItem; final XWikiContext context = this.xcontextProvider.get(); final XWikiGroupService groupService = context.getWiki().getGroupService(context); while (!entitiesToCheck.isEmpty()) { currentItem = entitiesToCheck.poll(); currentItemAccess = getAccessLevel(currentItem, owner, collaborators); if (currentItemAccess.compareTo(result) > 0) { result = currentItemAccess; } processedEntities.add(currentItem); final Collection<DocumentReference> groups = groupService.getAllGroupsReferencesForMember(currentItem, 0, 0, context); groups.removeAll(processedEntities); entitiesToCheck.addAll(groups); } } catch (final XWikiException ex) { this.logger.warn("Failed to compute access level for [{}] on [{}]: {}", userOrGroup, entity.getId(), ex.getMessage()); } return result; } }
DefaultEntityAccessManager implements EntityAccessManager { @Nonnull @Override public AccessLevel getAccessLevel(@Nullable final PrimaryEntity entity, @Nullable final EntityReference userOrGroup) { AccessLevel result = resolveAccessLevel(NONE); if (entity == null || userOrGroup == null) { return result; } try { final Owner ownerObj = getOwner(entity); final EntityReference owner = ownerObj == null ? null : ownerObj.getUser(); final Collection<Collaborator> collaborators = getCollaborators(entity); final Set<DocumentReference> processedEntities = new HashSet<>(); final Queue<DocumentReference> entitiesToCheck = new LinkedList<>(); entitiesToCheck.add((DocumentReference) userOrGroup); AccessLevel currentItemAccess; DocumentReference currentItem; final XWikiContext context = this.xcontextProvider.get(); final XWikiGroupService groupService = context.getWiki().getGroupService(context); while (!entitiesToCheck.isEmpty()) { currentItem = entitiesToCheck.poll(); currentItemAccess = getAccessLevel(currentItem, owner, collaborators); if (currentItemAccess.compareTo(result) > 0) { result = currentItemAccess; } processedEntities.add(currentItem); final Collection<DocumentReference> groups = groupService.getAllGroupsReferencesForMember(currentItem, 0, 0, context); groups.removeAll(processedEntities); entitiesToCheck.addAll(groups); } } catch (final XWikiException ex) { this.logger.warn("Failed to compute access level for [{}] on [{}]: {}", userOrGroup, entity.getId(), ex.getMessage()); } return result; }  }
DefaultEntityAccessManager implements EntityAccessManager { @Nonnull @Override public AccessLevel getAccessLevel(@Nullable final PrimaryEntity entity, @Nullable final EntityReference userOrGroup) { AccessLevel result = resolveAccessLevel(NONE); if (entity == null || userOrGroup == null) { return result; } try { final Owner ownerObj = getOwner(entity); final EntityReference owner = ownerObj == null ? null : ownerObj.getUser(); final Collection<Collaborator> collaborators = getCollaborators(entity); final Set<DocumentReference> processedEntities = new HashSet<>(); final Queue<DocumentReference> entitiesToCheck = new LinkedList<>(); entitiesToCheck.add((DocumentReference) userOrGroup); AccessLevel currentItemAccess; DocumentReference currentItem; final XWikiContext context = this.xcontextProvider.get(); final XWikiGroupService groupService = context.getWiki().getGroupService(context); while (!entitiesToCheck.isEmpty()) { currentItem = entitiesToCheck.poll(); currentItemAccess = getAccessLevel(currentItem, owner, collaborators); if (currentItemAccess.compareTo(result) > 0) { result = currentItemAccess; } processedEntities.add(currentItem); final Collection<DocumentReference> groups = groupService.getAllGroupsReferencesForMember(currentItem, 0, 0, context); groups.removeAll(processedEntities); entitiesToCheck.addAll(groups); } } catch (final XWikiException ex) { this.logger.warn("Failed to compute access level for [{}] on [{}]: {}", userOrGroup, entity.getId(), ex.getMessage()); } return result; }  @Nonnull @Override Collection<AccessLevel> listAccessLevels(); @Nonnull @Override Collection<AccessLevel> listAllAccessLevels(); @Nonnull @Override AccessLevel resolveAccessLevel(@Nullable final String name); @Nonnull @Override AccessLevel getAccessLevel(@Nullable final PrimaryEntity entity, @Nullable final EntityReference userOrGroup); @Override boolean isAdministrator(@Nullable final PrimaryEntity entity); @Override boolean isAdministrator(@Nullable final PrimaryEntity entity, @Nullable final DocumentReference user); @Nullable @Override Owner getOwner(@Nullable final PrimaryEntity entity); @Override boolean setOwner(@Nullable final PrimaryEntity entity, @Nullable final EntityReference userOrGroup); @Nonnull @Override Collection<Collaborator> getCollaborators(@Nullable final PrimaryEntity entity); @Override boolean setCollaborators(
        @Nullable final PrimaryEntity entity,
        @Nullable final Collection<Collaborator> newCollaborators); @Override boolean addCollaborator(@Nullable final PrimaryEntity entity, @Nullable final Collaborator collaborator); @Override boolean removeCollaborator(@Nullable final PrimaryEntity entity, @Nullable final Collaborator collaborator); }
DefaultEntityAccessManager implements EntityAccessManager { @Nonnull @Override public AccessLevel getAccessLevel(@Nullable final PrimaryEntity entity, @Nullable final EntityReference userOrGroup) { AccessLevel result = resolveAccessLevel(NONE); if (entity == null || userOrGroup == null) { return result; } try { final Owner ownerObj = getOwner(entity); final EntityReference owner = ownerObj == null ? null : ownerObj.getUser(); final Collection<Collaborator> collaborators = getCollaborators(entity); final Set<DocumentReference> processedEntities = new HashSet<>(); final Queue<DocumentReference> entitiesToCheck = new LinkedList<>(); entitiesToCheck.add((DocumentReference) userOrGroup); AccessLevel currentItemAccess; DocumentReference currentItem; final XWikiContext context = this.xcontextProvider.get(); final XWikiGroupService groupService = context.getWiki().getGroupService(context); while (!entitiesToCheck.isEmpty()) { currentItem = entitiesToCheck.poll(); currentItemAccess = getAccessLevel(currentItem, owner, collaborators); if (currentItemAccess.compareTo(result) > 0) { result = currentItemAccess; } processedEntities.add(currentItem); final Collection<DocumentReference> groups = groupService.getAllGroupsReferencesForMember(currentItem, 0, 0, context); groups.removeAll(processedEntities); entitiesToCheck.addAll(groups); } } catch (final XWikiException ex) { this.logger.warn("Failed to compute access level for [{}] on [{}]: {}", userOrGroup, entity.getId(), ex.getMessage()); } return result; }  @Nonnull @Override Collection<AccessLevel> listAccessLevels(); @Nonnull @Override Collection<AccessLevel> listAllAccessLevels(); @Nonnull @Override AccessLevel resolveAccessLevel(@Nullable final String name); @Nonnull @Override AccessLevel getAccessLevel(@Nullable final PrimaryEntity entity, @Nullable final EntityReference userOrGroup); @Override boolean isAdministrator(@Nullable final PrimaryEntity entity); @Override boolean isAdministrator(@Nullable final PrimaryEntity entity, @Nullable final DocumentReference user); @Nullable @Override Owner getOwner(@Nullable final PrimaryEntity entity); @Override boolean setOwner(@Nullable final PrimaryEntity entity, @Nullable final EntityReference userOrGroup); @Nonnull @Override Collection<Collaborator> getCollaborators(@Nullable final PrimaryEntity entity); @Override boolean setCollaborators(
        @Nullable final PrimaryEntity entity,
        @Nullable final Collection<Collaborator> newCollaborators); @Override boolean addCollaborator(@Nullable final PrimaryEntity entity, @Nullable final Collaborator collaborator); @Override boolean removeCollaborator(@Nullable final PrimaryEntity entity, @Nullable final Collaborator collaborator);  }