A judge in the Netherlands has upheld a new law to ban foreign tourists from entering cannabis cafes.
While soft drugs are tolerated, there is growing concern at tourists visiting just for drugs, and foreign dealers selling illegally at home.
The ban is due to start in three southern provinces next month, and go nationwide by the end of the year.
A group of cafe owners argued at The Hague district court that the ban was discriminatory against foreigners.
Under the new law, Dutch residents will still be allowed into the cafes, as long as they have valid identification, or possibly hold a new "weed pass", which is also being debated.
There are about 700 coffee shops, as they are called, in the Netherlands. The cultivation and sale of soft drugs through them is decriminalised, although not legal; police generally tolerate possession of up to five grams of cannabis.
A lawyer for the coffee shop owners said he would immediately lodge an appeal.
Michael Veling, a spokesman for the Dutch Cannabis Retailers Association, is among those challenging the government plan.
"It is going to cost me 90% of my turnover," he told the BBC World Service. "That is a very good reason for anyone to oppose any plan. Second it puts our customers in a very difficult spot, because why do you have to register to buy a substance that is still illegal?"
The BBC's Anna Holligan in The Hague says the nationwide ban is being strongly opposed by the Mayor of Amsterdam, Eberhard van der Laan, because around a third of the city's tourists visit to smoke cannabis in the cafes.
Lawyer Maurice Veldman, Cannabis Retailers' Association: "We will appeal straight away"
If the coffee shop owners lose their case they say they will take it to the European Court of Human Rights, on the grounds that the Dutch should not be allowed to discriminate against people on the basis of where they live.
The moves are part of a tougher approach to drugs introduced by the coalition conservative-led government, elected 18 months ago.
In October strong cannabis was reclassified as a hard drug, amid concerns that it has a psychotic effect on some users.
The move forced cannabis coffee shops to remove the more popular stronger varieties from their shelves.
In November the city of Maastricht brought in a coffee shop ban for foreign tourists from all countries, except Belgium and Germany, from where the majority of foreign customers come.