Displaced people who fled the anti-immigrant violence are seen in a camp on April 19, 2015, in the village of Primrose, 15 km east of Johannesburg. (Marco Longari/AFP/Getty Images)

JOHANNESBURG — Johannesburg Mayor Herman Mashaba seemed to be channeling President Trump when he lashed out at South Africa’s government for failing to crack down on illegal immigration, saying criminally minded foreigners living in South Africa are endangering its citizens.

“I feel sorry for law enforcement agencies that are actually failed by political leadership in this country, with porous borders where South Africa is made to be a haven for criminals,” Mashaba told the country’s public broadcaster last week. “This has got to end.”

Mashaba’s comments came after residents of Rosettenville, a Johannesburg suburb, set fire to several buildings they claimed were housing brothels and drug dens. He said that the buildings’ occupants were Nigerian, and seized on the moment to call attention to the dangers that undocumented immigrants pose to the nation.

South Africa has been a regional leader in its treatment of refugees. Unlike some countries in Africa, where asylum seekers are hosted in camps, South Africa issues permits to registered asylum seekers, allowing them to move freely and work while their cases are reviewed, a process that can take years. Approved refugees enjoy most of the same fundamental rights as South African citizens, thanks to the nation’s liberal constitution, written after the dark days of apartheid.

The government says economic migrants are taking advantage of its generous policies by registering for asylum to get jobs. Officials such as Mashaba worry that some of the migrants may also pose a security threat. “It is difficult not to feel that our national commitment to liberal asylum and refugee policies is not being abused,” Home Affairs Minister Malusi Gigaba said in October. “Immigration is the hard face of sovereignty and requires hard choices to be made.”

Sound familiar?

Now, much like the United States, South Africa is rethinking its role as a refugee haven. The government is mulling an overhaul of its immigration laws, a move critics worry could incite xenophobia, compromise refugee rights and jeopardize South Africa’s moral leadership in Africa.

A green paper — a kind of pre-legislation policy paper — on international migration published last year by the Department of Home Affairs proposes, for instance, to set up processing and detention centers for asylum seekers near the borders. It also proposes that asylum seekers no longer necessarily be granted the right to work, except under exceptional circumstances. Both could strip asylum seekers of crucial benefits, migrant rights groups say.

The paper also includes some measures welcomed by rights groups, such as giving economic migrants from the region more options to work legally in South Africa. That would, in theory, help steer them away from the overburdened asylum system, which the United Nations' refugee agency has said may have a backlog of more than 1 million cases (other experts dispute the number, saying it is likely to be much lower).

But the paper's recasting of immigration as a risk that needs to be mitigated is worrying, said Loren Landau, a professor at the African Center for Migration and Society at Wits University. Refugees have typically been treated by the government as a human rights matter, he said, but “now it is being reframed as a security issue.”

Asylum seekers’ rights are already coming under attack, said Sharon Ekambaram, head of the Refugee and Migrant Rights Program at Lawyers for Human Rights. It has become harder, for instance, for asylum seekers to renew their permits while their cases are reviewed, she says. Her organization has also recorded an increase in instances of people being unlawfully arrested and threatened with deportation back to the countries they fled, including conflict zones such as Burundi and Somalia.

These concerns play into a broader concern among some in South Africa that the nation is losing its moorings as a human rights leader under the populist tenure of President Jacob Zuma. Human Rights Watch’s 2017 World Report said the South African government was failing to protect the right to education, combat violence against women or crack down on anti-immigrant violence, among a number of problems. In 2015, at least five people were killed and thousands displaced after a series of attacks on foreigners’ shops at homes in several cities around the country.

The report also noted South Africa’s announcement in October that it plans to withdraw from the International Criminal Court, widely seen as a move away from a human rights-focused foreign policy.

“The Zuma administration cares very little about the country’s reputation,” Landau said. “They gain political points by rejecting these obligations.”

But as in the United States, where Trump’s executive order on immigration appears due for a tough court battle, South Africa’s policy overhaul is not a done deal. The government has accepted feedback from rights groups on the proposed changes to immigration and refugee laws. And when faced with the overtly xenophobic tone of the Rosettenville violence last week, the home minister condemned attempts to whip up anti-immigrant sentiment.

“Leaders have a responsibility at all times to be measured and consider the fact that as a result of what you say, there could be lives lost,” Gigaba said during a visit to the troubled area on Tuesday, according to local media reports. “South Africa has no desire — nor the capacity — to shut itself off from the rest of the world.”