phpCAS  version 1.4.0
example_proxy_GET.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 // force CAS authentication
41 
42 // at this step, the user has been authenticated by the CAS server
43 // and the user's login name can be read with phpCAS::getUser().
44 
45 // moreover, a PGT was retrieved from the CAS server that will
46 // permit to gain accesses to new services.
47 
48 ?>
49 <html>
50  <head>
51  <title>phpCAS proxy example #2</title>
52  <link rel="stylesheet" type='text/css' href='example.css'/>
53  </head>
54  <body>
55  <h1>phpCAS proxied proxy example</h1>
56  <?php require 'script_info.php' ?>
57  <p>the user's login is <b><?php echo phpCAS::getUser(); ?></b>.</p>
58  <h2>Response from service <?php echo $serviceUrl; ?></h2>
59 <?php
60 flush();
61 
62 // call a service and change the color depending on the result
63 try {
64  $service = phpCAS::getProxiedService(PHPCAS_PROXIED_SERVICE_HTTP_GET);
65  $service->setUrl($serviceUrl);
66  $service->send();
67  if ($service->getResponseStatusCode() == 200) {
68  echo '<div class="success">';
69  echo $service->getResponseBody();
70  echo '</div>';
71  } else {
72  // The service responded with an error code 404, 500, etc.
73  echo '<div class="error">';
74  echo 'The service responded with a '
75  . $service->getResponseStatusCode() . ' error.';
76  echo '</div>';
77  }
78 } catch (CAS_ProxyTicketException $e) {
79  if ($e->getCode() == PHPCAS_SERVICE_PT_FAILURE) {
80  echo '<div class="error">';
81  echo "Your login has timed out. You need to log in again.";
82  echo '</div>';
83  } else {
84  // Other proxy ticket errors are from bad request format (shouldn't happen)
85  // or CAS server failure (unlikely) so lets just stop if we hit those.
86  throw $e;
87  }
88 } catch (CAS_ProxiedService_Exception $e) {
89  // Something prevented the service request from being sent or received.
90  // We didn't even get a valid error response (404, 500, etc), so this
91  // might be caused by a network error or a DNS resolution failure.
92  // We could handle it in some way, but for now we will just stop.
93  throw $e;
94 }
95 
96  ?>
97  </body>
98 </html>
static forceAuthentication()
Definition: CAS.php:1146
Definition: CAS.php:281
static proxy($server_version, $server_hostname, $server_port, $server_uri, $changeSessionID=true, \SessionHandlerInterface $sessionHandler=null)
Definition: CAS.php:391
$phpcas_path
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