Index: xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java (revision 30762) +++ xwiki-core/src/main/java/com/xpn/xwiki/internal/DefaultWikiMacroInitializer.java (working copy) @@ -34,6 +34,7 @@ import org.xwiki.model.reference.DocumentReference; import org.xwiki.model.reference.SpaceReference; import org.xwiki.model.reference.WikiReference; +import org.xwiki.rendering.macro.wikibridge.InsufficientPrivilegesException; import org.xwiki.rendering.macro.wikibridge.WikiMacro; import org.xwiki.rendering.macro.wikibridge.WikiMacroException; import org.xwiki.rendering.macro.wikibridge.WikiMacroFactory; @@ -198,6 +199,10 @@ xcontext.setUser(wikiMacroDocumentAuthor); this.wikiMacroManager.registerWikiMacro(wikiMacroDocumentReference, macro); LOG.debug("Registered macro " + wikiMacroDocumentReference); + } catch (InsufficientPrivilegesException ex) { + // Just log the exception and skip to the next. + // We only log at the debug level here as this is not really an error + getLogger().debug(ex.getMessage(), ex); } catch (WikiMacroException ex) { // Just log the exception and skip to the next. getLogger().error(ex.getMessage(), ex); Index: xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/test/java/org/xwiki/rendering/internal/macro/wikibridge/DefaultWikiMacroManagerTest.java =================================================================== --- xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/test/java/org/xwiki/rendering/internal/macro/wikibridge/DefaultWikiMacroManagerTest.java (revision 30762) +++ xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/test/java/org/xwiki/rendering/internal/macro/wikibridge/DefaultWikiMacroManagerTest.java (working copy) @@ -30,6 +30,7 @@ import org.xwiki.rendering.macro.MacroId; import org.xwiki.rendering.macro.MacroManager; import org.xwiki.rendering.macro.descriptor.DefaultContentDescriptor; +import org.xwiki.rendering.macro.wikibridge.InsufficientPrivilegesException; import org.xwiki.rendering.macro.wikibridge.WikiMacroDescriptor; import org.xwiki.rendering.macro.wikibridge.WikiMacroException; import org.xwiki.rendering.macro.wikibridge.WikiMacroManager; @@ -146,7 +147,7 @@ Assert.assertEquals(0, registeredMacro.compareTo(wikiMacro)); } - @org.junit.Test + @org.junit.Test(expected=InsufficientPrivilegesException.class) public void testRegisterWikiMacroWhenGlobalVisibilityAndNotAllowed() throws Exception { final DefaultWikiMacro wikiMacro = generateWikiMacro(WikiMacroVisibility.GLOBAL); @@ -156,18 +157,10 @@ allowing(mockDocumentAccessBridge).hasProgrammingRights(); will(returnValue(false)); }}); - try { - wikiMacroManager.registerWikiMacro(wikiMacro.getDocumentReference(), wikiMacro); - Assert.fail("Should have raised an exception here"); - } catch (WikiMacroException e) { - Assert.assertEquals("Unable to register macro [testwikimacro] in " - + "[name = [TestWikiMacro], type = [DOCUMENT], parent = [name = [Main], type = [SPACE], " - + "parent = [name = [xwiki], type = [WIKI], parent = [null]]]] for visibility [GLOBAL] due to " - + "insufficient privileges", e.getMessage()); - } + wikiMacroManager.registerWikiMacro(wikiMacro.getDocumentReference(), wikiMacro); } - @org.junit.Test + @org.junit.Test(expected=InsufficientPrivilegesException.class) public void testRegisterWikiMacroWhenWikiVisibilityAndNotAllowed() throws Exception { final DefaultWikiMacro wikiMacro = generateWikiMacro(WikiMacroVisibility.WIKI); @@ -178,18 +171,10 @@ will(returnValue(false)); }}); - try { - wikiMacroManager.registerWikiMacro(wikiMacro.getDocumentReference(), wikiMacro); - Assert.fail("Should have raised an exception here"); - } catch (WikiMacroException e) { - Assert.assertEquals("Unable to register macro [testwikimacro] in [name = [TestWikiMacro], " - + "type = [DOCUMENT], parent = [name = [Main], type = [SPACE], parent = [name = [xwiki], " - + "type = [WIKI], parent = [null]]]] for visibility [WIKI] due to insufficient privileges", - e.getMessage()); - } + wikiMacroManager.registerWikiMacro(wikiMacro.getDocumentReference(), wikiMacro); } - @org.junit.Test + @org.junit.Test(expected=InsufficientPrivilegesException.class) public void testRegisterWikiMacroWhenUserVisibilityAndNotAllowed() throws Exception { final DefaultWikiMacro wikiMacro = generateWikiMacro(WikiMacroVisibility.USER); @@ -200,15 +185,7 @@ will(returnValue(false)); }}); - try { - wikiMacroManager.registerWikiMacro(wikiMacro.getDocumentReference(), wikiMacro); - Assert.fail("Should have raised an exception here"); - } catch (WikiMacroException e) { - Assert.assertEquals("Unable to register macro [testwikimacro] in [name = [TestWikiMacro], " - + "type = [DOCUMENT], parent = [name = [Main], type = [SPACE], parent = [name = [xwiki], " - + "type = [WIKI], parent = [null]]]] for visibility [USER] due to insufficient privileges", - e.getMessage()); - } + wikiMacroManager.registerWikiMacro(wikiMacro.getDocumentReference(), wikiMacro); } private DefaultWikiMacro generateWikiMacro(WikiMacroVisibility visibility) throws Exception Index: xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroManager.java =================================================================== --- xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroManager.java (revision 30762) +++ xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/macro/wikibridge/WikiMacroManager.java (working copy) @@ -42,18 +42,18 @@ * * @param documentReference the name of the document which contains the wiki macro * @param wikiMacro the {@link org.xwiki.rendering.macro.wikibridge.WikiMacro} instance - * @exception WikiMacroException if a problem happened when registering the macro (document doesn't exist, - * not enough privilege, etc) + * @exception InsufficientPrivilegesException if asked visibility is not allowed + * @exception WikiMacroException if a problem happened when registering the macro (document doesn't exist, etc.) * @since 2.2.M1 */ - void registerWikiMacro(DocumentReference documentReference, WikiMacro wikiMacro) throws WikiMacroException; + void registerWikiMacro(DocumentReference documentReference, WikiMacro wikiMacro) + throws InsufficientPrivilegesException, WikiMacroException; /** * Unregisters the wiki macro defined on the given document (if there is one). * * @param documentReference the name of the document which contains the wiki macro - * @exception WikiMacroException if a problem happened when registering the macro (document doesn't exist, - * not enough privilege, etc) + * @exception WikiMacroException if a problem happened when registering the macro (document doesn't exist, etc) * @since 2.2.M1 */ void unregisterWikiMacro(DocumentReference documentReference) throws WikiMacroException; Index: xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/internal/macro/wikibridge/DefaultWikiMacroManager.java =================================================================== --- xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/internal/macro/wikibridge/DefaultWikiMacroManager.java (revision 30762) +++ xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/internal/macro/wikibridge/DefaultWikiMacroManager.java (working copy) @@ -32,6 +32,7 @@ import org.xwiki.model.reference.DocumentReference; import org.xwiki.model.reference.EntityReference; import org.xwiki.rendering.macro.Macro; +import org.xwiki.rendering.macro.wikibridge.InsufficientPrivilegesException; import org.xwiki.rendering.macro.wikibridge.WikiMacro; import org.xwiki.rendering.macro.wikibridge.WikiMacroDescriptor; import org.xwiki.rendering.macro.wikibridge.WikiMacroException; @@ -146,7 +147,8 @@ * @see WikiMacroManager#registerWikiMacro(org.xwiki.model.reference.DocumentReference , WikiMacro) * @since 2.2M1 */ - public void registerWikiMacro(DocumentReference documentReference, WikiMacro wikiMacro) throws WikiMacroException + public void registerWikiMacro(DocumentReference documentReference, WikiMacro wikiMacro) + throws InsufficientPrivilegesException, WikiMacroException { WikiMacroDescriptor macroDescriptor = (WikiMacroDescriptor) wikiMacro.getDescriptor(); @@ -166,9 +168,9 @@ wikiMacro.getDescriptor().getId().getId(), documentReference, macroDescriptor.getVisibility()), e); } } else { - throw new WikiMacroException(String.format("Unable to register macro [%s] in [%s] for visibility [%s] " - + "due to insufficient privileges", wikiMacro.getDescriptor().getId().getId(), documentReference, - macroDescriptor.getVisibility())); + throw new InsufficientPrivilegesException(String.format( + "Unable to register macro [%s] in [%s] for visibility [%s] due to insufficient privileges", wikiMacro + .getDescriptor().getId().getId(), documentReference, macroDescriptor.getVisibility())); } } Index: xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/internal/macro/wikibridge/WikiMacroEventListener.java =================================================================== --- xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/internal/macro/wikibridge/WikiMacroEventListener.java (revision 30762) +++ xwiki-rendering/xwiki-rendering-macros/xwiki-rendering-macro-wikibridge/src/main/java/org/xwiki/rendering/internal/macro/wikibridge/WikiMacroEventListener.java (working copy) @@ -33,6 +33,7 @@ import org.xwiki.observation.event.DocumentSaveEvent; import org.xwiki.observation.event.DocumentUpdateEvent; import org.xwiki.observation.event.Event; +import org.xwiki.rendering.macro.wikibridge.InsufficientPrivilegesException; import org.xwiki.rendering.macro.wikibridge.WikiMacro; import org.xwiki.rendering.macro.wikibridge.WikiMacroFactory; import org.xwiki.rendering.macro.wikibridge.WikiMacroException; @@ -140,6 +141,9 @@ getLogger().debug( String.format("Unable to register macro [%s] in document [%s]", wikiMacro.getDescriptor().getId() .getId(), documentReference), e); + } catch (InsufficientPrivilegesException e) { + getLogger().debug(String.format("Insufficient privileges for registering macro [%s] in document [%s]", + wikiMacro.getDescriptor().getId().getId(), documentReference), e); } }