APY-13 : Complete the security gateway

Added better support for handling the complex gateways structure