Loyalty oaths have been tried in the past, but eventually were struck down by the courts as either too vague, or an unconstitutional violation of free speech. These applied, as far as I can tell from reading their history, only to American citizens.
Republican presidential candidate Donald Trump has suggested something different. He wants to screen people coming into America to see if they share American values. Trump says he would exclude not only people who sympathize with terrorists and believe in Sharia law, but those "who do not believe in our Constitution, or who support bigotry and hatred."READ it here