When is fulfillment of duty a justification for a crime?

For fulfillment of duty to be appreciated as a justifying circumstance, the following must be established: [1] that the offender acted in the lawful exercise of a right or a duty; and [2] that the injury or offense committed be the necessary consequence of the due performance of such right or office. (Ty vs. People, G.R. No. 149275, 27 September 2004, 439 SCRA 220)