phpCAS version 1.3.6

example_service_that_proxies.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::proxy(CAS_VERSION_2_0, $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 // 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 // )));
60 phpCAS::allowProxyChain(new CAS_ProxyChain(array($pgtUrlRegexp)));
61
62 // For quick testing or in certain production screnarios you might want to
63 // allow allow any other valid service to proxy your service. To do so, add
64 // the "Any" chain:
65 // phpCAS::allowProxyChain(new CAS_ProxyChain_Any);
66 // THIS SETTING IS HOWEVER NOT RECOMMENDED FOR PRODUCTION AND HAS SECURITY
67 // IMPLICATIONS: YOU ARE ALLOWING ANY SERVICE TO ACT ON BEHALF OF A USER
68 // ON THIS SERVICE.
69 //phpCAS::allowProxyChain(new CAS_ProxyChain_Any);
70
71 // force CAS authentication
72 phpCAS::forceAuthentication();
73
74 // at this step, the user has been authenticated by the CAS server
75 // and the user's login name can be read with phpCAS::getUser().
76
77 // moreover, a PGT was retrieved from the CAS server that will
78 // permit to gain accesses to new services.
79
80
81
82 ?>
83 <html>
84 <head>
85 <title>phpCAS proxied proxy service example</title>
86 <link rel="stylesheet" type='text/css' href='example.css'/>
87 </head>
88 <body>
89 <h1>I am a service that can be proxied. In turn, I proxy another service.</h1>
90 <?php require 'script_info.php' ?>
91 <p>the user's login is <b><?php echo phpCAS::getUser(); ?></b>.</p>
92 <h2>Response from service <?php echo $serviceUrl; ?></h2>
93 <?php
94 flush();
95 // call a service and change the color depending on the result
96 if ( phpCAS::serviceWeb($serviceUrl, $err_code, $output) ) {
97 echo '<div class="success">';
98 } else {
99 echo '<div class="error">';
100 }
101 echo $output;
102 echo '</div>';
103 ?>
104 </body>
105 </html>
106
$pgtUrlRegexp
$pgtUrlRegexp
Definition: config.example.php:87
phpCAS\forceAuthentication
static forceAuthentication()
Definition: CAS.php:1094
phpCAS
Definition: CAS.php:278
phpCAS\allowProxyChain
static allowProxyChain(CAS_ProxyChain_Interface $proxy_chain)
Definition: CAS.php:1745
$phpcas_path
$phpcas_path
Definition: config.example.php:20
phpCAS\proxy
static proxy($server_version, $server_hostname, $server_port, $server_uri, $changeSessionID=true)
Definition: CAS.php:382
CAS_VERSION_2_0
const CAS_VERSION_2_0
Definition: CAS.php:78
phpCAS\setVerbose
static setVerbose($verbose)
Definition: CAS.php:481
$cas_host
$cas_host
Definition: config.example.php:27
CAS_ProxyChain
Definition: ProxyChain.php:42
$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\setNoCasServerValidation
static setNoCasServerValidation()
Definition: CAS.php:1639