Briefly
I think this is just an expression of defiance in the face of the presumably stronger or evenly matched enemy, set on passing certain [narrow] point
I don't think it is to be especially connected to any contemporary (to Tolkien) events, but rather to battle-cries throughout history in general, as uttered by defenders to defy the offenders - as in this case Gandalf is acting defender, denying the passage to Balrog ("This is Spartaaa!" of the 300 movie might have altered perceptions somewhat, but much like Leonides in Thermopylae, kind of)
One of the reasons some ill-disposed critics tended to label LoTR as full of cliches, haven't they now? Replace "cliche" with "archetype", that will take us back to some primordial man at the mouth of the cave, brandishing his club and growling something of the kind to the face of the cave bear intent on spending the night in the same cave...
And ah, I do find the exchange brilliant, and so I think Tolkien might have liked it, even if he wrote it himself