@Test public void isAllowed() throws Exception { assertTrue(this.wikiMacroFactory.isAllowed(DOCUMENT_REFERENCE, WikiMacroVisibility.USER)); assertFalse(this.wikiMacroFactory.isAllowed(DOCUMENT_REFERENCE, WikiMacroVisibility.WIKI)); assertFalse(this.wikiMacroFactory.isAllowed(DOCUMENT_REFERENCE, WikiMacroVisibility.GLOBAL)); when(this.oldcore.getMockAuthorizationManager().hasAccess(Right.ADMIN, null, DOCUMENT_REFERENCE.getWikiReference())).thenReturn(true); assertTrue(this.wikiMacroFactory.isAllowed(DOCUMENT_REFERENCE, WikiMacroVisibility.USER)); assertTrue(this.wikiMacroFactory.isAllowed(DOCUMENT_REFERENCE, WikiMacroVisibility.WIKI)); assertFalse(this.wikiMacroFactory.isAllowed(DOCUMENT_REFERENCE, WikiMacroVisibility.GLOBAL)); when(this.oldcore.getMockAuthorizationManager().hasAccess(Right.PROGRAM, null, null)).thenReturn(true); assertTrue(this.wikiMacroFactory.isAllowed(DOCUMENT_REFERENCE, WikiMacroVisibility.USER)); assertTrue(this.wikiMacroFactory.isAllowed(DOCUMENT_REFERENCE, WikiMacroVisibility.WIKI)); assertTrue(this.wikiMacroFactory.isAllowed(DOCUMENT_REFERENCE, WikiMacroVisibility.GLOBAL)); }
@Override public boolean isAllowed(DocumentReference documentReference, WikiMacroVisibility visibility) { boolean isAllowed = false; XWikiContext xcontext = getContext(); DocumentReference authorReference; XWikiDocument doc; try { doc = xcontext.getWiki().getDocument(documentReference, getContext()); authorReference = doc.getAuthorReference(); } catch (XWikiException e) { this.logger.error("Failed to get document", e); doc = null; authorReference = null; } switch (visibility) { case GLOBAL: isAllowed = doc != null && this.authorization.hasAccess(Right.PROGRAM, authorReference, null); break; case WIKI: isAllowed = doc != null && this.authorization.hasAccess(Right.ADMIN, authorReference, doc.getDocumentReference().getWikiReference()); break; default: isAllowed = true; } return isAllowed; }
DefaultWikiMacroFactory implements WikiMacroFactory, WikiMacroConstants { @Override public boolean isAllowed(DocumentReference documentReference, WikiMacroVisibility visibility) { boolean isAllowed = false; XWikiContext xcontext = getContext(); DocumentReference authorReference; XWikiDocument doc; try { doc = xcontext.getWiki().getDocument(documentReference, getContext()); authorReference = doc.getAuthorReference(); } catch (XWikiException e) { this.logger.error("Failed to get document", e); doc = null; authorReference = null; } switch (visibility) { case GLOBAL: isAllowed = doc != null && this.authorization.hasAccess(Right.PROGRAM, authorReference, null); break; case WIKI: isAllowed = doc != null && this.authorization.hasAccess(Right.ADMIN, authorReference, doc.getDocumentReference().getWikiReference()); break; default: isAllowed = true; } return isAllowed; } }
DefaultWikiMacroFactory implements WikiMacroFactory, WikiMacroConstants { @Override public boolean isAllowed(DocumentReference documentReference, WikiMacroVisibility visibility) { boolean isAllowed = false; XWikiContext xcontext = getContext(); DocumentReference authorReference; XWikiDocument doc; try { doc = xcontext.getWiki().getDocument(documentReference, getContext()); authorReference = doc.getAuthorReference(); } catch (XWikiException e) { this.logger.error("Failed to get document", e); doc = null; authorReference = null; } switch (visibility) { case GLOBAL: isAllowed = doc != null && this.authorization.hasAccess(Right.PROGRAM, authorReference, null); break; case WIKI: isAllowed = doc != null && this.authorization.hasAccess(Right.ADMIN, authorReference, doc.getDocumentReference().getWikiReference()); break; default: isAllowed = true; } return isAllowed; }  }
DefaultWikiMacroFactory implements WikiMacroFactory, WikiMacroConstants { @Override public boolean isAllowed(DocumentReference documentReference, WikiMacroVisibility visibility) { boolean isAllowed = false; XWikiContext xcontext = getContext(); DocumentReference authorReference; XWikiDocument doc; try { doc = xcontext.getWiki().getDocument(documentReference, getContext()); authorReference = doc.getAuthorReference(); } catch (XWikiException e) { this.logger.error("Failed to get document", e); doc = null; authorReference = null; } switch (visibility) { case GLOBAL: isAllowed = doc != null && this.authorization.hasAccess(Right.PROGRAM, authorReference, null); break; case WIKI: isAllowed = doc != null && this.authorization.hasAccess(Right.ADMIN, authorReference, doc.getDocumentReference().getWikiReference()); break; default: isAllowed = true; } return isAllowed; }  @Override WikiMacro createWikiMacro(DocumentReference documentReference); @Override boolean containsWikiMacro(DocumentReference documentReference); @Override boolean isAllowed(DocumentReference documentReference, WikiMacroVisibility visibility); }
DefaultWikiMacroFactory implements WikiMacroFactory, WikiMacroConstants { @Override public boolean isAllowed(DocumentReference documentReference, WikiMacroVisibility visibility) { boolean isAllowed = false; XWikiContext xcontext = getContext(); DocumentReference authorReference; XWikiDocument doc; try { doc = xcontext.getWiki().getDocument(documentReference, getContext()); authorReference = doc.getAuthorReference(); } catch (XWikiException e) { this.logger.error("Failed to get document", e); doc = null; authorReference = null; } switch (visibility) { case GLOBAL: isAllowed = doc != null && this.authorization.hasAccess(Right.PROGRAM, authorReference, null); break; case WIKI: isAllowed = doc != null && this.authorization.hasAccess(Right.ADMIN, authorReference, doc.getDocumentReference().getWikiReference()); break; default: isAllowed = true; } return isAllowed; }  @Override WikiMacro createWikiMacro(DocumentReference documentReference); @Override boolean containsWikiMacro(DocumentReference documentReference); @Override boolean isAllowed(DocumentReference documentReference, WikiMacroVisibility visibility);  }