The only limit to the 1st case you describe is given by Kripke's idea of essential properties. Basically, A and B would have to share all of their essential properties if the possible world with swapped names is really possible.
This limit can be really tight. If, for instance, an essential property of people is having a particular DNA, or being born from a particular set of gametes, name swapping can only work for identical twins.
Now, general permutations of rigid designators would require you to start by descriptively describing different possible worlds and then to assign rigid designators to the objects in those worlds. This way of thinking is, according to Kripke, mistaken.
Kripke says in NaN that "you don't see possible worlds through a telescope" and "possible worlds are given by the descriptive conditions we associate with them" (1st conference, not literal quotes, I only have a Spanish edition and am quoting from memory); this remarks mean that, since there's not anything more to possible worlds than the descriptions we use when we describe them, the rigid designators that apply in a possible world have to be already given once we describe it, and it makes no sense to ask which objects in a descriptively specified world are to be called with such and such rigid designators.