1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Response callbacks for the CAS Server module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Returns a CAS 2.0 service response for a validation success.
|
10 |
|
|
*
|
11 |
|
|
* @param $variables
|
12 |
|
|
* An associative array containing the keys:
|
13 |
|
|
* - 'name': CAS username.
|
14 |
|
|
* - 'attributes': (optional) CAS attributes.
|
15 |
|
|
*/
|
16 |
|
|
function theme_cas_service_validate_success($variables) {
|
17 |
|
|
$cas_name = $variables['name'];
|
18 |
|
|
$output .= "<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>\n";
|
19 |
|
|
$output .= "<cas:authenticationSuccess>\n";
|
20 |
|
|
$output .= "<cas:user>$cas_name</cas:user>\n";
|
21 |
|
|
$output .= theme('cas_service_validate_attributes', $variables);
|
22 |
|
|
$output .= "</cas:authenticationSuccess>\n";
|
23 |
|
|
$output .= "</cas:serviceResponse>\n";
|
24 |
|
|
|
25 |
|
|
return $output;
|
26 |
|
|
}
|
27 |
|
|
|
28 |
|
|
/**
|
29 |
|
|
* Returns CAS attributes as part of a CAS 2.0 service response.
|
30 |
|
|
*
|
31 |
|
|
* @param $variables
|
32 |
|
|
* An asociative array containing the keys 'attributes' and 'style', where
|
33 |
|
|
* the value of 'style' must be one of:
|
34 |
|
|
* - 'jasig' (default)
|
35 |
|
|
* - 'rubycas'
|
36 |
|
|
* - 'name-value'
|
37 |
|
|
*/
|
38 |
|
|
function theme_cas_service_validate_attributes($variables) {
|
39 |
|
|
$attributes = $variables['attributes'];
|
40 |
|
|
$style = $variables['style'];
|
41 |
|
|
|
42 |
|
|
$output = '';
|
43 |
|
|
switch($style) {
|
44 |
|
|
case 'jasig':
|
45 |
|
|
default:
|
46 |
|
|
$output .= "<cas:attributes>\n";
|
47 |
|
|
$output .= "<cas:attraStyle>Jasig</cas:attraStyle>\n";
|
48 |
|
|
foreach ($attributes as $name => $values) {
|
49 |
|
|
foreach ((array) $values as $value) {
|
50 |
|
|
$output .= strtr("<cas:!name>!value</cas:!name>\n", array('!name' => $name, '!value' => $value));
|
51 |
|
|
}
|
52 |
|
|
}
|
53 |
|
|
$output .= "</cas:attributes>\n";
|
54 |
|
|
break;
|
55 |
|
|
case 'rubycas':
|
56 |
|
|
$output .= "<cas:attraStyle>RubyCAS</cas:attraStyle>\n";
|
57 |
|
|
foreach ($attributes as $name => $values) {
|
58 |
|
|
foreach ((array) $values as $value) {
|
59 |
|
|
$output .= strtr("<cas:!name>!value</cas:!name>\n", array('!name' => $name, '!value' => $value));
|
60 |
|
|
}
|
61 |
|
|
}
|
62 |
|
|
break;
|
63 |
|
|
case 'name-value':
|
64 |
|
|
$output .= "<cas:attribute name='attraStyle' value='Name-Value' />\n";
|
65 |
|
|
foreach ($attributes as $name => $values) {
|
66 |
|
|
foreach ((array) $values as $value) {
|
67 |
|
|
$output .= strtr("<cas:attribute name='!name' value='!value' />\n", array('!name' => $name, '!value' => $value));
|
68 |
|
|
}
|
69 |
|
|
}
|
70 |
|
|
break;
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
return $output;
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
/**
|
78 |
|
|
* Returns a CAS 2.0 service response for a validation failure.
|
79 |
|
|
*
|
80 |
|
|
* @param $variables
|
81 |
|
|
* An associative array containing the keys 'ticket' and 'error_code'.
|
82 |
|
|
*/
|
83 |
|
|
function theme_cas_service_validate_failure($variables) {
|
84 |
|
|
$ticket = $variables['ticket'];
|
85 |
|
|
$error_code = $variables['error_code'];
|
86 |
|
|
$output = "<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>\n";
|
87 |
|
|
$output .= "<cas:authenticationFailure code=\"$error_code\">\n";
|
88 |
|
|
$output .= "Ticket $ticket not recognized.\n";
|
89 |
|
|
$output .= "</cas:authenticationFailure>\n";
|
90 |
|
|
$output .= "</cas:serviceResponse>\n";
|
91 |
|
|
|
92 |
|
|
return $output;
|
93 |
|
|
} |