phpCAS  version 1.4.0
example_hardening.php
Go to the documentation of this file.
1 <?php
2 
17 // Load the settings from the central config file
18 require_once 'config.php';
19 // Load the CAS lib
20 require_once $phpcas_path . '/CAS.php';
21 
22 // Enable debugging
24 // Enable verbose error messages. Disable in production!
25 phpCAS::setVerbose(false);
26 
27 // Harden session cookie to prevent some attacks on the cookie (e.g. XSS)
29 
30 // Initialize phpCAS
32 
33 // For production use set the CA certificate that is the issuer of the cert
34 // on the CAS server and uncomment the line below
36 
37 // For quick testing you can disable SSL validation of the CAS server.
38 // THIS SETTING IS NOT RECOMMENDED FOR PRODUCTION.
39 // VALIDATING THE CAS SERVER IS CRUCIAL TO THE SECURITY OF THE CAS PROTOCOL!
40 // phpCAS::setNoCasServerValidation();
41 
42 // Handle SAML logout requests that emanate from the CAS host exclusively.
43 // Failure to restrict SAML logout requests to authorized hosts could
44 // allow denial of service attacks where at the least the server is
45 // tied up parsing bogus XML messages.
47 
48 // Force CAS authentication on any page that includes this file
50 
51 // Some small code triggered by the logout button
52 if (isset($_REQUEST['logout'])) {
54 }
55 ?>
56 <html>
57  <head>
58  <title>Advanced SAML 1.1 example</title>
59  </head>
60  <body>
61 <h2>Advanced SAML 1.1 example</h2>
62 <?php require 'script_info.php' ?>
63 
64 Authentication succeeded for user
65 <strong><?php echo phpCAS::getUser(); ?></strong>.
66 
67 <h3>User Attributes</h3>
68 <ul>
69 <?php
70 foreach (phpCAS::getAttributes() as $key => $value) {
71  if (is_array($value)) {
72  echo '<li>', $key, ':<ol>';
73  foreach ($value as $item) {
74  echo '<li><strong>', $item, '</strong></li>';
75  }
76  echo '</ol></li>';
77  } else {
78  echo '<li>', $key, ': <strong>', $value, '</strong></li>' . PHP_EOL;
79  }
80 }
81  ?>
82 </ul>
83 <p><a href="?logout=">Logout</a></p>
84 </body>
85 </html>
$client_domain
$client_path
static forceAuthentication()
Definition: CAS.php:1146
static getUser()
Definition: CAS.php:1227
const SAML_VERSION_1_1
Definition: CAS.php:91
$client_httpOnly
static handleLogoutRequests($check_client=true, $allowed_clients=array())
Definition: CAS.php:1324
$cas_server_ca_cert_path
$cas_real_hosts
static getAttributes()
Definition: CAS.php:1246
$client_secure
static client($server_version, $server_hostname, $server_port, $server_uri, $changeSessionID=true, \SessionHandlerInterface $sessionHandler=null)
Definition: CAS.php:345
$phpcas_path
static setLogger($logger=null)
Definition: CAS.php:448
$client_lifetime
static logout($params="")
Definition: CAS.php:1480
static setCasServerCACert($cert, $validate_cn=true)
Definition: CAS.php:1670
static setVerbose($verbose)
Definition: CAS.php:512
$cas_host
$cas_context
$cas_port