@Test public void authorizedClassesOnly() throws XWikiRestException { when(authorization.hasAccess(eq(Right.VIEW), eq(new DocumentReference("xwiki", "XWiki", "Protected")))) .thenReturn(false); Classes xwikiClasses = resource.getClasses("xwiki", 0, -1); assertEquals(3, xwikiClasses.getClazzs().size()); for (Class clazz : xwikiClasses.getClazzs()) { assertTrue(clazz.getId().equals("Foo.Class1") || clazz.getId().equals("XWiki.User") || clazz.getId().equals("Bar.Other")); assertNotEquals("XWiki.Protected", clazz.getId()); } }
@Override public Classes getClasses(String wikiName, Integer start, Integer number) throws XWikiRestException { String database = Utils.getXWikiContext(componentManager).getWikiId(); try { getXWikiContext().setWikiId(wikiName); List<String> classNames = Utils.getXWikiApi(componentManager).getClassList(); Collections.sort(classNames); RangeIterable<String> ri = new RangeIterable<String>(classNames, start, number); Classes classes = objectFactory.createClasses(); for (String className : ri) { DocumentReference classReference = this.resolver.resolve(className, new WikiReference(wikiName)); if (this.authorization.hasAccess(Right.VIEW, classReference)) { com.xpn.xwiki.api.Class xwikiClass = Utils.getXWikiApi(componentManager).getClass(classReference); classes.getClazzs().add(this.utils.toRestClass(uriInfo.getBaseUri(), xwikiClass)); } } return classes; } catch (XWikiException e) { throw new XWikiRestException(e); } finally { Utils.getXWikiContext(componentManager).setWikiId(database); } }
ClassesResourceImpl extends XWikiResource implements ClassesResource { @Override public Classes getClasses(String wikiName, Integer start, Integer number) throws XWikiRestException { String database = Utils.getXWikiContext(componentManager).getWikiId(); try { getXWikiContext().setWikiId(wikiName); List<String> classNames = Utils.getXWikiApi(componentManager).getClassList(); Collections.sort(classNames); RangeIterable<String> ri = new RangeIterable<String>(classNames, start, number); Classes classes = objectFactory.createClasses(); for (String className : ri) { DocumentReference classReference = this.resolver.resolve(className, new WikiReference(wikiName)); if (this.authorization.hasAccess(Right.VIEW, classReference)) { com.xpn.xwiki.api.Class xwikiClass = Utils.getXWikiApi(componentManager).getClass(classReference); classes.getClazzs().add(this.utils.toRestClass(uriInfo.getBaseUri(), xwikiClass)); } } return classes; } catch (XWikiException e) { throw new XWikiRestException(e); } finally { Utils.getXWikiContext(componentManager).setWikiId(database); } } }
ClassesResourceImpl extends XWikiResource implements ClassesResource { @Override public Classes getClasses(String wikiName, Integer start, Integer number) throws XWikiRestException { String database = Utils.getXWikiContext(componentManager).getWikiId(); try { getXWikiContext().setWikiId(wikiName); List<String> classNames = Utils.getXWikiApi(componentManager).getClassList(); Collections.sort(classNames); RangeIterable<String> ri = new RangeIterable<String>(classNames, start, number); Classes classes = objectFactory.createClasses(); for (String className : ri) { DocumentReference classReference = this.resolver.resolve(className, new WikiReference(wikiName)); if (this.authorization.hasAccess(Right.VIEW, classReference)) { com.xpn.xwiki.api.Class xwikiClass = Utils.getXWikiApi(componentManager).getClass(classReference); classes.getClazzs().add(this.utils.toRestClass(uriInfo.getBaseUri(), xwikiClass)); } } return classes; } catch (XWikiException e) { throw new XWikiRestException(e); } finally { Utils.getXWikiContext(componentManager).setWikiId(database); } }  }
ClassesResourceImpl extends XWikiResource implements ClassesResource { @Override public Classes getClasses(String wikiName, Integer start, Integer number) throws XWikiRestException { String database = Utils.getXWikiContext(componentManager).getWikiId(); try { getXWikiContext().setWikiId(wikiName); List<String> classNames = Utils.getXWikiApi(componentManager).getClassList(); Collections.sort(classNames); RangeIterable<String> ri = new RangeIterable<String>(classNames, start, number); Classes classes = objectFactory.createClasses(); for (String className : ri) { DocumentReference classReference = this.resolver.resolve(className, new WikiReference(wikiName)); if (this.authorization.hasAccess(Right.VIEW, classReference)) { com.xpn.xwiki.api.Class xwikiClass = Utils.getXWikiApi(componentManager).getClass(classReference); classes.getClazzs().add(this.utils.toRestClass(uriInfo.getBaseUri(), xwikiClass)); } } return classes; } catch (XWikiException e) { throw new XWikiRestException(e); } finally { Utils.getXWikiContext(componentManager).setWikiId(database); } }  @Override Classes getClasses(String wikiName, Integer start, Integer number); }
ClassesResourceImpl extends XWikiResource implements ClassesResource { @Override public Classes getClasses(String wikiName, Integer start, Integer number) throws XWikiRestException { String database = Utils.getXWikiContext(componentManager).getWikiId(); try { getXWikiContext().setWikiId(wikiName); List<String> classNames = Utils.getXWikiApi(componentManager).getClassList(); Collections.sort(classNames); RangeIterable<String> ri = new RangeIterable<String>(classNames, start, number); Classes classes = objectFactory.createClasses(); for (String className : ri) { DocumentReference classReference = this.resolver.resolve(className, new WikiReference(wikiName)); if (this.authorization.hasAccess(Right.VIEW, classReference)) { com.xpn.xwiki.api.Class xwikiClass = Utils.getXWikiApi(componentManager).getClass(classReference); classes.getClazzs().add(this.utils.toRestClass(uriInfo.getBaseUri(), xwikiClass)); } } return classes; } catch (XWikiException e) { throw new XWikiRestException(e); } finally { Utils.getXWikiContext(componentManager).setWikiId(database); } }  @Override Classes getClasses(String wikiName, Integer start, Integer number);  }