4 * Advanced example for SAML with attributes and single logout
8 * @file example_advanced_saml.php
9 * @category Authentication
11 * @author Joachim Fritschi <jfritschi@freenet.de>
12 * @author Adam Franco <afranco@middlebury.edu>
13 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
14 * @link https://wiki.jasig.org/display/CASC/phpCAS
17 // Load the settings from the central config file
18 require_once 'config.php';
20 require_once $phpcas_path . '/CAS.php';
22 // Uncomment to enable debugging
26 phpCAS::client(SAML_VERSION_1_1, $cas_host, $cas_port, $cas_context);
28 // For production use set the CA certificate that is the issuer of the cert
29 // on the CAS server and uncomment the line below
30 phpCAS::setCasServerCACert($cas_server_ca_cert_path);
32 // For quick testing you can disable SSL validation of the CAS server.
33 // THIS SETTING IS NOT RECOMMENDED FOR PRODUCTION.
34 // VALIDATING THE CAS SERVER IS CRUCIAL TO THE SECURITY OF THE CAS PROTOCOL!
35 // phpCAS::setNoCasServerValidation();
37 // Handle SAML logout requests that emanate from the CAS host exclusively.
38 // Failure to restrict SAML logout requests to authorized hosts could
39 // allow denial of service attacks where at the least the server is
40 // tied up parsing bogus XML messages.
41 phpCAS::handleLogoutRequests(true, $cas_real_hosts);
43 // Force CAS authentication on any page that includes this file
44 phpCAS::forceAuthentication();
46 // Some small code triggered by the logout button
\r
47 if (isset($_REQUEST['logout'])) {
\r
53 <title>Advanced SAML 1.1 example</title>
56 <h2>Advanced SAML 1.1 example</h2>
57 <?php require 'script_info.php' ?>
59 Authentication succeeded for user
60 <strong><?php echo phpCAS::getUser(); ?></strong>.
62 <h3>User Attributes</h3>
65 foreach (phpCAS::getAttributes() as $key => $value) {
66 if (is_array($value)) {
67 echo '<li>', $key, ':<ol>';
68 foreach ($value as $item) {
69 echo '<li><strong>', $item, '</strong></li>';
73 echo '<li>', $key, ': <strong>', $value, '</strong></li>' . PHP_EOL;
78 <p><a href="?logout=">Logout</a></p>