LOS ANGELES — A federal appeals court in San Francisco ruled Thursday that the Second Amendment of the Constitution does not guarantee the right of gun owners to carry concealed weapons in public places, upholding a California law that imposes stringent conditions on who may be granted a concealed-carry permit.

The 7-to-4 ruling by the United States Court of Appeals for the Ninth Circuit, in San Francisco, overturned a decision by a three-judge panel of the same court and was a setback for gun advocates. The California law requires applicants to demonstrate “good cause” for carrying a weapon, like working in a job with a security threat — a restriction sharply attacked by gun advocates as violating the Second Amendment right to bear arms.

“Based on the overwhelming consensus of historical sources, we conclude that the protection of the Second Amendment — whatever the scope of that protection may be — simply does not extend to the carrying of concealed firearms in public by members of the general public,” the court said in a ruling written by Judge William A. Fletcher.

The case was brought by gun owners who were denied permits in Yolo and San Diego Counties. The plaintiffs did not immediately say whether they planned to appeal to the United States Supreme Court.