1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
/*
|
4
|
|
|
* Copyright © 2003-2010, The ESUP-Portail consortium & the JA-SIG Collaborative.
|
5
|
|
|
* All rights reserved.
|
6
|
|
|
*
|
7
|
|
|
* Redistribution and use in source and binary forms, with or without
|
8
|
|
|
* modification, are permitted provided that the following conditions are met:
|
9
|
|
|
*
|
10
|
|
|
* * Redistributions of source code must retain the above copyright notice,
|
11
|
|
|
* this list of conditions and the following disclaimer.
|
12
|
|
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
13
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
14
|
|
|
* and/or other materials provided with the distribution.
|
15
|
|
|
* * Neither the name of the ESUP-Portail consortium & the JA-SIG
|
16
|
|
|
* Collaborative nor the names of its contributors may be used to endorse or
|
17
|
|
|
* promote products derived from this software without specific prior
|
18
|
|
|
* written permission.
|
19
|
|
|
|
20
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
24
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27
|
|
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
|
|
*/
|
31
|
|
|
|
32
|
|
|
//
|
33
|
|
|
// hack by Vangelis Haniotakis to handle the absence of $_SERVER['REQUEST_URI'] in IIS
|
34
|
|
|
//
|
35
|
|
|
if (!$_SERVER['REQUEST_URI']) {
|
36
|
|
|
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING'];
|
37
|
|
|
}
|
38
|
|
|
|
39
|
|
|
//
|
40
|
|
|
// another one by Vangelis Haniotakis also to make phpCAS work with PHP5
|
41
|
|
|
//
|
42
|
|
|
if (version_compare(PHP_VERSION, '5', '>=')) {
|
43
|
|
|
require_once(dirname(__FILE__) . '/CAS/domxml-php4-to-php5.php');
|
44
|
|
|
}
|
45
|
|
|
|
46
|
|
|
/**
|
47
|
|
|
* @file CAS/CAS.php
|
48
|
|
|
* Interface class of the phpCAS library
|
49
|
|
|
*
|
50
|
|
|
* @ingroup public
|
51
|
|
|
*/
|
52
|
|
|
|
53
|
|
|
// ########################################################################
|
54
|
|
|
// CONSTANTS
|
55
|
|
|
// ########################################################################
|
56
|
|
|
|
57
|
|
|
// ------------------------------------------------------------------------
|
58
|
|
|
// CAS VERSIONS
|
59
|
|
|
// ------------------------------------------------------------------------
|
60
|
|
|
|
61
|
|
|
/**
|
62
|
|
|
* phpCAS version. accessible for the user by phpCAS::getVersion().
|
63
|
|
|
*/
|
64
|
|
|
define('PHPCAS_VERSION', '1.1.1');
|
65
|
|
|
|
66
|
|
|
// ------------------------------------------------------------------------
|
67
|
|
|
// CAS VERSIONS
|
68
|
|
|
// ------------------------------------------------------------------------
|
69
|
|
|
/**
|
70
|
|
|
* @addtogroup public
|
71
|
|
|
* @{
|
72
|
|
|
*/
|
73
|
|
|
|
74
|
|
|
/**
|
75
|
|
|
* CAS version 1.0
|
76
|
|
|
*/
|
77
|
|
|
define("CAS_VERSION_1_0", '1.0');
|
78
|
|
|
/*!
|
79
|
|
|
* CAS version 2.0
|
80
|
|
|
*/
|
81
|
|
|
define("CAS_VERSION_2_0", '2.0');
|
82
|
|
|
|
83
|
|
|
// ------------------------------------------------------------------------
|
84
|
|
|
// SAML defines
|
85
|
|
|
// ------------------------------------------------------------------------
|
86
|
|
|
|
87
|
|
|
/**
|
88
|
|
|
* SAML protocol
|
89
|
|
|
*/
|
90
|
|
|
define("SAML_VERSION_1_1", 'S1');
|
91
|
|
|
|
92
|
|
|
/**
|
93
|
|
|
* XML header for SAML POST
|
94
|
|
|
*/
|
95
|
|
|
define("SAML_XML_HEADER", '<?xml version="1.0" encoding="UTF-8"?>');
|
96
|
|
|
|
97
|
|
|
/**
|
98
|
|
|
* SOAP envelope for SAML POST
|
99
|
|
|
*/
|
100
|
|
|
define("SAML_SOAP_ENV",
|
101
|
|
|
'<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/>');
|
102
|
|
|
|
103
|
|
|
/**
|
104
|
|
|
* SOAP body for SAML POST
|
105
|
|
|
*/
|
106
|
|
|
define("SAML_SOAP_BODY", '<SOAP-ENV:Body>');
|
107
|
|
|
|
108
|
|
|
/**
|
109
|
|
|
* SAMLP request
|
110
|
|
|
*/
|
111
|
|
|
define("SAMLP_REQUEST",
|
112
|
|
|
'<samlp:Request xmlns:samlp="urn:oasis:names:tc:SAML:1.0:protocol" MajorVersion="1" MinorVersion="1" RequestID="_192.168.16.51.1024506224022" IssueInstant="2002-06-19T17:03:44.022Z">');
|
113
|
|
|
define("SAMLP_REQUEST_CLOSE", '</samlp:Request>');
|
114
|
|
|
|
115
|
|
|
/**
|
116
|
|
|
* SAMLP artifact tag (for the ticket)
|
117
|
|
|
*/
|
118
|
|
|
define("SAML_ASSERTION_ARTIFACT", '<samlp:AssertionArtifact>');
|
119
|
|
|
|
120
|
|
|
/**
|
121
|
|
|
* SAMLP close
|
122
|
|
|
*/
|
123
|
|
|
define("SAML_ASSERTION_ARTIFACT_CLOSE", '</samlp:AssertionArtifact>');
|
124
|
|
|
|
125
|
|
|
/**
|
126
|
|
|
* SOAP body close
|
127
|
|
|
*/
|
128
|
|
|
define("SAML_SOAP_BODY_CLOSE", '</SOAP-ENV:Body>');
|
129
|
|
|
|
130
|
|
|
/**
|
131
|
|
|
* SOAP envelope close
|
132
|
|
|
*/
|
133
|
|
|
define("SAML_SOAP_ENV_CLOSE", '</SOAP-ENV:Envelope>');
|
134
|
|
|
|
135
|
|
|
/**
|
136
|
|
|
* SAML Attributes
|
137
|
|
|
*/
|
138
|
|
|
define("SAML_ATTRIBUTES", 'SAMLATTRIBS');
|
139
|
|
|
|
140
|
|
|
/** @} */
|
141
|
|
|
/**
|
142
|
|
|
* @addtogroup publicPGTStorage
|
143
|
|
|
* @{
|
144
|
|
|
*/
|
145
|
|
|
// ------------------------------------------------------------------------
|
146
|
|
|
// FILE PGT STORAGE
|
147
|
|
|
// ------------------------------------------------------------------------
|
148
|
|
|
/**
|
149
|
|
|
* Default path used when storing PGT's to file
|
150
|
|
|
*/
|
151
|
|
|
define("CAS_PGT_STORAGE_FILE_DEFAULT_PATH", '/tmp');
|
152
|
|
|
/**
|
153
|
|
|
* phpCAS::setPGTStorageFile()'s 2nd parameter to write plain text files
|
154
|
|
|
*/
|
155
|
|
|
define("CAS_PGT_STORAGE_FILE_FORMAT_PLAIN", 'plain');
|
156
|
|
|
/**
|
157
|
|
|
* phpCAS::setPGTStorageFile()'s 2nd parameter to write xml files
|
158
|
|
|
*/
|
159
|
|
|
define("CAS_PGT_STORAGE_FILE_FORMAT_XML", 'xml');
|
160
|
|
|
/**
|
161
|
|
|
* Default format used when storing PGT's to file
|
162
|
|
|
*/
|
163
|
|
|
define("CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT", CAS_PGT_STORAGE_FILE_FORMAT_PLAIN);
|
164
|
|
|
// ------------------------------------------------------------------------
|
165
|
|
|
// DATABASE PGT STORAGE
|
166
|
|
|
// ------------------------------------------------------------------------
|
167
|
|
|
/**
|
168
|
|
|
* default database type when storing PGT's to database
|
169
|
|
|
*/
|
170
|
|
|
define("CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE", 'mysql');
|
171
|
|
|
/**
|
172
|
|
|
* default host when storing PGT's to database
|
173
|
|
|
*/
|
174
|
|
|
define("CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME", 'localhost');
|
175
|
|
|
/**
|
176
|
|
|
* default port when storing PGT's to database
|
177
|
|
|
*/
|
178
|
|
|
define("CAS_PGT_STORAGE_DB_DEFAULT_PORT", '');
|
179
|
|
|
/**
|
180
|
|
|
* default database when storing PGT's to database
|
181
|
|
|
*/
|
182
|
|
|
define("CAS_PGT_STORAGE_DB_DEFAULT_DATABASE", 'phpCAS');
|
183
|
|
|
/**
|
184
|
|
|
* default table when storing PGT's to database
|
185
|
|
|
*/
|
186
|
|
|
define("CAS_PGT_STORAGE_DB_DEFAULT_TABLE", 'pgt');
|
187
|
|
|
|
188
|
|
|
/** @} */
|
189
|
|
|
// ------------------------------------------------------------------------
|
190
|
|
|
// SERVICE ACCESS ERRORS
|
191
|
|
|
// ------------------------------------------------------------------------
|
192
|
|
|
/**
|
193
|
|
|
* @addtogroup publicServices
|
194
|
|
|
* @{
|
195
|
|
|
*/
|
196
|
|
|
|
197
|
|
|
/**
|
198
|
|
|
* phpCAS::service() error code on success
|
199
|
|
|
*/
|
200
|
|
|
define("PHPCAS_SERVICE_OK", 0);
|
201
|
|
|
/**
|
202
|
|
|
* phpCAS::service() error code when the PT could not retrieve because
|
203
|
|
|
* the CAS server did not respond.
|
204
|
|
|
*/
|
205
|
|
|
define("PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE", 1);
|
206
|
|
|
/**
|
207
|
|
|
* phpCAS::service() error code when the PT could not retrieve because
|
208
|
|
|
* the response of the CAS server was ill-formed.
|
209
|
|
|
*/
|
210
|
|
|
define("PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE", 2);
|
211
|
|
|
/**
|
212
|
|
|
* phpCAS::service() error code when the PT could not retrieve because
|
213
|
|
|
* the CAS server did not want to.
|
214
|
|
|
*/
|
215
|
|
|
define("PHPCAS_SERVICE_PT_FAILURE", 3);
|
216
|
|
|
/**
|
217
|
|
|
* phpCAS::service() error code when the service was not available.
|
218
|
|
|
*/
|
219
|
|
|
define("PHPCAS_SERVICE_NOT AVAILABLE", 4);
|
220
|
|
|
|
221
|
|
|
/** @} */
|
222
|
|
|
// ------------------------------------------------------------------------
|
223
|
|
|
// LANGUAGES
|
224
|
|
|
// ------------------------------------------------------------------------
|
225
|
|
|
/**
|
226
|
|
|
* @addtogroup publicLang
|
227
|
|
|
* @{
|
228
|
|
|
*/
|
229
|
|
|
|
230
|
|
|
define("PHPCAS_LANG_ENGLISH", 'english');
|
231
|
|
|
define("PHPCAS_LANG_FRENCH", 'french');
|
232
|
|
|
define("PHPCAS_LANG_GREEK", 'greek');
|
233
|
|
|
define("PHPCAS_LANG_GERMAN", 'german');
|
234
|
|
|
define("PHPCAS_LANG_JAPANESE", 'japanese');
|
235
|
|
|
define("PHPCAS_LANG_SPANISH", 'spanish');
|
236
|
|
|
define("PHPCAS_LANG_CATALAN", 'catalan');
|
237
|
|
|
|
238
|
|
|
/** @} */
|
239
|
|
|
|
240
|
|
|
/**
|
241
|
|
|
* @addtogroup internalLang
|
242
|
|
|
* @{
|
243
|
|
|
*/
|
244
|
|
|
|
245
|
|
|
/**
|
246
|
|
|
* phpCAS default language (when phpCAS::setLang() is not used)
|
247
|
|
|
*/
|
248
|
|
|
define("PHPCAS_LANG_DEFAULT", PHPCAS_LANG_ENGLISH);
|
249
|
|
|
|
250
|
|
|
/** @} */
|
251
|
|
|
// ------------------------------------------------------------------------
|
252
|
|
|
// DEBUG
|
253
|
|
|
// ------------------------------------------------------------------------
|
254
|
|
|
/**
|
255
|
|
|
* @addtogroup publicDebug
|
256
|
|
|
* @{
|
257
|
|
|
*/
|
258
|
|
|
|
259
|
|
|
/**
|
260
|
|
|
* The default directory for the debug file under Unix.
|
261
|
|
|
*/
|
262
|
|
|
define('DEFAULT_DEBUG_DIR', '/tmp/');
|
263
|
|
|
|
264
|
|
|
/** @} */
|
265
|
|
|
// ------------------------------------------------------------------------
|
266
|
|
|
// MISC
|
267
|
|
|
// ------------------------------------------------------------------------
|
268
|
|
|
/**
|
269
|
|
|
* @addtogroup internalMisc
|
270
|
|
|
* @{
|
271
|
|
|
*/
|
272
|
|
|
|
273
|
|
|
/**
|
274
|
|
|
* This global variable is used by the interface class phpCAS.
|
275
|
|
|
*
|
276
|
|
|
* @hideinitializer
|
277
|
|
|
*/
|
278
|
|
|
$GLOBALS['PHPCAS_CLIENT'] = null;
|
279
|
|
|
|
280
|
|
|
/**
|
281
|
|
|
* This global variable is used to store where the initializer is called from
|
282
|
|
|
* (to print a comprehensive error in case of multiple calls).
|
283
|
|
|
*
|
284
|
|
|
* @hideinitializer
|
285
|
|
|
*/
|
286
|
|
|
$GLOBALS['PHPCAS_INIT_CALL'] = array(
|
287
|
|
|
'done' => false,
|
288
|
|
|
'file' => '?',
|
289
|
|
|
'line' => -1,
|
290
|
|
|
'method' => '?'
|
291
|
|
|
);
|
292
|
|
|
|
293
|
|
|
/**
|
294
|
|
|
* This global variable is used to store where the method checking
|
295
|
|
|
* the authentication is called from (to print comprehensive errors)
|
296
|
|
|
*
|
297
|
|
|
* @hideinitializer
|
298
|
|
|
*/
|
299
|
|
|
$GLOBALS['PHPCAS_AUTH_CHECK_CALL'] = array(
|
300
|
|
|
'done' => false,
|
301
|
|
|
'file' => '?',
|
302
|
|
|
'line' => -1,
|
303
|
|
|
'method' => '?',
|
304
|
|
|
'result' => false
|
305
|
|
|
);
|
306
|
|
|
|
307
|
|
|
/**
|
308
|
|
|
* This global variable is used to store phpCAS debug mode.
|
309
|
|
|
*
|
310
|
|
|
* @hideinitializer
|
311
|
|
|
*/
|
312
|
|
|
$GLOBALS['PHPCAS_DEBUG'] = array(
|
313
|
|
|
'filename' => '/tmp/cas.log',
|
314
|
|
|
'indent' => 0,
|
315
|
|
|
'unique_id' => ''
|
316
|
|
|
);
|
317
|
|
|
|
318
|
|
|
/** @} */
|
319
|
|
|
|
320
|
|
|
// ########################################################################
|
321
|
|
|
// CLIENT CLASS
|
322
|
|
|
// ########################################################################
|
323
|
|
|
|
324
|
|
|
// include client class
|
325
|
|
|
include_once(dirname(__FILE__) . '/CAS/client.php');
|
326
|
|
|
|
327
|
|
|
// ########################################################################
|
328
|
|
|
// INTERFACE CLASS
|
329
|
|
|
// ########################################################################
|
330
|
|
|
|
331
|
|
|
/**
|
332
|
|
|
* @class phpCAS
|
333
|
|
|
* The phpCAS class is a simple container for the phpCAS library. It provides CAS
|
334
|
|
|
* authentication for web applications written in PHP.
|
335
|
|
|
*
|
336
|
|
|
* @ingroup public
|
337
|
|
|
* @author Pascal Aubry <pascal.aubry at univ-rennes1.fr>
|
338
|
|
|
*
|
339
|
|
|
* \internal All its methods access the same object ($PHPCAS_CLIENT, declared
|
340
|
|
|
* at the end of CAS/client.php).
|
341
|
|
|
*/
|
342
|
|
|
class phpCAS
|
343
|
|
|
{
|
344
|
|
|
|
345
|
|
|
// ########################################################################
|
346
|
|
|
// INITIALIZATION
|
347
|
|
|
// ########################################################################
|
348
|
|
|
|
349
|
|
|
/**
|
350
|
|
|
* @addtogroup publicInit
|
351
|
|
|
* @{
|
352
|
|
|
*/
|
353
|
|
|
|
354
|
|
|
/**
|
355
|
|
|
* phpCAS client initializer.
|
356
|
|
|
* @note Only one of the phpCAS::client() and phpCAS::proxy functions should be
|
357
|
|
|
* called, only once, and before all other methods (except phpCAS::getVersion()
|
358
|
|
|
* and phpCAS::setDebug()).
|
359
|
|
|
*
|
360
|
|
|
* @param $server_version the version of the CAS server
|
361
|
|
|
* @param $server_hostname the hostname of the CAS server
|
362
|
|
|
* @param $server_port the port the CAS server is running on
|
363
|
|
|
* @param $server_uri the URI the CAS server is responding on
|
364
|
|
|
* @param $start_session Have phpCAS start PHP sessions (default true)
|
365
|
|
|
*
|
366
|
|
|
* @return a newly created CASClient object
|
367
|
|
|
*/
|
368
|
|
View Code Duplication |
function client($server_version, $server_hostname, $server_port, $server_uri, $start_session = true)
|
369
|
|
|
{
|
370
|
|
|
global $PHPCAS_CLIENT, $PHPCAS_INIT_CALL;
|
371
|
|
|
|
372
|
|
|
phpCAS:: traceBegin();
|
373
|
|
|
if (is_object($PHPCAS_CLIENT)) {
|
374
|
|
|
phpCAS:: error($PHPCAS_INIT_CALL['method'] . '() has already been called (at ' . $PHPCAS_INIT_CALL['file'] . ':' . $PHPCAS_INIT_CALL['line'] . ')');
|
375
|
|
|
}
|
376
|
|
|
if (gettype($server_version) != 'string') {
|
377
|
|
|
phpCAS:: error('type mismatched for parameter $server_version (should be `string\')');
|
378
|
|
|
}
|
379
|
|
|
if (gettype($server_hostname) != 'string') {
|
380
|
|
|
phpCAS:: error('type mismatched for parameter $server_hostname (should be `string\')');
|
381
|
|
|
}
|
382
|
|
|
if (gettype($server_port) != 'integer') {
|
383
|
|
|
phpCAS:: error('type mismatched for parameter $server_port (should be `integer\')');
|
384
|
|
|
}
|
385
|
|
|
if (gettype($server_uri) != 'string') {
|
386
|
|
|
phpCAS:: error('type mismatched for parameter $server_uri (should be `string\')');
|
387
|
|
|
}
|
388
|
|
|
|
389
|
|
|
// store where the initializer is called from
|
390
|
|
|
$dbg = phpCAS:: backtrace();
|
391
|
|
|
$PHPCAS_INIT_CALL = array(
|
392
|
|
|
'done' => true,
|
393
|
|
|
'file' => $dbg[0]['file'],
|
394
|
|
|
'line' => $dbg[0]['line'],
|
395
|
|
|
'method' => __CLASS__ . '::' . __FUNCTION__
|
396
|
|
|
);
|
397
|
|
|
|
398
|
|
|
// initialize the global object $PHPCAS_CLIENT
|
399
|
|
|
$PHPCAS_CLIENT = new CASClient($server_version, false /*proxy*/
|
400
|
|
|
, $server_hostname, $server_port, $server_uri, $start_session);
|
401
|
|
|
phpCAS:: traceEnd();
|
402
|
|
|
}
|
403
|
|
|
|
404
|
|
|
/**
|
405
|
|
|
* phpCAS proxy initializer.
|
406
|
|
|
* @note Only one of the phpCAS::client() and phpCAS::proxy functions should be
|
407
|
|
|
* called, only once, and before all other methods (except phpCAS::getVersion()
|
408
|
|
|
* and phpCAS::setDebug()).
|
409
|
|
|
*
|
410
|
|
|
* @param $server_version the version of the CAS server
|
411
|
|
|
* @param $server_hostname the hostname of the CAS server
|
412
|
|
|
* @param $server_port the port the CAS server is running on
|
413
|
|
|
* @param $server_uri the URI the CAS server is responding on
|
414
|
|
|
* @param $start_session Have phpCAS start PHP sessions (default true)
|
415
|
|
|
*
|
416
|
|
|
* @return a newly created CASClient object
|
417
|
|
|
*/
|
418
|
|
View Code Duplication |
function proxy($server_version, $server_hostname, $server_port, $server_uri, $start_session = true)
|
419
|
|
|
{
|
420
|
|
|
global $PHPCAS_CLIENT, $PHPCAS_INIT_CALL;
|
421
|
|
|
|
422
|
|
|
phpCAS:: traceBegin();
|
423
|
|
|
if (is_object($PHPCAS_CLIENT)) {
|
424
|
|
|
phpCAS:: error($PHPCAS_INIT_CALL['method'] . '() has already been called (at ' . $PHPCAS_INIT_CALL['file'] . ':' . $PHPCAS_INIT_CALL['line'] . ')');
|
425
|
|
|
}
|
426
|
|
|
if (gettype($server_version) != 'string') {
|
427
|
|
|
phpCAS:: error('type mismatched for parameter $server_version (should be `string\')');
|
428
|
|
|
}
|
429
|
|
|
if (gettype($server_hostname) != 'string') {
|
430
|
|
|
phpCAS:: error('type mismatched for parameter $server_hostname (should be `string\')');
|
431
|
|
|
}
|
432
|
|
|
if (gettype($server_port) != 'integer') {
|
433
|
|
|
phpCAS:: error('type mismatched for parameter $server_port (should be `integer\')');
|
434
|
|
|
}
|
435
|
|
|
if (gettype($server_uri) != 'string') {
|
436
|
|
|
phpCAS:: error('type mismatched for parameter $server_uri (should be `string\')');
|
437
|
|
|
}
|
438
|
|
|
|
439
|
|
|
// store where the initialzer is called from
|
440
|
|
|
$dbg = phpCAS:: backtrace();
|
441
|
|
|
$PHPCAS_INIT_CALL = array(
|
442
|
|
|
'done' => true,
|
443
|
|
|
'file' => $dbg[0]['file'],
|
444
|
|
|
'line' => $dbg[0]['line'],
|
445
|
|
|
'method' => __CLASS__ . '::' . __FUNCTION__
|
446
|
|
|
);
|
447
|
|
|
|
448
|
|
|
// initialize the global object $PHPCAS_CLIENT
|
449
|
|
|
$PHPCAS_CLIENT = new CASClient($server_version, true /*proxy*/
|
450
|
|
|
, $server_hostname, $server_port, $server_uri, $start_session);
|
451
|
|
|
phpCAS:: traceEnd();
|
452
|
|
|
}
|
453
|
|
|
|
454
|
|
|
/** @} */
|
455
|
|
|
// ########################################################################
|
456
|
|
|
// DEBUGGING
|
457
|
|
|
// ########################################################################
|
458
|
|
|
|
459
|
|
|
/**
|
460
|
|
|
* @addtogroup publicDebug
|
461
|
|
|
* @{
|
462
|
|
|
*/
|
463
|
|
|
|
464
|
|
|
/**
|
465
|
|
|
* Set/unset debug mode
|
466
|
|
|
*
|
467
|
|
|
* @param $filename the name of the file used for logging, or FALSE to stop debugging.
|
468
|
|
|
*/
|
469
|
|
|
function setDebug($filename = '')
|
470
|
|
|
{
|
471
|
|
|
global $PHPCAS_DEBUG;
|
472
|
|
|
|
473
|
|
|
if ($filename != false && gettype($filename) != 'string') {
|
|
|
|
|
474
|
|
|
phpCAS:: error('type mismatched for parameter $dbg (should be FALSE or the name of the log file)');
|
475
|
|
|
}
|
476
|
|
|
|
477
|
|
|
if (empty ($filename)) {
|
478
|
|
|
if (preg_match('/^Win.*/', getenv('OS'))) {
|
479
|
|
|
if (isset ($_ENV['TMP'])) {
|
480
|
|
|
$debugDir = $_ENV['TMP'] . '/';
|
481
|
|
|
} else {
|
482
|
|
|
if (isset ($_ENV['TEMP'])) {
|
483
|
|
|
$debugDir = $_ENV['TEMP'] . '/';
|
484
|
|
|
} else {
|
485
|
|
|
$debugDir = '';
|
486
|
|
|
}
|
487
|
|
|
}
|
488
|
|
|
} else {
|
489
|
|
|
$debugDir = DEFAULT_DEBUG_DIR;
|
490
|
|
|
}
|
491
|
|
|
$filename = $debugDir . 'phpCAS.log';
|
492
|
|
|
}
|
493
|
|
|
|
494
|
|
|
if (empty ($PHPCAS_DEBUG['unique_id'])) {
|
495
|
|
|
$PHPCAS_DEBUG['unique_id'] = substr(strtoupper(md5(uniqid(''))), 0, 4);
|
496
|
|
|
}
|
497
|
|
|
|
498
|
|
|
$PHPCAS_DEBUG['filename'] = $filename;
|
499
|
|
|
|
500
|
|
|
phpCAS:: trace('START ******************');
|
501
|
|
|
}
|
502
|
|
|
|
503
|
|
|
/** @} */
|
504
|
|
|
/**
|
505
|
|
|
* @addtogroup internalDebug
|
506
|
|
|
* @{
|
507
|
|
|
*/
|
508
|
|
|
|
509
|
|
|
/**
|
510
|
|
|
* This method is a wrapper for debug_backtrace() that is not available
|
511
|
|
|
* in all PHP versions (>= 4.3.0 only)
|
512
|
|
|
*/
|
513
|
|
|
function backtrace()
|
514
|
|
|
{
|
515
|
|
|
if (function_exists('debug_backtrace')) {
|
516
|
|
|
return debug_backtrace();
|
517
|
|
|
} else {
|
518
|
|
|
// poor man's hack ... but it does work ...
|
519
|
|
|
return array();
|
520
|
|
|
}
|
521
|
|
|
}
|
522
|
|
|
|
523
|
|
|
/**
|
524
|
|
|
* Logs a string in debug mode.
|
525
|
|
|
*
|
526
|
|
|
* @param $str the string to write
|
527
|
|
|
*
|
528
|
|
|
* @private
|
529
|
|
|
*/
|
530
|
|
|
function log($str)
|
531
|
|
|
{
|
532
|
|
|
$indent_str = ".";
|
533
|
|
|
global $PHPCAS_DEBUG;
|
534
|
|
|
|
535
|
|
|
if ($PHPCAS_DEBUG['filename']) {
|
536
|
|
|
for ($i = 0; $i < $PHPCAS_DEBUG['indent']; $i++) {
|
537
|
|
|
$indent_str .= '| ';
|
538
|
|
|
}
|
539
|
|
|
error_log($PHPCAS_DEBUG['unique_id'] . ' ' . $indent_str . $str . "\n", 3, $PHPCAS_DEBUG['filename']);
|
540
|
|
|
}
|
541
|
|
|
|
542
|
|
|
}
|
543
|
|
|
|
544
|
|
|
/**
|
545
|
|
|
* This method is used by interface methods to print an error and where the function
|
546
|
|
|
* was originally called from.
|
547
|
|
|
*
|
548
|
|
|
* @param $msg the message to print
|
549
|
|
|
*
|
550
|
|
|
* @private
|
551
|
|
|
*/
|
552
|
|
|
function error($msg)
|
553
|
|
|
{
|
554
|
|
|
$dbg = phpCAS:: backtrace();
|
555
|
|
|
$function = '?';
|
556
|
|
|
$file = '?';
|
557
|
|
|
$line = '?';
|
558
|
|
|
if (is_array($dbg)) {
|
559
|
|
|
for ($i = 1; $i < sizeof($dbg); $i++) {
|
560
|
|
|
if (is_array($dbg[$i])) {
|
561
|
|
|
if ($dbg[$i]['class'] == __CLASS__) {
|
562
|
|
|
$function = $dbg[$i]['function'];
|
563
|
|
|
$file = $dbg[$i]['file'];
|
564
|
|
|
$line = $dbg[$i]['line'];
|
565
|
|
|
}
|
566
|
|
|
}
|
567
|
|
|
}
|
568
|
|
|
}
|
569
|
|
|
echo "<br />\n<b>phpCAS error</b>: <font color=\"FF0000\"><b>" . __CLASS__ . "::" . $function . '(): ' . htmlentities($msg) . "</b></font> in <b>" . $file . "</b> on line <b>" . $line . "</b><br />\n";
|
570
|
|
|
phpCAS:: trace($msg);
|
571
|
|
|
phpCAS:: traceExit();
|
572
|
|
|
exit ();
|
573
|
|
|
}
|
574
|
|
|
|
575
|
|
|
/**
|
576
|
|
|
* This method is used to log something in debug mode.
|
577
|
|
|
*/
|
578
|
|
|
function trace($str)
|
579
|
|
|
{
|
580
|
|
|
$dbg = phpCAS:: backtrace();
|
581
|
|
|
phpCAS:: log($str . ' [' . basename($dbg[1]['file']) . ':' . $dbg[1]['line'] . ']');
|
582
|
|
|
}
|
583
|
|
|
|
584
|
|
|
/**
|
585
|
|
|
* This method is used to indicate the start of the execution of a function in debug mode.
|
586
|
|
|
*/
|
587
|
|
|
function traceBegin()
|
588
|
|
|
{
|
589
|
|
|
global $PHPCAS_DEBUG;
|
590
|
|
|
|
591
|
|
|
$dbg = phpCAS:: backtrace();
|
592
|
|
|
$str = '=> ';
|
593
|
|
|
if (!empty ($dbg[2]['class'])) {
|
594
|
|
|
$str .= $dbg[2]['class'] . '::';
|
595
|
|
|
}
|
596
|
|
|
$str .= $dbg[2]['function'] . '(';
|
597
|
|
|
if (is_array($dbg[2]['args'])) {
|
598
|
|
|
foreach ($dbg[2]['args'] as $index => $arg) {
|
599
|
|
|
if ($index != 0) {
|
600
|
|
|
$str .= ', ';
|
601
|
|
|
}
|
602
|
|
|
$str .= str_replace("\n", "", var_export($arg, true));
|
603
|
|
|
}
|
604
|
|
|
}
|
605
|
|
|
$str .= ') [' . basename($dbg[2]['file']) . ':' . $dbg[2]['line'] . ']';
|
606
|
|
|
phpCAS:: log($str);
|
607
|
|
|
$PHPCAS_DEBUG['indent']++;
|
608
|
|
|
}
|
609
|
|
|
|
610
|
|
|
/**
|
611
|
|
|
* This method is used to indicate the end of the execution of a function in debug mode.
|
612
|
|
|
*
|
613
|
|
|
* @param $res the result of the function
|
614
|
|
|
*/
|
615
|
|
|
function traceEnd($res = '')
|
616
|
|
|
{
|
617
|
|
|
global $PHPCAS_DEBUG;
|
618
|
|
|
|
619
|
|
|
$PHPCAS_DEBUG['indent']--;
|
620
|
|
|
$dbg = phpCAS:: backtrace();
|
621
|
|
|
$str = '';
|
622
|
|
|
$str .= '<= ' . str_replace("\n", "", var_export($res, true));
|
623
|
|
|
phpCAS:: log($str);
|
624
|
|
|
}
|
625
|
|
|
|
626
|
|
|
/**
|
627
|
|
|
* This method is used to indicate the end of the execution of the program
|
628
|
|
|
*/
|
629
|
|
|
function traceExit()
|
630
|
|
|
{
|
631
|
|
|
global $PHPCAS_DEBUG;
|
632
|
|
|
|
633
|
|
|
phpCAS:: log('exit()');
|
634
|
|
|
while ($PHPCAS_DEBUG['indent'] > 0) {
|
635
|
|
|
phpCAS:: log('-');
|
636
|
|
|
$PHPCAS_DEBUG['indent']--;
|
637
|
|
|
}
|
638
|
|
|
}
|
639
|
|
|
|
640
|
|
|
/** @} */
|
641
|
|
|
// ########################################################################
|
642
|
|
|
// INTERNATIONALIZATION
|
643
|
|
|
// ########################################################################
|
644
|
|
|
/**
|
645
|
|
|
* @addtogroup publicLang
|
646
|
|
|
* @{
|
647
|
|
|
*/
|
648
|
|
|
|
649
|
|
|
/**
|
650
|
|
|
* This method is used to set the language used by phpCAS.
|
651
|
|
|
* @note Can be called only once.
|
652
|
|
|
*
|
653
|
|
|
* @param $lang a string representing the language.
|
654
|
|
|
*
|
655
|
|
|
* @sa PHPCAS_LANG_FRENCH, PHPCAS_LANG_ENGLISH
|
656
|
|
|
*/
|
657
|
|
View Code Duplication |
function setLang($lang)
|
658
|
|
|
{
|
659
|
|
|
global $PHPCAS_CLIENT;
|
660
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
661
|
|
|
phpCAS:: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
|
662
|
|
|
}
|
663
|
|
|
if (gettype($lang) != 'string') {
|
664
|
|
|
phpCAS:: error('type mismatched for parameter $lang (should be `string\')');
|
665
|
|
|
}
|
666
|
|
|
$PHPCAS_CLIENT->setLang($lang);
|
667
|
|
|
}
|
668
|
|
|
|
669
|
|
|
/** @} */
|
670
|
|
|
// ########################################################################
|
671
|
|
|
// VERSION
|
672
|
|
|
// ########################################################################
|
673
|
|
|
/**
|
674
|
|
|
* @addtogroup public
|
675
|
|
|
* @{
|
676
|
|
|
*/
|
677
|
|
|
|
678
|
|
|
/**
|
679
|
|
|
* This method returns the phpCAS version.
|
680
|
|
|
*
|
681
|
|
|
* @return the phpCAS version.
|
682
|
|
|
*/
|
683
|
|
|
function getVersion()
|
684
|
|
|
{
|
685
|
|
|
return PHPCAS_VERSION;
|
686
|
|
|
}
|
687
|
|
|
|
688
|
|
|
/** @} */
|
689
|
|
|
// ########################################################################
|
690
|
|
|
// HTML OUTPUT
|
691
|
|
|
// ########################################################################
|
692
|
|
|
/**
|
693
|
|
|
* @addtogroup publicOutput
|
694
|
|
|
* @{
|
695
|
|
|
*/
|
696
|
|
|
|
697
|
|
|
/**
|
698
|
|
|
* This method sets the HTML header used for all outputs.
|
699
|
|
|
*
|
700
|
|
|
* @param $header the HTML header.
|
701
|
|
|
*/
|
702
|
|
View Code Duplication |
function setHTMLHeader($header)
|
703
|
|
|
{
|
704
|
|
|
global $PHPCAS_CLIENT;
|
705
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
706
|
|
|
phpCAS:: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
|
707
|
|
|
}
|
708
|
|
|
if (gettype($header) != 'string') {
|
709
|
|
|
phpCAS:: error('type mismatched for parameter $header (should be `string\')');
|
710
|
|
|
}
|
711
|
|
|
$PHPCAS_CLIENT->setHTMLHeader($header);
|
712
|
|
|
}
|
713
|
|
|
|
714
|
|
|
/**
|
715
|
|
|
* This method sets the HTML footer used for all outputs.
|
716
|
|
|
*
|
717
|
|
|
* @param $footer the HTML footer.
|
718
|
|
|
*/
|
719
|
|
View Code Duplication |
function setHTMLFooter($footer)
|
720
|
|
|
{
|
721
|
|
|
global $PHPCAS_CLIENT;
|
722
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
723
|
|
|
phpCAS:: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
|
724
|
|
|
}
|
725
|
|
|
if (gettype($footer) != 'string') {
|
726
|
|
|
phpCAS:: error('type mismatched for parameter $footer (should be `string\')');
|
727
|
|
|
}
|
728
|
|
|
$PHPCAS_CLIENT->setHTMLFooter($footer);
|
729
|
|
|
}
|
730
|
|
|
|
731
|
|
|
/** @} */
|
732
|
|
|
// ########################################################################
|
733
|
|
|
// PGT STORAGE
|
734
|
|
|
// ########################################################################
|
735
|
|
|
/**
|
736
|
|
|
* @addtogroup publicPGTStorage
|
737
|
|
|
* @{
|
738
|
|
|
*/
|
739
|
|
|
|
740
|
|
|
/**
|
741
|
|
|
* This method is used to tell phpCAS to store the response of the
|
742
|
|
|
* CAS server to PGT requests onto the filesystem.
|
743
|
|
|
*
|
744
|
|
|
* @param $format the format used to store the PGT's (`plain' and `xml' allowed)
|
745
|
|
|
* @param $path the path where the PGT's should be stored
|
746
|
|
|
*/
|
747
|
|
|
function setPGTStorageFile($format = '', $path = '')
|
748
|
|
|
{
|
749
|
|
|
global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
|
750
|
|
|
|
751
|
|
|
phpCAS:: traceBegin();
|
752
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
753
|
|
|
phpCAS:: error('this method should only be called after ' . __CLASS__ . '::proxy()');
|
754
|
|
|
}
|
755
|
|
|
if (!$PHPCAS_CLIENT->isProxy()) {
|
756
|
|
|
phpCAS:: error('this method should only be called after ' . __CLASS__ . '::proxy()');
|
757
|
|
|
}
|
758
|
|
|
if ($PHPCAS_AUTH_CHECK_CALL['done']) {
|
759
|
|
|
phpCAS:: error('this method should only be called before ' . $PHPCAS_AUTH_CHECK_CALL['method'] . '() (called at ' . $PHPCAS_AUTH_CHECK_CALL['file'] . ':' . $PHPCAS_AUTH_CHECK_CALL['line'] . ')');
|
760
|
|
|
}
|
761
|
|
|
if (gettype($format) != 'string') {
|
762
|
|
|
phpCAS:: error('type mismatched for parameter $format (should be `string\')');
|
763
|
|
|
}
|
764
|
|
|
if (gettype($path) != 'string') {
|
765
|
|
|
phpCAS:: error('type mismatched for parameter $format (should be `string\')');
|
766
|
|
|
}
|
767
|
|
|
$PHPCAS_CLIENT->setPGTStorageFile($format, $path);
|
768
|
|
|
phpCAS:: traceEnd();
|
769
|
|
|
}
|
770
|
|
|
|
771
|
|
|
/**
|
772
|
|
|
* This method is used to tell phpCAS to store the response of the
|
773
|
|
|
* CAS server to PGT requests into a database.
|
774
|
|
|
* @note The connection to the database is done only when needed.
|
775
|
|
|
* As a consequence, bad parameters are detected only when
|
776
|
|
|
* initializing PGT storage, except in debug mode.
|
777
|
|
|
*
|
778
|
|
|
* @param $user the user to access the data with
|
779
|
|
|
* @param $password the user's password
|
780
|
|
|
* @param $database_type the type of the database hosting the data
|
781
|
|
|
* @param $hostname the server hosting the database
|
782
|
|
|
* @param $port the port the server is listening on
|
783
|
|
|
* @param $database the name of the database
|
784
|
|
|
* @param $table the name of the table storing the data
|
785
|
|
|
*/
|
786
|
|
|
function setPGTStorageDB(
|
787
|
|
|
$user,
|
788
|
|
|
$password,
|
789
|
|
|
$database_type = '',
|
790
|
|
|
$hostname = '',
|
791
|
|
|
$port = 0,
|
792
|
|
|
$database = '',
|
793
|
|
|
$table = ''
|
794
|
|
|
) {
|
795
|
|
|
global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
|
796
|
|
|
|
797
|
|
|
phpCAS:: traceBegin();
|
798
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
799
|
|
|
phpCAS:: error('this method should only be called after ' . __CLASS__ . '::proxy()');
|
800
|
|
|
}
|
801
|
|
|
if (!$PHPCAS_CLIENT->isProxy()) {
|
802
|
|
|
phpCAS:: error('this method should only be called after ' . __CLASS__ . '::proxy()');
|
803
|
|
|
}
|
804
|
|
|
if ($PHPCAS_AUTH_CHECK_CALL['done']) {
|
805
|
|
|
phpCAS:: error('this method should only be called before ' . $PHPCAS_AUTH_CHECK_CALL['method'] . '() (called at ' . $PHPCAS_AUTH_CHECK_CALL['file'] . ':' . $PHPCAS_AUTH_CHECK_CALL['line'] . ')');
|
806
|
|
|
}
|
807
|
|
|
if (gettype($user) != 'string') {
|
808
|
|
|
phpCAS:: error('type mismatched for parameter $user (should be `string\')');
|
809
|
|
|
}
|
810
|
|
|
if (gettype($password) != 'string') {
|
811
|
|
|
phpCAS:: error('type mismatched for parameter $password (should be `string\')');
|
812
|
|
|
}
|
813
|
|
|
if (gettype($database_type) != 'string') {
|
814
|
|
|
phpCAS:: error('type mismatched for parameter $database_type (should be `string\')');
|
815
|
|
|
}
|
816
|
|
|
if (gettype($hostname) != 'string') {
|
817
|
|
|
phpCAS:: error('type mismatched for parameter $hostname (should be `string\')');
|
818
|
|
|
}
|
819
|
|
|
if (gettype($port) != 'integer') {
|
820
|
|
|
phpCAS:: error('type mismatched for parameter $port (should be `integer\')');
|
821
|
|
|
}
|
822
|
|
|
if (gettype($database) != 'string') {
|
823
|
|
|
phpCAS:: error('type mismatched for parameter $database (should be `string\')');
|
824
|
|
|
}
|
825
|
|
|
if (gettype($table) != 'string') {
|
826
|
|
|
phpCAS:: error('type mismatched for parameter $table (should be `string\')');
|
827
|
|
|
}
|
828
|
|
|
$PHPCAS_CLIENT->setPGTStorageDB($user, $password, $database_type, $hostname, $port, $database, $table);
|
829
|
|
|
phpCAS:: traceEnd();
|
830
|
|
|
}
|
831
|
|
|
|
832
|
|
|
/** @} */
|
833
|
|
|
// ########################################################################
|
834
|
|
|
// ACCESS TO EXTERNAL SERVICES
|
835
|
|
|
// ########################################################################
|
836
|
|
|
/**
|
837
|
|
|
* @addtogroup publicServices
|
838
|
|
|
* @{
|
839
|
|
|
*/
|
840
|
|
|
|
841
|
|
|
/**
|
842
|
|
|
* This method is used to access an HTTP[S] service.
|
843
|
|
|
*
|
844
|
|
|
* @param $url the service to access.
|
845
|
|
|
* @param $err_code an error code Possible values are PHPCAS_SERVICE_OK (on
|
846
|
|
|
* success), PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE, PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE,
|
847
|
|
|
* PHPCAS_SERVICE_PT_FAILURE, PHPCAS_SERVICE_NOT AVAILABLE.
|
848
|
|
|
* @param $output the output of the service (also used to give an error
|
849
|
|
|
* message on failure).
|
850
|
|
|
*
|
851
|
|
|
* @return TRUE on success, FALSE otherwise (in this later case, $err_code
|
852
|
|
|
* gives the reason why it failed and $output contains an error message).
|
853
|
|
|
*/
|
854
|
|
|
function serviceWeb($url, & $err_code, & $output)
|
855
|
|
|
{
|
856
|
|
|
global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
|
857
|
|
|
|
858
|
|
|
phpCAS:: traceBegin();
|
859
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
860
|
|
|
phpCAS:: error('this method should only be called after ' . __CLASS__ . '::proxy()');
|
861
|
|
|
}
|
862
|
|
|
if (!$PHPCAS_CLIENT->isProxy()) {
|
863
|
|
|
phpCAS:: error('this method should only be called after ' . __CLASS__ . '::proxy()');
|
864
|
|
|
}
|
865
|
|
|
if (!$PHPCAS_AUTH_CHECK_CALL['done']) {
|
866
|
|
|
phpCAS:: error('this method should only be called after the programmer is sure the user has been authenticated (by calling ' . __CLASS__ . '::checkAuthentication() or ' . __CLASS__ . '::forceAuthentication()');
|
867
|
|
|
}
|
868
|
|
|
if (!$PHPCAS_AUTH_CHECK_CALL['result']) {
|
869
|
|
|
phpCAS:: error('authentication was checked (by ' . $PHPCAS_AUTH_CHECK_CALL['method'] . '() at ' . $PHPCAS_AUTH_CHECK_CALL['file'] . ':' . $PHPCAS_AUTH_CHECK_CALL['line'] . ') but the method returned FALSE');
|
870
|
|
|
}
|
871
|
|
|
if (gettype($url) != 'string') {
|
872
|
|
|
phpCAS:: error('type mismatched for parameter $url (should be `string\')');
|
873
|
|
|
}
|
874
|
|
|
|
875
|
|
|
$res = $PHPCAS_CLIENT->serviceWeb($url, $err_code, $output);
|
876
|
|
|
|
877
|
|
|
phpCAS:: traceEnd($res);
|
878
|
|
|
return $res;
|
879
|
|
|
}
|
880
|
|
|
|
881
|
|
|
/**
|
882
|
|
|
* This method is used to access an IMAP/POP3/NNTP service.
|
883
|
|
|
*
|
884
|
|
|
* @param $url a string giving the URL of the service, including the mailing box
|
885
|
|
|
* for IMAP URLs, as accepted by imap_open().
|
886
|
|
|
* @param $service a string giving for CAS retrieve Proxy ticket
|
887
|
|
|
* @param $flags options given to imap_open().
|
888
|
|
|
* @param $err_code an error code Possible values are PHPCAS_SERVICE_OK (on
|
889
|
|
|
* success), PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE, PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE,
|
890
|
|
|
* PHPCAS_SERVICE_PT_FAILURE, PHPCAS_SERVICE_NOT AVAILABLE.
|
891
|
|
|
* @param $err_msg an error message on failure
|
892
|
|
|
* @param $pt the Proxy Ticket (PT) retrieved from the CAS server to access the URL
|
893
|
|
|
* on success, FALSE on error).
|
894
|
|
|
*
|
895
|
|
|
* @return an IMAP stream on success, FALSE otherwise (in this later case, $err_code
|
896
|
|
|
* gives the reason why it failed and $err_msg contains an error message).
|
897
|
|
|
*/
|
898
|
|
|
function serviceMail($url, $service, $flags, & $err_code, & $err_msg, & $pt)
|
899
|
|
|
{
|
900
|
|
|
global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
|
901
|
|
|
|
902
|
|
|
phpCAS:: traceBegin();
|
903
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
904
|
|
|
phpCAS:: error('this method should only be called after ' . __CLASS__ . '::proxy()');
|
905
|
|
|
}
|
906
|
|
|
if (!$PHPCAS_CLIENT->isProxy()) {
|
907
|
|
|
phpCAS:: error('this method should only be called after ' . __CLASS__ . '::proxy()');
|
908
|
|
|
}
|
909
|
|
|
if (!$PHPCAS_AUTH_CHECK_CALL['done']) {
|
910
|
|
|
phpCAS:: error('this method should only be called after the programmer is sure the user has been authenticated (by calling ' . __CLASS__ . '::checkAuthentication() or ' . __CLASS__ . '::forceAuthentication()');
|
911
|
|
|
}
|
912
|
|
|
if (!$PHPCAS_AUTH_CHECK_CALL['result']) {
|
913
|
|
|
phpCAS:: error('authentication was checked (by ' . $PHPCAS_AUTH_CHECK_CALL['method'] . '() at ' . $PHPCAS_AUTH_CHECK_CALL['file'] . ':' . $PHPCAS_AUTH_CHECK_CALL['line'] . ') but the method returned FALSE');
|
914
|
|
|
}
|
915
|
|
|
if (gettype($url) != 'string') {
|
916
|
|
|
phpCAS:: error('type mismatched for parameter $url (should be `string\')');
|
917
|
|
|
}
|
918
|
|
|
|
919
|
|
|
if (gettype($flags) != 'integer') {
|
920
|
|
|
phpCAS:: error('type mismatched for parameter $flags (should be `integer\')');
|
921
|
|
|
}
|
922
|
|
|
|
923
|
|
|
$res = $PHPCAS_CLIENT->serviceMail($url, $service, $flags, $err_code, $err_msg, $pt);
|
924
|
|
|
|
925
|
|
|
phpCAS:: traceEnd($res);
|
926
|
|
|
return $res;
|
927
|
|
|
}
|
928
|
|
|
|
929
|
|
|
/** @} */
|
930
|
|
|
// ########################################################################
|
931
|
|
|
// AUTHENTICATION
|
932
|
|
|
// ########################################################################
|
933
|
|
|
/**
|
934
|
|
|
* @addtogroup publicAuth
|
935
|
|
|
* @{
|
936
|
|
|
*/
|
937
|
|
|
|
938
|
|
|
/**
|
939
|
|
|
* Set the times authentication will be cached before really accessing the CAS server in gateway mode:
|
940
|
|
|
* - -1: check only once, and then never again (until you pree login)
|
941
|
|
|
* - 0: always check
|
942
|
|
|
* - n: check every "n" time
|
943
|
|
|
*
|
944
|
|
|
* @param $n an integer.
|
945
|
|
|
*/
|
946
|
|
View Code Duplication |
function setCacheTimesForAuthRecheck($n)
|
947
|
|
|
{
|
948
|
|
|
global $PHPCAS_CLIENT;
|
949
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
950
|
|
|
phpCAS:: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
|
951
|
|
|
}
|
952
|
|
|
if (gettype($n) != 'integer') {
|
953
|
|
|
phpCAS:: error('type mismatched for parameter $header (should be `string\')');
|
954
|
|
|
}
|
955
|
|
|
$PHPCAS_CLIENT->setCacheTimesForAuthRecheck($n);
|
956
|
|
|
}
|
957
|
|
|
|
958
|
|
|
/**
|
959
|
|
|
* This method is called to check if the user is authenticated (use the gateway feature).
|
960
|
|
|
* @return TRUE when the user is authenticated; otherwise FALSE.
|
961
|
|
|
*/
|
962
|
|
View Code Duplication |
function checkAuthentication()
|
963
|
|
|
{
|
964
|
|
|
global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
|
965
|
|
|
|
966
|
|
|
phpCAS:: traceBegin();
|
967
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
968
|
|
|
phpCAS:: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
|
969
|
|
|
}
|
970
|
|
|
|
971
|
|
|
$auth = $PHPCAS_CLIENT->checkAuthentication();
|
972
|
|
|
|
973
|
|
|
// store where the authentication has been checked and the result
|
974
|
|
|
$dbg = phpCAS:: backtrace();
|
975
|
|
|
$PHPCAS_AUTH_CHECK_CALL = array(
|
976
|
|
|
'done' => true,
|
977
|
|
|
'file' => $dbg[0]['file'],
|
978
|
|
|
'line' => $dbg[0]['line'],
|
979
|
|
|
'method' => __CLASS__ . '::' . __FUNCTION__,
|
980
|
|
|
'result' => $auth
|
981
|
|
|
);
|
982
|
|
|
phpCAS:: traceEnd($auth);
|
983
|
|
|
return $auth;
|
984
|
|
|
}
|
985
|
|
|
|
986
|
|
|
/**
|
987
|
|
|
* This method is called to force authentication if the user was not already
|
988
|
|
|
* authenticated. If the user is not authenticated, halt by redirecting to
|
989
|
|
|
* the CAS server.
|
990
|
|
|
*/
|
991
|
|
|
function forceAuthentication()
|
992
|
|
|
{
|
993
|
|
|
global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
|
994
|
|
|
|
995
|
|
|
phpCAS:: traceBegin();
|
996
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
997
|
|
|
phpCAS:: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
|
998
|
|
|
}
|
999
|
|
|
|
1000
|
|
|
$auth = $PHPCAS_CLIENT->forceAuthentication();
|
1001
|
|
|
|
1002
|
|
|
// store where the authentication has been checked and the result
|
1003
|
|
|
$dbg = phpCAS:: backtrace();
|
1004
|
|
|
$PHPCAS_AUTH_CHECK_CALL = array(
|
1005
|
|
|
'done' => true,
|
1006
|
|
|
'file' => $dbg[0]['file'],
|
1007
|
|
|
'line' => $dbg[0]['line'],
|
1008
|
|
|
'method' => __CLASS__ . '::' . __FUNCTION__,
|
1009
|
|
|
'result' => $auth
|
1010
|
|
|
);
|
1011
|
|
|
|
1012
|
|
|
if (!$auth) {
|
1013
|
|
|
phpCAS:: trace('user is not authenticated, redirecting to the CAS server');
|
1014
|
|
|
$PHPCAS_CLIENT->forceAuthentication();
|
1015
|
|
|
} else {
|
1016
|
|
|
phpCAS:: trace('no need to authenticate (user `' . phpCAS:: getUser() . '\' is already authenticated)');
|
1017
|
|
|
}
|
1018
|
|
|
|
1019
|
|
|
phpCAS:: traceEnd();
|
1020
|
|
|
return $auth;
|
1021
|
|
|
}
|
1022
|
|
|
|
1023
|
|
|
/**
|
1024
|
|
|
* This method is called to renew the authentication.
|
1025
|
|
|
**/
|
1026
|
|
|
function renewAuthentication()
|
1027
|
|
|
{
|
1028
|
|
|
global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
|
1029
|
|
|
|
1030
|
|
|
phpCAS:: traceBegin();
|
1031
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
1032
|
|
|
phpCAS:: error('this method should not be called before' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
|
1033
|
|
|
}
|
1034
|
|
|
|
1035
|
|
|
// store where the authentication has been checked and the result
|
1036
|
|
|
$dbg = phpCAS:: backtrace();
|
1037
|
|
|
$PHPCAS_AUTH_CHECK_CALL = array(
|
1038
|
|
|
'done' => true,
|
1039
|
|
|
'file' => $dbg[0]['file'],
|
1040
|
|
|
'line' => $dbg[0]['line'],
|
1041
|
|
|
'method' => __CLASS__ . '::' . __FUNCTION__,
|
1042
|
|
|
'result' => $auth
|
|
|
|
|
1043
|
|
|
);
|
1044
|
|
|
|
1045
|
|
|
$PHPCAS_CLIENT->renewAuthentication();
|
1046
|
|
|
phpCAS:: traceEnd();
|
1047
|
|
|
}
|
1048
|
|
|
|
1049
|
|
|
/**
|
1050
|
|
|
* This method has been left from version 0.4.1 for compatibility reasons.
|
1051
|
|
|
*/
|
1052
|
|
|
function authenticate()
|
1053
|
|
|
{
|
1054
|
|
|
phpCAS:: error('this method is deprecated. You should use ' . __CLASS__ . '::forceAuthentication() instead');
|
1055
|
|
|
}
|
1056
|
|
|
|
1057
|
|
|
/**
|
1058
|
|
|
* This method is called to check if the user is authenticated (previously or by
|
1059
|
|
|
* tickets given in the URL).
|
1060
|
|
|
*
|
1061
|
|
|
* @return TRUE when the user is authenticated.
|
1062
|
|
|
*/
|
1063
|
|
View Code Duplication |
function isAuthenticated()
|
1064
|
|
|
{
|
1065
|
|
|
global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
|
1066
|
|
|
|
1067
|
|
|
phpCAS:: traceBegin();
|
1068
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
1069
|
|
|
phpCAS:: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
|
1070
|
|
|
}
|
1071
|
|
|
|
1072
|
|
|
// call the isAuthenticated method of the global $PHPCAS_CLIENT object
|
1073
|
|
|
$auth = $PHPCAS_CLIENT->isAuthenticated();
|
1074
|
|
|
|
1075
|
|
|
// store where the authentication has been checked and the result
|
1076
|
|
|
$dbg = phpCAS:: backtrace();
|
1077
|
|
|
$PHPCAS_AUTH_CHECK_CALL = array(
|
1078
|
|
|
'done' => true,
|
1079
|
|
|
'file' => $dbg[0]['file'],
|
1080
|
|
|
'line' => $dbg[0]['line'],
|
1081
|
|
|
'method' => __CLASS__ . '::' . __FUNCTION__,
|
1082
|
|
|
'result' => $auth
|
1083
|
|
|
);
|
1084
|
|
|
phpCAS:: traceEnd($auth);
|
1085
|
|
|
return $auth;
|
1086
|
|
|
}
|
1087
|
|
|
|
1088
|
|
|
/**
|
1089
|
|
|
* Checks whether authenticated based on $_SESSION. Useful to avoid
|
1090
|
|
|
* server calls.
|
1091
|
|
|
* @return true if authenticated, false otherwise.
|
1092
|
|
|
* @since 0.4.22 by Brendan Arnold
|
1093
|
|
|
*/
|
1094
|
|
View Code Duplication |
function isSessionAuthenticated()
|
1095
|
|
|
{
|
1096
|
|
|
global $PHPCAS_CLIENT;
|
1097
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
1098
|
|
|
phpCAS:: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
|
1099
|
|
|
}
|
1100
|
|
|
return ($PHPCAS_CLIENT->isSessionAuthenticated());
|
1101
|
|
|
}
|
1102
|
|
|
|
1103
|
|
|
/**
|
1104
|
|
|
* This method returns the CAS user's login name.
|
1105
|
|
|
* @warning should not be called only after phpCAS::forceAuthentication()
|
1106
|
|
|
* or phpCAS::checkAuthentication().
|
1107
|
|
|
*
|
1108
|
|
|
* @return the login name of the authenticated user
|
1109
|
|
|
*/
|
1110
|
|
View Code Duplication |
function getUser()
|
1111
|
|
|
{
|
1112
|
|
|
global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
|
1113
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
1114
|
|
|
phpCAS:: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
|
1115
|
|
|
}
|
1116
|
|
|
if (!$PHPCAS_AUTH_CHECK_CALL['done']) {
|
1117
|
|
|
phpCAS:: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
|
1118
|
|
|
}
|
1119
|
|
|
if (!$PHPCAS_AUTH_CHECK_CALL['result']) {
|
1120
|
|
|
phpCAS:: error('authentication was checked (by ' . $PHPCAS_AUTH_CHECK_CALL['method'] . '() at ' . $PHPCAS_AUTH_CHECK_CALL['file'] . ':' . $PHPCAS_AUTH_CHECK_CALL['line'] . ') but the method returned FALSE');
|
1121
|
|
|
}
|
1122
|
|
|
return $PHPCAS_CLIENT->getUser();
|
1123
|
|
|
}
|
1124
|
|
|
|
1125
|
|
|
/**
|
1126
|
|
|
* This method returns the CAS user's login name.
|
1127
|
|
|
* @warning should not be called only after phpCAS::forceAuthentication()
|
1128
|
|
|
* or phpCAS::checkAuthentication().
|
1129
|
|
|
*
|
1130
|
|
|
* @return the login name of the authenticated user
|
1131
|
|
|
*/
|
1132
|
|
View Code Duplication |
function getAttributes()
|
1133
|
|
|
{
|
1134
|
|
|
global $PHPCAS_CLIENT, $PHPCAS_AUTH_CHECK_CALL;
|
1135
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
1136
|
|
|
phpCAS:: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
|
1137
|
|
|
}
|
1138
|
|
|
if (!$PHPCAS_AUTH_CHECK_CALL['done']) {
|
1139
|
|
|
phpCAS:: error('this method should only be called after ' . __CLASS__ . '::forceAuthentication() or ' . __CLASS__ . '::isAuthenticated()');
|
1140
|
|
|
}
|
1141
|
|
|
if (!$PHPCAS_AUTH_CHECK_CALL['result']) {
|
1142
|
|
|
phpCAS:: error('authentication was checked (by ' . $PHPCAS_AUTH_CHECK_CALL['method'] . '() at ' . $PHPCAS_AUTH_CHECK_CALL['file'] . ':' . $PHPCAS_AUTH_CHECK_CALL['line'] . ') but the method returned FALSE');
|
1143
|
|
|
}
|
1144
|
|
|
return $PHPCAS_CLIENT->getAttributes();
|
1145
|
|
|
}
|
1146
|
|
|
|
1147
|
|
|
/**
|
1148
|
|
|
* Handle logout requests.
|
1149
|
|
|
*/
|
1150
|
|
|
function handleLogoutRequests($check_client = true, $allowed_clients = false)
|
1151
|
|
|
{
|
1152
|
|
|
global $PHPCAS_CLIENT;
|
1153
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
1154
|
|
|
phpCAS:: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
|
1155
|
|
|
}
|
1156
|
|
|
return ($PHPCAS_CLIENT->handleLogoutRequests($check_client, $allowed_clients));
|
1157
|
|
|
}
|
1158
|
|
|
|
1159
|
|
|
/**
|
1160
|
|
|
* This method returns the URL to be used to login.
|
1161
|
|
|
* or phpCAS::isAuthenticated().
|
1162
|
|
|
*
|
1163
|
|
|
* @return the login name of the authenticated user
|
1164
|
|
|
*/
|
1165
|
|
View Code Duplication |
function getServerLoginURL()
|
1166
|
|
|
{
|
1167
|
|
|
global $PHPCAS_CLIENT;
|
1168
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
1169
|
|
|
phpCAS:: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
|
1170
|
|
|
}
|
1171
|
|
|
return $PHPCAS_CLIENT->getServerLoginURL();
|
1172
|
|
|
}
|
1173
|
|
|
|
1174
|
|
|
/**
|
1175
|
|
|
* Set the login URL of the CAS server.
|
1176
|
|
|
* @param $url the login URL
|
1177
|
|
|
* @since 0.4.21 by Wyman Chan
|
1178
|
|
|
*/
|
1179
|
|
View Code Duplication |
function setServerLoginURL($url = '')
|
1180
|
|
|
{
|
1181
|
|
|
global $PHPCAS_CLIENT;
|
1182
|
|
|
phpCAS:: traceBegin();
|
1183
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
1184
|
|
|
phpCAS:: error('this method should only be called after
|
1185
|
|
|
' . __CLASS__ . '::client()');
|
1186
|
|
|
}
|
1187
|
|
|
if (gettype($url) != 'string') {
|
1188
|
|
|
phpCAS:: error('type mismatched for parameter $url (should be
|
1189
|
|
|
`string\')');
|
1190
|
|
|
}
|
1191
|
|
|
$PHPCAS_CLIENT->setServerLoginURL($url);
|
1192
|
|
|
phpCAS:: traceEnd();
|
1193
|
|
|
}
|
1194
|
|
|
|
1195
|
|
|
/**
|
1196
|
|
|
* Set the serviceValidate URL of the CAS server.
|
1197
|
|
|
* Used only in CAS 1.0 validations
|
1198
|
|
|
* @param $url the serviceValidate URL
|
1199
|
|
|
* @since 1.1.0 by Joachim Fritschi
|
1200
|
|
|
*/
|
1201
|
|
View Code Duplication |
function setServerServiceValidateURL($url = '')
|
1202
|
|
|
{
|
1203
|
|
|
global $PHPCAS_CLIENT;
|
1204
|
|
|
phpCAS:: traceBegin();
|
1205
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
1206
|
|
|
phpCAS:: error('this method should only be called after
|
1207
|
|
|
' . __CLASS__ . '::client()');
|
1208
|
|
|
}
|
1209
|
|
|
if (gettype($url) != 'string') {
|
1210
|
|
|
phpCAS:: error('type mismatched for parameter $url (should be
|
1211
|
|
|
`string\')');
|
1212
|
|
|
}
|
1213
|
|
|
$PHPCAS_CLIENT->setServerServiceValidateURL($url);
|
1214
|
|
|
phpCAS:: traceEnd();
|
1215
|
|
|
}
|
1216
|
|
|
|
1217
|
|
|
/**
|
1218
|
|
|
* Set the proxyValidate URL of the CAS server.
|
1219
|
|
|
* Used for all CAS 2.0 validations
|
1220
|
|
|
* @param $url the proxyValidate URL
|
1221
|
|
|
* @since 1.1.0 by Joachim Fritschi
|
1222
|
|
|
*/
|
1223
|
|
View Code Duplication |
function setServerProxyValidateURL($url = '')
|
1224
|
|
|
{
|
1225
|
|
|
global $PHPCAS_CLIENT;
|
1226
|
|
|
phpCAS:: traceBegin();
|
1227
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
1228
|
|
|
phpCAS:: error('this method should only be called after
|
1229
|
|
|
' . __CLASS__ . '::client()');
|
1230
|
|
|
}
|
1231
|
|
|
if (gettype($url) != 'string') {
|
1232
|
|
|
phpCAS:: error('type mismatched for parameter $url (should be
|
1233
|
|
|
`string\')');
|
1234
|
|
|
}
|
1235
|
|
|
$PHPCAS_CLIENT->setServerProxyValidateURL($url);
|
1236
|
|
|
phpCAS:: traceEnd();
|
1237
|
|
|
}
|
1238
|
|
|
|
1239
|
|
|
/**
|
1240
|
|
|
* Set the samlValidate URL of the CAS server.
|
1241
|
|
|
* @param $url the samlValidate URL
|
1242
|
|
|
* @since 1.1.0 by Joachim Fritschi
|
1243
|
|
|
*/
|
1244
|
|
View Code Duplication |
function setServerSamlValidateURL($url = '')
|
1245
|
|
|
{
|
1246
|
|
|
global $PHPCAS_CLIENT;
|
1247
|
|
|
phpCAS:: traceBegin();
|
1248
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
1249
|
|
|
phpCAS:: error('this method should only be called after
|
1250
|
|
|
' . __CLASS__ . '::client()');
|
1251
|
|
|
}
|
1252
|
|
|
if (gettype($url) != 'string') {
|
1253
|
|
|
phpCAS:: error('type mismatched for parameter $url (should be
|
1254
|
|
|
`string\')');
|
1255
|
|
|
}
|
1256
|
|
|
$PHPCAS_CLIENT->setServerSamlValidateURL($url);
|
1257
|
|
|
phpCAS:: traceEnd();
|
1258
|
|
|
}
|
1259
|
|
|
|
1260
|
|
|
/**
|
1261
|
|
|
* This method returns the URL to be used to login.
|
1262
|
|
|
* or phpCAS::isAuthenticated().
|
1263
|
|
|
*
|
1264
|
|
|
* @return the login name of the authenticated user
|
1265
|
|
|
*/
|
1266
|
|
View Code Duplication |
function getServerLogoutURL()
|
1267
|
|
|
{
|
1268
|
|
|
global $PHPCAS_CLIENT;
|
1269
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
1270
|
|
|
phpCAS:: error('this method should not be called before ' . __CLASS__ . '::client() or ' . __CLASS__ . '::proxy()');
|
1271
|
|
|
}
|
1272
|
|
|
return $PHPCAS_CLIENT->getServerLogoutURL();
|
1273
|
|
|
}
|
1274
|
|
|
|
1275
|
|
|
/**
|
1276
|
|
|
* Set the logout URL of the CAS server.
|
1277
|
|
|
* @param $url the logout URL
|
1278
|
|
|
* @since 0.4.21 by Wyman Chan
|
1279
|
|
|
*/
|
1280
|
|
View Code Duplication |
function setServerLogoutURL($url = '')
|
1281
|
|
|
{
|
1282
|
|
|
global $PHPCAS_CLIENT;
|
1283
|
|
|
phpCAS:: traceBegin();
|
1284
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
1285
|
|
|
phpCAS:: error('this method should only be called after
|
1286
|
|
|
' . __CLASS__ . '::client()');
|
1287
|
|
|
}
|
1288
|
|
|
if (gettype($url) != 'string') {
|
1289
|
|
|
phpCAS:: error('type mismatched for parameter $url (should be
|
1290
|
|
|
`string\')');
|
1291
|
|
|
}
|
1292
|
|
|
$PHPCAS_CLIENT->setServerLogoutURL($url);
|
1293
|
|
|
phpCAS:: traceEnd();
|
1294
|
|
|
}
|
1295
|
|
|
|
1296
|
|
|
/**
|
1297
|
|
|
* This method is used to logout from CAS.
|
1298
|
|
|
* @params $params an array that contains the optional url and service parameters that will be passed to the CAS server
|
1299
|
|
|
* @public
|
1300
|
|
|
*/
|
1301
|
|
|
function logout($params = "")
|
1302
|
|
|
{
|
1303
|
|
|
global $PHPCAS_CLIENT;
|
1304
|
|
|
phpCAS:: traceBegin();
|
1305
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
1306
|
|
|
phpCAS:: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
|
1307
|
|
|
}
|
1308
|
|
|
$parsedParams = array();
|
1309
|
|
|
if ($params != "") {
|
1310
|
|
|
if (is_string($params)) {
|
1311
|
|
|
phpCAS:: error('method `phpCAS::logout($url)\' is now deprecated, use `phpCAS::logoutWithUrl($url)\' instead');
|
1312
|
|
|
}
|
1313
|
|
|
if (!is_array($params)) {
|
1314
|
|
|
phpCAS:: error('type mismatched for parameter $params (should be `array\')');
|
1315
|
|
|
}
|
1316
|
|
|
foreach ($params as $key => $value) {
|
|
|
|
|
1317
|
|
|
if ($key != "service" && $key != "url") {
|
1318
|
|
|
phpCAS:: error('only `url\' and `service\' parameters are allowed for method `phpCAS::logout($params)\'');
|
1319
|
|
|
}
|
1320
|
|
|
$parsedParams[$key] = $value;
|
1321
|
|
|
}
|
1322
|
|
|
}
|
1323
|
|
|
$PHPCAS_CLIENT->logout($parsedParams);
|
1324
|
|
|
// never reached
|
1325
|
|
|
phpCAS:: traceEnd();
|
1326
|
|
|
}
|
1327
|
|
|
|
1328
|
|
|
/**
|
1329
|
|
|
* This method is used to logout from CAS. Halts by redirecting to the CAS server.
|
1330
|
|
|
* @param $service a URL that will be transmitted to the CAS server
|
1331
|
|
|
*/
|
1332
|
|
View Code Duplication |
function logoutWithRedirectService($service)
|
1333
|
|
|
{
|
1334
|
|
|
global $PHPCAS_CLIENT;
|
1335
|
|
|
phpCAS:: traceBegin();
|
1336
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
1337
|
|
|
phpCAS:: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
|
1338
|
|
|
}
|
1339
|
|
|
if (!is_string($service)) {
|
1340
|
|
|
phpCAS:: error('type mismatched for parameter $service (should be `string\')');
|
1341
|
|
|
}
|
1342
|
|
|
$PHPCAS_CLIENT->logout(array(
|
1343
|
|
|
"service" => $service
|
1344
|
|
|
));
|
1345
|
|
|
// never reached
|
1346
|
|
|
phpCAS:: traceEnd();
|
1347
|
|
|
}
|
1348
|
|
|
|
1349
|
|
|
/**
|
1350
|
|
|
* This method is used to logout from CAS. Halts by redirecting to the CAS server.
|
1351
|
|
|
* @param $url a URL that will be transmitted to the CAS server
|
1352
|
|
|
*/
|
1353
|
|
View Code Duplication |
function logoutWithUrl($url)
|
1354
|
|
|
{
|
1355
|
|
|
global $PHPCAS_CLIENT;
|
1356
|
|
|
phpCAS:: traceBegin();
|
1357
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
1358
|
|
|
phpCAS:: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
|
1359
|
|
|
}
|
1360
|
|
|
if (!is_string($url)) {
|
1361
|
|
|
phpCAS:: error('type mismatched for parameter $url (should be `string\')');
|
1362
|
|
|
}
|
1363
|
|
|
$PHPCAS_CLIENT->logout(array(
|
1364
|
|
|
"url" => $url
|
1365
|
|
|
));
|
1366
|
|
|
// never reached
|
1367
|
|
|
phpCAS:: traceEnd();
|
1368
|
|
|
}
|
1369
|
|
|
|
1370
|
|
|
/**
|
1371
|
|
|
* This method is used to logout from CAS. Halts by redirecting to the CAS server.
|
1372
|
|
|
* @param $service a URL that will be transmitted to the CAS server
|
1373
|
|
|
* @param $url a URL that will be transmitted to the CAS server
|
1374
|
|
|
*/
|
1375
|
|
|
function logoutWithRedirectServiceAndUrl($service, $url)
|
1376
|
|
|
{
|
1377
|
|
|
global $PHPCAS_CLIENT;
|
1378
|
|
|
phpCAS:: traceBegin();
|
1379
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
1380
|
|
|
phpCAS:: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
|
1381
|
|
|
}
|
1382
|
|
|
if (!is_string($service)) {
|
1383
|
|
|
phpCAS:: error('type mismatched for parameter $service (should be `string\')');
|
1384
|
|
|
}
|
1385
|
|
|
if (!is_string($url)) {
|
1386
|
|
|
phpCAS:: error('type mismatched for parameter $url (should be `string\')');
|
1387
|
|
|
}
|
1388
|
|
|
$PHPCAS_CLIENT->logout(array(
|
1389
|
|
|
"service" => $service,
|
1390
|
|
|
"url" => $url
|
1391
|
|
|
));
|
1392
|
|
|
// never reached
|
1393
|
|
|
phpCAS:: traceEnd();
|
1394
|
|
|
}
|
1395
|
|
|
|
1396
|
|
|
/**
|
1397
|
|
|
* Set the fixed URL that will be used by the CAS server to transmit the PGT.
|
1398
|
|
|
* When this method is not called, a phpCAS script uses its own URL for the callback.
|
1399
|
|
|
*
|
1400
|
|
|
* @param $url the URL
|
1401
|
|
|
*/
|
1402
|
|
|
function setFixedCallbackURL($url = '')
|
1403
|
|
|
{
|
1404
|
|
|
global $PHPCAS_CLIENT;
|
1405
|
|
|
phpCAS:: traceBegin();
|
1406
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
1407
|
|
|
phpCAS:: error('this method should only be called after ' . __CLASS__ . '::proxy()');
|
1408
|
|
|
}
|
1409
|
|
|
if (!$PHPCAS_CLIENT->isProxy()) {
|
1410
|
|
|
phpCAS:: error('this method should only be called after ' . __CLASS__ . '::proxy()');
|
1411
|
|
|
}
|
1412
|
|
|
if (gettype($url) != 'string') {
|
1413
|
|
|
phpCAS:: error('type mismatched for parameter $url (should be `string\')');
|
1414
|
|
|
}
|
1415
|
|
|
$PHPCAS_CLIENT->setCallbackURL($url);
|
1416
|
|
|
phpCAS:: traceEnd();
|
1417
|
|
|
}
|
1418
|
|
|
|
1419
|
|
|
/**
|
1420
|
|
|
* Set the fixed URL that will be set as the CAS service parameter. When this
|
1421
|
|
|
* method is not called, a phpCAS script uses its own URL.
|
1422
|
|
|
*
|
1423
|
|
|
* @param $url the URL
|
1424
|
|
|
*/
|
1425
|
|
|
function setFixedServiceURL($url)
|
1426
|
|
|
{
|
1427
|
|
|
global $PHPCAS_CLIENT;
|
1428
|
|
|
phpCAS:: traceBegin();
|
1429
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
1430
|
|
|
phpCAS:: error('this method should only be called after ' . __CLASS__ . '::proxy()');
|
1431
|
|
|
}
|
1432
|
|
|
if (gettype($url) != 'string') {
|
1433
|
|
|
phpCAS:: error('type mismatched for parameter $url (should be `string\')');
|
1434
|
|
|
}
|
1435
|
|
|
$PHPCAS_CLIENT->setURL($url);
|
1436
|
|
|
phpCAS:: traceEnd();
|
1437
|
|
|
}
|
1438
|
|
|
|
1439
|
|
|
/**
|
1440
|
|
|
* Get the URL that is set as the CAS service parameter.
|
1441
|
|
|
*/
|
1442
|
|
|
function getServiceURL()
|
1443
|
|
|
{
|
1444
|
|
|
global $PHPCAS_CLIENT;
|
1445
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
1446
|
|
|
phpCAS:: error('this method should only be called after ' . __CLASS__ . '::proxy()');
|
1447
|
|
|
}
|
1448
|
|
|
return ($PHPCAS_CLIENT->getURL());
|
1449
|
|
|
}
|
1450
|
|
|
|
1451
|
|
|
/**
|
1452
|
|
|
* Retrieve a Proxy Ticket from the CAS server.
|
1453
|
|
|
*/
|
1454
|
|
|
function retrievePT($target_service, & $err_code, & $err_msg)
|
1455
|
|
|
{
|
1456
|
|
|
global $PHPCAS_CLIENT;
|
1457
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
1458
|
|
|
phpCAS:: error('this method should only be called after ' . __CLASS__ . '::proxy()');
|
1459
|
|
|
}
|
1460
|
|
|
if (gettype($target_service) != 'string') {
|
1461
|
|
|
phpCAS:: error('type mismatched for parameter $target_service(should be `string\')');
|
1462
|
|
|
}
|
1463
|
|
|
return ($PHPCAS_CLIENT->retrievePT($target_service, $err_code, $err_msg));
|
1464
|
|
|
}
|
1465
|
|
|
|
1466
|
|
|
/**
|
1467
|
|
|
* Set the certificate of the CAS server.
|
1468
|
|
|
*
|
1469
|
|
|
* @param $cert the PEM certificate
|
1470
|
|
|
*/
|
1471
|
|
View Code Duplication |
function setCasServerCert($cert)
|
1472
|
|
|
{
|
1473
|
|
|
global $PHPCAS_CLIENT;
|
1474
|
|
|
phpCAS:: traceBegin();
|
1475
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
1476
|
|
|
phpCAS:: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
|
1477
|
|
|
}
|
1478
|
|
|
if (gettype($cert) != 'string') {
|
1479
|
|
|
phpCAS:: error('type mismatched for parameter $cert (should be `string\')');
|
1480
|
|
|
}
|
1481
|
|
|
$PHPCAS_CLIENT->setCasServerCert($cert);
|
1482
|
|
|
phpCAS:: traceEnd();
|
1483
|
|
|
}
|
1484
|
|
|
|
1485
|
|
|
/**
|
1486
|
|
|
* Set the certificate of the CAS server CA.
|
1487
|
|
|
*
|
1488
|
|
|
* @param $cert the CA certificate
|
1489
|
|
|
*/
|
1490
|
|
View Code Duplication |
function setCasServerCACert($cert)
|
1491
|
|
|
{
|
1492
|
|
|
global $PHPCAS_CLIENT;
|
1493
|
|
|
phpCAS:: traceBegin();
|
1494
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
1495
|
|
|
phpCAS:: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
|
1496
|
|
|
}
|
1497
|
|
|
if (gettype($cert) != 'string') {
|
1498
|
|
|
phpCAS:: error('type mismatched for parameter $cert (should be `string\')');
|
1499
|
|
|
}
|
1500
|
|
|
$PHPCAS_CLIENT->setCasServerCACert($cert);
|
1501
|
|
|
phpCAS:: traceEnd();
|
1502
|
|
|
}
|
1503
|
|
|
|
1504
|
|
|
/**
|
1505
|
|
|
* Set no SSL validation for the CAS server.
|
1506
|
|
|
*/
|
1507
|
|
View Code Duplication |
function setNoCasServerValidation()
|
1508
|
|
|
{
|
1509
|
|
|
global $PHPCAS_CLIENT;
|
1510
|
|
|
phpCAS:: traceBegin();
|
1511
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
1512
|
|
|
phpCAS:: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
|
1513
|
|
|
}
|
1514
|
|
|
$PHPCAS_CLIENT->setNoCasServerValidation();
|
1515
|
|
|
phpCAS:: traceEnd();
|
1516
|
|
|
}
|
1517
|
|
|
|
1518
|
|
|
/** @} */
|
1519
|
|
|
|
1520
|
|
|
/**
|
1521
|
|
|
* Change CURL options.
|
1522
|
|
|
* CURL is used to connect through HTTPS to CAS server
|
1523
|
|
|
* @param $key the option key
|
1524
|
|
|
* @param $value the value to set
|
1525
|
|
|
*/
|
1526
|
|
View Code Duplication |
function setExtraCurlOption($key, $value)
|
1527
|
|
|
{
|
1528
|
|
|
global $PHPCAS_CLIENT;
|
1529
|
|
|
phpCAS:: traceBegin();
|
1530
|
|
|
if (!is_object($PHPCAS_CLIENT)) {
|
1531
|
|
|
phpCAS:: error('this method should only be called after ' . __CLASS__ . '::client() or' . __CLASS__ . '::proxy()');
|
1532
|
|
|
}
|
1533
|
|
|
$PHPCAS_CLIENT->setExtraCurlOption($key, $value);
|
1534
|
|
|
phpCAS:: traceEnd();
|
1535
|
|
|
}
|
1536
|
|
|
|
1537
|
|
|
}
|
1538
|
|
|
|
1539
|
|
|
// ########################################################################
|
1540
|
|
|
// DOCUMENTATION
|
1541
|
|
|
// ########################################################################
|
1542
|
|
|
|
1543
|
|
|
// ########################################################################
|
1544
|
|
|
// MAIN PAGE
|
1545
|
|
|
|
1546
|
|
|
/**
|
1547
|
|
|
* @mainpage
|
1548
|
|
|
*
|
1549
|
|
|
* The following pages only show the source documentation.
|
1550
|
|
|
*
|
1551
|
|
|
*/
|
1552
|
|
|
|
1553
|
|
|
// ########################################################################
|
1554
|
|
|
// MODULES DEFINITION
|
1555
|
|
|
|
1556
|
|
|
/** @defgroup public User interface */
|
1557
|
|
|
|
1558
|
|
|
/** @defgroup publicInit Initialization
|
1559
|
|
|
* @ingroup public
|
1560
|
|
|
*/
|
1561
|
|
|
|
1562
|
|
|
/** @defgroup publicAuth Authentication
|
1563
|
|
|
* @ingroup public
|
1564
|
|
|
*/
|
1565
|
|
|
|
1566
|
|
|
/** @defgroup publicServices Access to external services
|
1567
|
|
|
* @ingroup public
|
1568
|
|
|
*/
|
1569
|
|
|
|
1570
|
|
|
/** @defgroup publicConfig Configuration
|
1571
|
|
|
* @ingroup public
|
1572
|
|
|
*/
|
1573
|
|
|
|
1574
|
|
|
/** @defgroup publicLang Internationalization
|
1575
|
|
|
* @ingroup publicConfig
|
1576
|
|
|
*/
|
1577
|
|
|
|
1578
|
|
|
/** @defgroup publicOutput HTML output
|
1579
|
|
|
* @ingroup publicConfig
|
1580
|
|
|
*/
|
1581
|
|
|
|
1582
|
|
|
/** @defgroup publicPGTStorage PGT storage
|
1583
|
|
|
* @ingroup publicConfig
|
1584
|
|
|
*/
|
1585
|
|
|
|
1586
|
|
|
/** @defgroup publicDebug Debugging
|
1587
|
|
|
* @ingroup public
|
1588
|
|
|
*/
|
1589
|
|
|
|
1590
|
|
|
/** @defgroup internal Implementation */
|
1591
|
|
|
|
1592
|
|
|
/** @defgroup internalAuthentication Authentication
|
1593
|
|
|
* @ingroup internal
|
1594
|
|
|
*/
|
1595
|
|
|
|
1596
|
|
|
/** @defgroup internalBasic CAS Basic client features (CAS 1.0, Service Tickets)
|
1597
|
|
|
* @ingroup internal
|
1598
|
|
|
*/
|
1599
|
|
|
|
1600
|
|
|
/** @defgroup internalProxy CAS Proxy features (CAS 2.0, Proxy Granting Tickets)
|
1601
|
|
|
* @ingroup internal
|
1602
|
|
|
*/
|
1603
|
|
|
|
1604
|
|
|
/** @defgroup internalPGTStorage PGT storage
|
1605
|
|
|
* @ingroup internalProxy
|
1606
|
|
|
*/
|
1607
|
|
|
|
1608
|
|
|
/** @defgroup internalPGTStorageDB PGT storage in a database
|
1609
|
|
|
* @ingroup internalPGTStorage
|
1610
|
|
|
*/
|
1611
|
|
|
|
1612
|
|
|
/** @defgroup internalPGTStorageFile PGT storage on the filesystem
|
1613
|
|
|
* @ingroup internalPGTStorage
|
1614
|
|
|
*/
|
1615
|
|
|
|
1616
|
|
|
/** @defgroup internalCallback Callback from the CAS server
|
1617
|
|
|
* @ingroup internalProxy
|
1618
|
|
|
*/
|
1619
|
|
|
|
1620
|
|
|
/** @defgroup internalProxied CAS proxied client features (CAS 2.0, Proxy Tickets)
|
1621
|
|
|
* @ingroup internal
|
1622
|
|
|
*/
|
1623
|
|
|
|
1624
|
|
|
/** @defgroup internalConfig Configuration
|
1625
|
|
|
* @ingroup internal
|
1626
|
|
|
*/
|
1627
|
|
|
|
1628
|
|
|
/** @defgroup internalOutput HTML output
|
1629
|
|
|
* @ingroup internalConfig
|
1630
|
|
|
*/
|
1631
|
|
|
|
1632
|
|
|
/** @defgroup internalLang Internationalization
|
1633
|
|
|
* @ingroup internalConfig
|
1634
|
|
|
*
|
1635
|
|
|
* To add a new language:
|
1636
|
|
|
* - 1. define a new constant PHPCAS_LANG_XXXXXX in CAS/CAS.php
|
1637
|
|
|
* - 2. copy any file from CAS/languages to CAS/languages/XXXXXX.php
|
1638
|
|
|
* - 3. Make the translations
|
1639
|
|
|
*/
|
1640
|
|
|
|
1641
|
|
|
/** @defgroup internalDebug Debugging
|
1642
|
|
|
* @ingroup internal
|
1643
|
|
|
*/
|
1644
|
|
|
|
1645
|
|
|
/** @defgroup internalMisc Miscellaneous
|
1646
|
|
|
* @ingroup internal
|
1647
|
|
|
*/
|
1648
|
|
|
|
1649
|
|
|
// ########################################################################
|
1650
|
|
|
// EXAMPLES
|
1651
|
|
|
|
1652
|
|
|
/**
|
1653
|
|
|
* @example example_simple.php
|
1654
|
|
|
*/
|
1655
|
|
|
/**
|
1656
|
|
|
* @example example_proxy.php
|
1657
|
|
|
*/
|
1658
|
|
|
/**
|
1659
|
|
|
* @example example_proxy2.php
|
1660
|
|
|
*/
|
1661
|
|
|
/**
|
1662
|
|
|
* @example example_lang.php
|
1663
|
|
|
*/
|
1664
|
|
|
/**
|
1665
|
|
|
* @example example_html.php
|
1666
|
|
|
*/
|
1667
|
|
|
/**
|
1668
|
|
|
* @example example_file.php
|
1669
|
|
|
*/
|
1670
|
|
|
/**
|
1671
|
|
|
* @example example_db.php
|
1672
|
|
|
*/
|
1673
|
|
|
/**
|
1674
|
|
|
* @example example_service.php
|
1675
|
|
|
*/
|
1676
|
|
|
/**
|
1677
|
|
|
* @example example_session_proxy.php
|
1678
|
|
|
*/
|
1679
|
|
|
/**
|
1680
|
|
|
* @example example_session_service.php
|
1681
|
|
|
*/
|
1682
|
|
|
/**
|
1683
|
|
|
* @example example_gateway.php
|
1684
|
|
|
*/
|
1685
|
|
|
/**
|
1686
|
|
|
* @example example_custom_urls.php
|
1687
|
|
|
*/
|
1688
|
|
|
|