They are all correct.
For lengthier discussions with lots of examples of the use of the past perfect tense after before,
see Re: before past perfect tense , past tense and Re: Past Simple or Past Perfect.
This is a common pattern for expressing "interruptive relationships" between actions. (Leaving university "interrupts" the normal course of events which would have led to exams; the sacking "interrupts" the normal course of events which would have led to an explanation of the behavior.) The main clause contains the "interrupting" action. The before clause contains the "interrupted" action. Because the interrupted action has not taken place, the past perfect may be considered a way of expressing a counterfactual, that is, it may be considered a subjunctive with family resemblances to the if clause of the third conditional, thus: if I had taken the final exam or if he had had a chance to explain.
CJ