Harnessing quadratic optical response of two-dimensional materials through active microcavities