This biography of Einstein (exact page) asserts that, and narrates the dream in astonishing detail. The only chance of it being true is a direct testimony of Einstein himself, but I haven't found it.
According to an article in Nature reviewing Magueijo's earlier book, the story is fictional:
Faster Than the Speed of Light is a lively book that captures the excitement and frustrations of doing real-world science. Magueijo relates interestingly how his VSL proposal might possibly be a way out of some major puzzles facing cosmology, which he explains well. There are irritating passages, however, where he makes extended use of a metaphor involving farmers and cows in explaining relativity theory. Magueijo states that this is based on a dream that Einstein had as a boy — a fictional invention that displays such a cavalier attitude to historical truth as to call into question his other historical claims (and for the record, it was Richard Tolman, not Yakov Zeldovich, who first investigated the thermodynamics of bouncing universes).
No cows but might be the source.
Einstein: An Intimate Study of a Great Man
Biography by Dimitri Marianoff (Einstein' son-in-law), Palma Wayne
"-How is it, Albert, that you arrived at your theory?
-In vision, "he answered."
He said that one night he had gone to bad with a discouragement of such black depths that no argument would pierce it. "When one's thought falls into despair, nothing serves him any longer, not his hours of work, not his past success-nothing. All reassurance is gone. It is finished, I told myself, it is useless. There are no results. I must give up. Then this happened. With infinite precision the universe, with its underlying unity of size, structure, distance, time, space, slowly fell piece by piece, like a monolithic picture puzzle, into place in Albert Einstein's mind. Suddenly clear, like a giant die that made an indelible impress, a huge map of the universe outlined itself in one clarified vision. And that is when peace came, and that is when conviction came, and with these things came an almighty calm that nothing could ever shake again, not while Albert Einstein lives...""