This is certainly a sensible topic and I'm afraid there's no easy answer as it's very dependant on context.
The criteria for rejecting or accepting certain immigrants will vary depending on the cultural and political relationship between the country where each immigrant comes from and the country they intend to relocate to.
Every nation should aspire to generate conditions of tolerance in which ethnic or racial differences don't represent a threat to the safety of their communities. To achieve this, it would require governments a sustained effort to educate its people in favor of diversity and apply policies that encourage freedom and protect civil liberties. However, this is a long and arduous process that history has shown sometimes may take several centuries.
In many cases, the tensions between different ethnicities and cultural backgrounds are so high at the present time, that there's no other way to ensure safety than limiting specific types of immigration in certain regions. That is why to me, it is legitimate for a country to take nationality, race and religion into account when deciding who they let in, as long as the government keeps moving towards tolerance in the long-run.
Hope this helps!