private void ensureValidUser(final UserRef userRef) {
        final Optional<User> optional = userCache.getByRef(userRef);
        if (optional.isEmpty()) {
            throwPermissionException(userRef, "User '" + userRef.toDisplayString() + "' not found");
        } else if (!optional.get().isEnabled()) {
            throwPermissionException(userRef, "User '" + userRef.toDisplayString() + "' is not enabled");
        }
    }
Run the supplied code as the specified user.
stroom-security/stroom-security-impl/src/main/java/stroom/security/impl/SecurityContextImpl.java