LEX INIUSTA NON EST LEX.
An unjust law is no law at all. – St Augustine (On Free Choice of the Will)
A just law is an ordinance of reason, publicly promulgated by one invested with legitimate authority, in the interest of the common good.
If a law does not fulfil these conditions, then it is an unjust law and you have a moral obligation to resist it.
