@Override
    public void asUser(final UserIdentity userIdentity, final Runnable runnable) {
        boolean success = false;
        try {
            pushUser(userIdentity);
            success = true;
            runnable.run();
        } finally {
            if (success) {
                popUser();
            }
        }
    }
Run the supplied code as the specified user.
stroom-security/stroom-security-impl/src/main/java/stroom/security/impl/SecurityContextImpl.java