In a major blow to immigration advocates, the conservative-leaning Supreme Court has ruled that immigrants – even those with a permanent legal status – can be held indefinitely by federal immigration agents and that they do not have the right to periodic bond hearings, reports NPR.

The Supreme Court’s 5-3 ruling on Tuesday follows a Trump administration appeal of a ruling by the 9th Circuit Court of Appeals last year that imposed a rule requiring immigrants held in custody be given a bond hearing every six months, as long as they aren’t considered a flight risk or a danger to national security. Justice Elena Kagan recused herself from the case.

“To impose a rigid six-month rule like the Court of Appeals did is really a mistake,” Solicitor General Ian Gershengorn said in November.

The Supreme Court’s ruling affirmed the right of the government to detain immigrants indefinitely while it determines whether they should be allowed to remain in the country.

“Immigration officials are authorized to detain certain aliens in the course of immigration proceedings while they determine whether those aliens may be lawfully present in the country,” Justice Samuel Alito wrote in the majority opinion.

The lead plaintiff in the class-action lawsuit, Alejandro Rodriguez, is an immigrant with permanent legal status who was convicted of possession of a controlled substance and joyriding. He was detained by immigration officials for three years without a bond hearing.

The ACLU took up his case, eventually winning his release and the cancellation of his deportation order. The government’s appeal was begun under the Obama administration, and continued after President Trump took office last year.