/** * Runs the given {@link Consumer} with a system {@link CoreSession} while logged in as a system user. * * @param repositoryName the repository name for the {@link CoreSession} * @param consumer the consumer taking a system {@link CoreSession} * @since 8.4 */ public static void doPrivileged(String repositoryName, Consumer<CoreSession> consumer) { new UnrestrictedSessionRunner(repositoryName, getCurrentPrincipalName()) { @Override public void run() { consumer.accept(session); } }.runUnrestricted(); }
/** * Runs the given {@link Function} with a system {@link CoreSession} while logged in as a system user. * * @param repositoryName the repository name for the {@link CoreSession} * @param function the function taking a system {@link CoreSession} and returning a result of type {@code <R>} * @param <R> the function return type * @return the result of the function * @since 8.4 */ public static <R> R doPrivileged(String repositoryName, Function<CoreSession, R> function) { MutableObject<R> result = new MutableObject<>(); new UnrestrictedSessionRunner(repositoryName, getCurrentPrincipalName()) { @Override public void run() { result.setValue(function.apply(session)); } }.runUnrestricted(); return result.getValue(); }