@Test public void checkWhenNoPermissionAndSourceMetaData() { CancelableEvent event = mock(CancelableEvent.class); MacroTransformationContext context = new MacroTransformationContext(); MacroBlock macroBlock = new MacroBlock("macro", Collections.emptyMap(), false); MetaData sourceMetaData = new MetaData(); sourceMetaData.addMetaData(MetaData.SOURCE, "location"); new MetaDataBlock(Arrays.asList(macroBlock), sourceMetaData); context.setCurrentMacroBlock(macroBlock); ScriptMacroParameters parameters = new ScriptMacroParameters(); when(this.macroPermissionPolicy.hasPermission(parameters, context)).thenReturn(false); this.listener.check(event, context, parameters); verify(event).cancel("The execution of the [macro] script macro is not allowed in [location]. " + "Check the rights of its last author or the parameters if it's rendered from another script."); }
@Override protected void check(CancelableEvent event, MacroTransformationContext context, ScriptMacroParameters parameters) { MacroId currentMacroId = new MacroId(context.getCurrentMacroBlock().getId()); try { MacroPermissionPolicy mpp = this.componentManager.getInstance(MacroPermissionPolicy.class, currentMacroId.getId()); if (!mpp.hasPermission(parameters, context)) { String sourceContentReference = extractSourceContentReference(context.getCurrentMacroBlock()); String sourceText = ""; if (sourceContentReference != null) { sourceText = String.format(" in [%s]", sourceContentReference); } else { sourceText = ""; } event.cancel(String.format("The execution of the [%s] script macro is not allowed%s." + " Check the rights of its last author or the parameters if it's rendered from another script.", currentMacroId, sourceText)); } } catch (ComponentLookupException e) { backwardCompatibilityCheck(currentMacroId, event); } }
PermissionCheckerListener extends AbstractScriptCheckerListener { @Override protected void check(CancelableEvent event, MacroTransformationContext context, ScriptMacroParameters parameters) { MacroId currentMacroId = new MacroId(context.getCurrentMacroBlock().getId()); try { MacroPermissionPolicy mpp = this.componentManager.getInstance(MacroPermissionPolicy.class, currentMacroId.getId()); if (!mpp.hasPermission(parameters, context)) { String sourceContentReference = extractSourceContentReference(context.getCurrentMacroBlock()); String sourceText = ""; if (sourceContentReference != null) { sourceText = String.format(" in [%s]", sourceContentReference); } else { sourceText = ""; } event.cancel(String.format("The execution of the [%s] script macro is not allowed%s." + " Check the rights of its last author or the parameters if it's rendered from another script.", currentMacroId, sourceText)); } } catch (ComponentLookupException e) { backwardCompatibilityCheck(currentMacroId, event); } } }
PermissionCheckerListener extends AbstractScriptCheckerListener { @Override protected void check(CancelableEvent event, MacroTransformationContext context, ScriptMacroParameters parameters) { MacroId currentMacroId = new MacroId(context.getCurrentMacroBlock().getId()); try { MacroPermissionPolicy mpp = this.componentManager.getInstance(MacroPermissionPolicy.class, currentMacroId.getId()); if (!mpp.hasPermission(parameters, context)) { String sourceContentReference = extractSourceContentReference(context.getCurrentMacroBlock()); String sourceText = ""; if (sourceContentReference != null) { sourceText = String.format(" in [%s]", sourceContentReference); } else { sourceText = ""; } event.cancel(String.format("The execution of the [%s] script macro is not allowed%s." + " Check the rights of its last author or the parameters if it's rendered from another script.", currentMacroId, sourceText)); } } catch (ComponentLookupException e) { backwardCompatibilityCheck(currentMacroId, event); } }  }
PermissionCheckerListener extends AbstractScriptCheckerListener { @Override protected void check(CancelableEvent event, MacroTransformationContext context, ScriptMacroParameters parameters) { MacroId currentMacroId = new MacroId(context.getCurrentMacroBlock().getId()); try { MacroPermissionPolicy mpp = this.componentManager.getInstance(MacroPermissionPolicy.class, currentMacroId.getId()); if (!mpp.hasPermission(parameters, context)) { String sourceContentReference = extractSourceContentReference(context.getCurrentMacroBlock()); String sourceText = ""; if (sourceContentReference != null) { sourceText = String.format(" in [%s]", sourceContentReference); } else { sourceText = ""; } event.cancel(String.format("The execution of the [%s] script macro is not allowed%s." + " Check the rights of its last author or the parameters if it's rendered from another script.", currentMacroId, sourceText)); } } catch (ComponentLookupException e) { backwardCompatibilityCheck(currentMacroId, event); } }  @Override String getName(); }
PermissionCheckerListener extends AbstractScriptCheckerListener { @Override protected void check(CancelableEvent event, MacroTransformationContext context, ScriptMacroParameters parameters) { MacroId currentMacroId = new MacroId(context.getCurrentMacroBlock().getId()); try { MacroPermissionPolicy mpp = this.componentManager.getInstance(MacroPermissionPolicy.class, currentMacroId.getId()); if (!mpp.hasPermission(parameters, context)) { String sourceContentReference = extractSourceContentReference(context.getCurrentMacroBlock()); String sourceText = ""; if (sourceContentReference != null) { sourceText = String.format(" in [%s]", sourceContentReference); } else { sourceText = ""; } event.cancel(String.format("The execution of the [%s] script macro is not allowed%s." + " Check the rights of its last author or the parameters if it's rendered from another script.", currentMacroId, sourceText)); } } catch (ComponentLookupException e) { backwardCompatibilityCheck(currentMacroId, event); } }  @Override String getName();  }