/** * Setup the context so that following code is executed with provided user rights. * * <pre> * {@code * try (AutoCloseable context = this.executor.before(author, sourceDocument)) { * ... * } * } * </pre> * * @param authorReference the user to check rights on * @param sourceReference the reference of the document associated with the {@link Callable} (which will be used to * test the author right) * @return the context to restore * @see #after(AutoCloseable) * @since 10.11RC1 */ @Unstable default AutoCloseable before(DocumentReference authorReference, DocumentReference sourceReference) { return before(authorReference); }
/** * Called when receiving a {@link WikiMacroExecutionFinishedEvent} event. */ public void onWikiMacroExecutionFinishedEvent() { // Get the su context to restore ExecutionContext econtext = this.execution.getContext(); // Use a stack in case a wiki macro calls another wiki macro Stack<AutoCloseable> backup = (Stack<AutoCloseable>) econtext.getProperty(SUCONTEXT_KEY); if (backup != null && !backup.isEmpty()) { // Restore the context execution rights this.suExecutor.after(backup.pop()); } else { this.logger.error("Can't find any backed up execution right information in the execution context"); } } }
/** * Execute the passed {@link Callable} with the rights of the passed user. * * @param callable the task to execute * @param authorReference the user to check rights on * @param sourceReference the reference of the document associated with the {@link Callable} (which will be used to * test the author right) * @return computed result * @throws Exception if unable to compute a result * @param <V> the result type of method <tt>call</tt> * @since 10.11RC1 */ @Unstable default <V> V call(Callable<V> callable, DocumentReference authorReference, DocumentReference sourceReference) throws Exception { return call(callable, authorReference); }
/** * Called when receiving a {@link WikiMacroExecutionStartsEvent} event. * * @param wikiMacro the wiki macro sending the event */ public void onWikiMacroExecutionStartsEvent(WikiMacro wikiMacro) { // Modify the context for that following code is executed with the right of wiki macro author AutoCloseable sucontext = this.suExecutor.before(wikiMacro.getAuthorReference()); // Put it in an hidden context property to restore it later ExecutionContext econtext = this.execution.getContext(); // Use a stack in case a wiki macro calls another wiki macro Stack<AutoCloseable> backup = (Stack<AutoCloseable>) econtext.getProperty(SUCONTEXT_KEY); if (backup == null) { backup = new Stack<AutoCloseable>(); econtext.setProperty(SUCONTEXT_KEY, backup); } backup.push(sucontext); }