The High Court yesterday backed random stop-and-search powers for police across London as part of the fight against terrorism.
But the police were told not to target particular groups, including demonstrators, disproportionately.
David Blunkett, the Home Secretary, and Sir John Stevens, the Metropolitan Police commissioner, decided in February 2001 to authorise police to stop and search members of the public at any time. The authorisation has continued since then.
Their decision was challenged in court by Kevin Gillan, 26, a student from Sheffield, and by Pennie Quinton, 32, a freelance photo-journalist from Bermondsey, south-east London. They were backed by the campaign group Liberty.
Both had been stopped and searched on their way to Europe's largest arms fair, at the ExCel Centre in London's Docklands on 9 September.
Lord Justice Brooke and Mr Justice Maurice Kay rejected their challenge.
In the first case of its kind, the judges ruled: "The exercise and use of the power was proportionate to the gravity of the (terrorism) risk."
They added: "If the police wish to use this extraordinary power to stop and search without cause they must exercise it in a way that does not give rise to legitimate complaints of arbitrary abuse of power." The judges also urged the police to review training in the use of stop and search powers. Mr Gillan and Ms Quinton were given leave to appeal.
Mr Blunkett said the ruling showed procedures for authorising the use of the stop-and-search powers under Section 44 of the Terrorism Act 2000 were appropriate.
He said: "This power is an essential part of the range of counter-terrorism measures".
Shami Chakrabarti, a director of Liberty, said: "Ultimately the judges gave deference to the police and Home Secretary in national security issues. We will be seeking to appeal."