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 |
a2baadd1
|
Assos Assos
|
$output = "<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>\n";
|
19 |
85ad3d82
|
Assos Assos
|
$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 |
4f315dab
|
Assos Assos
|
* An associative array containing the keys 'attributes' and 'style', where
|
33 |
85ad3d82
|
Assos Assos
|
* 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 |
a2baadd1
|
Assos Assos
|
switch ($style) {
|
44 |
85ad3d82
|
Assos Assos
|
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 |
|
|
}
|
94 |
a2baadd1
|
Assos Assos
|
|
95 |
|
|
|
96 |
4f315dab
|
Assos Assos
|
/**
|
97 |
|
|
* Returns a CAS 2.0 service response for a service not on the whitelist.
|
98 |
|
|
*
|
99 |
|
|
* @param $variables
|
100 |
|
|
* An associative array containing the keys 'service' and 'error_code'.
|
101 |
|
|
*/
|
102 |
|
|
function theme_cas_service_validate_whitelist_failure($variables) {
|
103 |
|
|
$service = $variables['service'];
|
104 |
|
|
$error_code = $variables['error_code'];
|
105 |
|
|
$output = "<cas:serviceReponse xmlns:cas='http://www.yale.edu/tp/cas'>\n" .
|
106 |
|
|
"<cas:authenticationFailure code=\"$error_code\">\n" .
|
107 |
|
|
"Service $service not recognized.\n" .
|
108 |
|
|
"</cas:authenticationFailure>\n" .
|
109 |
|
|
"</cas:serviceResponse>\n";
|
110 |
|
|
return $output;
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
|
114 |
a2baadd1
|
Assos Assos
|
/**
|
115 |
|
|
* Generate the Single Sign Out request.
|
116 |
|
|
*
|
117 |
|
|
* @param unknown_type $variables
|
118 |
|
|
* An associative array containing the key, date and logout id request
|
119 |
|
|
*/
|
120 |
|
|
function theme_cas_service_logout_request($variables) {
|
121 |
|
|
$id = $variables['id'];
|
122 |
|
|
$date = $variables['date'];
|
123 |
|
|
$ticket = $variables['ticket'];
|
124 |
|
|
$output = "<samlp:LogoutRequest xmlns:samlp='urn:oasis:names:tc:SAML:2.0:protocol' ID='$id' Version='2.0' IssueInstant='$date'>\n";
|
125 |
|
|
$output .= "<saml:NameID xmlns:saml='urn:oasis:names:tc:SAML:2.0:assertion'>@NOT_USED@</saml:NameID>\n";
|
126 |
|
|
$output .= "<samlp:SessionIndex>$ticket</samlp:SessionIndex>\n";
|
127 |
|
|
$output .= "</samlp:LogoutRequest>\n";
|
128 |
|
|
return $output;
|
129 |
|
|
} |