phpCAS
version 1.4.0
docs
examples
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
23
phpCAS::setLogger
();
24
// Enable verbose error messages. Disable in production!
25
phpCAS::setVerbose
(
true
);
26
27
// Initialize phpCAS
28
phpCAS::client
(
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
phpCAS::allowProxyChain
(
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
79
phpCAS::forceAuthentication
();
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
?>
print
print
Definition:
example_service.php:81
$pgtUrlRegexp
$pgtUrlRegexp
Definition:
config.example.php:87
phpCAS\forceAuthentication
static forceAuthentication()
Definition:
CAS.php:1146
phpCAS\getUser
static getUser()
Definition:
CAS.php:1227
phpCAS\allowProxyChain
static allowProxyChain(CAS_ProxyChain_Interface $proxy_chain)
Definition:
CAS.php:1795
phpCAS\client
static client($server_version, $server_hostname, $server_port, $server_uri, $changeSessionID=true, \SessionHandlerInterface $sessionHandler=null)
Definition:
CAS.php:345
$phpcas_path
$phpcas_path
Definition:
config.example.php:20
$pgtBase
$pgtBase
Definition:
config.example.php:86
phpCAS\setLogger
static setLogger($logger=null)
Definition:
CAS.php:448
CAS_VERSION_2_0
const CAS_VERSION_2_0
Definition:
CAS.php:78
phpCAS\setVerbose
static setVerbose($verbose)
Definition:
CAS.php:512
$cas_host
$cas_host
Definition:
config.example.php:27
CAS_ProxyChain
Definition:
ProxyChain.php:42
$cas_context
$cas_context
Definition:
config.example.php:30
$cas_port
$cas_port
Definition:
config.example.php:33
phpCAS\setNoCasServerValidation
static setNoCasServerValidation()
Definition:
CAS.php:1689
Generated by
1.8.13