Configure both as Idp and Sp

Hi guys
I have a requirement to setup a portal to be as Idp with certain scenario and also become as Sp if in other scenario. My question is it possible to setup configuration to be as Idp and Sp

Yes. You can include both the IdP and SP configuration in a single saml.config.
The following outlines how this would look.