phpCAS version 1.3.6

example_advanced_saml11.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
23 phpCAS::setDebug();
24 // Enable verbose error messages. Disable in production!
25 phpCAS::setVerbose(true);
26
27 // Initialize phpCAS
28 phpCAS::client(SAML_VERSION_1_1, $cas_host, $cas_port, $cas_context);
29
30 // For production use set the CA certificate that is the issuer of the cert
31 // on the CAS server and uncomment the line below
32 phpCAS::setCasServerCACert($cas_server_ca_cert_path);
33
34 // For quick testing you can disable SSL validation of the CAS server.
35 // THIS SETTING IS NOT RECOMMENDED FOR PRODUCTION.
36 // VALIDATING THE CAS SERVER IS CRUCIAL TO THE SECURITY OF THE CAS PROTOCOL!
37 // phpCAS::setNoCasServerValidation();
38
39 // Handle SAML logout requests that emanate from the CAS host exclusively.
40 // Failure to restrict SAML logout requests to authorized hosts could
41 // allow denial of service attacks where at the least the server is
42 // tied up parsing bogus XML messages.
43 phpCAS::handleLogoutRequests(true, $cas_real_hosts);
44
45 // Force CAS authentication on any page that includes this file
46 phpCAS::forceAuthentication();
47
48 // Some small code triggered by the logout button
49 if (isset($_REQUEST['logout'])) {
50 phpCAS::logout();
51 }
52 ?>
53 <html>
54 <head>
55 <title>Advanced SAML 1.1 example</title>
56 </head>
57 <body>
58 <h2>Advanced SAML 1.1 example</h2>
59 <?php require 'script_info.php' ?>
60
61 Authentication succeeded for user
62 <strong><?php echo phpCAS::getUser(); ?></strong>.
63
64 <h3>User Attributes</h3>
65 <ul>
66 <?php
67 foreach (phpCAS::getAttributes() as $key => $value) {
68 if (is_array($value)) {
69 echo '<li>', $key, ':<ol>';
70 foreach ($value as $item) {
71 echo '<li><strong>', $item, '</strong></li>';
72 }
73 echo '</ol></li>';
74 } else {
75 echo '<li>', $key, ': <strong>', $value, '</strong></li>' . PHP_EOL;
76 }
77 }
78 ?>
79 </ul>
80 <p><a href="?logout=">Logout</a></p>
81 </body>
82 </html>
phpCAS\forceAuthentication
static forceAuthentication()
Definition: CAS.php:1094
phpCAS\getUser
static getUser()
Definition: CAS.php:1175
SAML_VERSION_1_1
const SAML_VERSION_1_1
Definition: CAS.php:91
$cas_server_ca_cert_path
$cas_server_ca_cert_path
Definition: config.example.php:36
$cas_real_hosts
$cas_real_hosts
Definition: config.example.php:44
phpCAS\getAttributes
static getAttributes()
Definition: CAS.php:1194
$phpcas_path
$phpcas_path
Definition: config.example.php:20
phpCAS\handleLogoutRequests
static handleLogoutRequests($check_client=true, $allowed_clients=false)
Definition: CAS.php:1272
phpCAS\logout
static logout($params="")
Definition: CAS.php:1430
phpCAS\setCasServerCACert
static setCasServerCACert($cert, $validate_cn=true)
Definition: CAS.php:1620
phpCAS\setVerbose
static setVerbose($verbose)
Definition: CAS.php:481
$cas_host
$cas_host
Definition: config.example.php:27
$cas_context
$cas_context
Definition: config.example.php:30
phpCAS\setDebug
static setDebug($filename='')
Definition: CAS.php:439
$cas_port
$cas_port
Definition: config.example.php:33
phpCAS\client
static client($server_version, $server_hostname, $server_port, $server_uri, $changeSessionID=true)
Definition: CAS.php:338