It looks like CAS Server supports the SAML protocol (perhaps via a module that you need to install in v4). I would recommend you go that route, and implement the SAML module in the Mendix app store. That would allow you to avoid any custom coding. The documentation for that module is pretty thorough.