phpCAS  version 1.4.0
example_service.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(true);
26 
27 // Initialize phpCAS
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!
38 
39 // If you want your service to be proxied you have to enable it (default
40 // disabled) and define an accepable list of proxies that are allowed to
41 // proxy your service.
42 //
43 // Add each allowed proxy definition object. For the normal CAS_ProxyChain
44 // class, the constructor takes an array of proxies to match. The list is in
45 // reverse just as seen from the service. Proxies have to be defined in reverse
46 // from the service to the user. If a user hits service A and gets proxied via
47 // B to service C the list of acceptable on C would be array(B,A). The definition
48 // of an individual proxy can be either a string or a regexp (preg_match is used)
49 // that will be matched against the proxy list supplied by the cas server
50 // when validating the proxy tickets. The strings are compared starting from
51 // the beginning and must fully match with the proxies in the list.
52 // Example:
53 // phpCAS::allowProxyChain(new CAS_ProxyChain(array(
54 // 'https://app.example.com/'
55 // )));
56 // phpCAS::allowProxyChain(new CAS_ProxyChain(array(
57 // '/^https:\/\/app[0-9]\.example\.com\/rest\//',
58 // 'http://client.example.com/'
59 // )));
62  new CAS_ProxyChain(
63  array('/^' . $pgtBase . 'example_service_that_proxies.php$/',
64  '/^' . $pgtBase . 'example_proxy_serviceWeb_chaining.php$/'
65  )
66  )
67 );
68 
69 // For quick testing or in certain production screnarios you might want to
70 // allow allow any other valid service to proxy your service. To do so, add
71 // the "Any" chain:
72 // phpCAS::allowProxyChain(new CAS_ProxyChain_Any);
73 // THIS SETTING IS HOWEVER NOT RECOMMENDED FOR PRODUCTION AND HAS SECURITY
74 // IMPLICATIONS: YOU ARE ALLOWING ANY SERVICE TO ACT ON BEHALF OF A USER
75 // ON THIS SERVICE.
76 //phpCAS::allowProxyChain(new CAS_ProxyChain_Any);
77 
78 // force CAS authentication
80 
81 print '<h1>I am a service that can be proxied.</h1>';
82 
83 // at this step, the user has been authenticated by the CAS server
84 // and the user's login name can be read with phpCAS::getUser().
85 require 'script_info.php';
86 
87 // for this test, simply print that the authentication was successfull
88 echo '<p>The user\'s login is <b>' . phpCAS::getUser() . '</b>.</p>';
89 
90 // increment the number of requests of the session and print it
91 if (!isset($_SESSION['n'])) {
92  $_SESSION['n'] = 0;
93 }
94 echo '<p>request #' . (++$_SESSION['n']) . '</p>';
95 
96 ?>
$pgtUrlRegexp
static forceAuthentication()
Definition: CAS.php:1146
static getUser()
Definition: CAS.php:1227
static allowProxyChain(CAS_ProxyChain_Interface $proxy_chain)
Definition: CAS.php:1795
static client($server_version, $server_hostname, $server_port, $server_uri, $changeSessionID=true, \SessionHandlerInterface $sessionHandler=null)
Definition: CAS.php:345
$phpcas_path
$pgtBase
static setLogger($logger=null)
Definition: CAS.php:448
const CAS_VERSION_2_0
Definition: CAS.php:78
static setVerbose($verbose)
Definition: CAS.php:512
$cas_host
$cas_context
$cas_port
static setNoCasServerValidation()
Definition: CAS.php:1689