A federal judge yesterday ruled that two Bay State men — previously convicted of marijuana possession in other states — could not be denied the right to have guns in their homes for self-defense purposes based on their prior drug crimes.

U.S. District Court Judge Richard Stearns ruled that Michael Wesson of Salisbury and Thomas Woods of Natick have a Second Amendment right to own firearms despite being convicted of possessing weed in the past. Sterns said the portion of the Massachusetts Gun Control Act that disqualifies gun applicants who had previously been convicted of possessing a controlled substance was unconstitutional, as applied to the two men.

“What they are seeking is a vindication of their personal Second Amendment rights to purchase and possess firearms for home self-defense,” Stearns wrote. “They also seek, as an extension of the core right of home self-defense, the right, subject to reasonable restrictions, to transport firearms to a shooting range or other lawful location to maintain proficiency in their use.”

The ruling did not toss the state gun law. Rather it showed that those who have previously been convicted of possessing marijuana may be able to get a gun in Massachusetts based on the state’s softened stance on the drug.