I'm not sure how it's done elsewhere but this is how I've always done it
Read more at Impersonating Users