Adding authentication support

I have added authentication support on a per socket basis which is done in a lazy fashion as and when required. The connections also get re-authenticated in the event of a failover. I have been able to test this and confirm that it works. My solution might not be good from a design or architectural standpoint. Your suggestions for improvements are welcome.