the foreach and the two if blocks are identical to handleApacheAuth. Consider adding a method that returns the first active session backend.