Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00032 class ShibWAYF
00033 {
00034
00035 var $isSelection = false;
00036 var $isValidSelection = false;
00037 var $selectedIDP = '-';
00038 var $IDPList = false;
00039
00040 function ShibWAYF()
00041 {
00042
00043 if (isset($_POST['home_organization_selection']))
00044 {
00045 $this->isSelection = true;
00046 }
00047 else
00048 {
00049 $this->isSelection = false;
00050 }
00051
00052
00053 $this->IDPList = $this->getIDPList();
00054 if (
00055 isset($_POST['idp_selection'])
00056 && $_POST['idp_selection'] != '-'
00057 && isset($this->IDPList[$_POST['idp_selection']])
00058 )
00059 {
00060 $this->isValidSelection = true;
00061 $this->selectedIDP = $_POST['idp_selection'];
00062 }
00063 else
00064 {
00065 $this->isValidSelection = false;
00066 }
00067 }
00068
00069
00070 function isSelection()
00071 {
00072
00073 return $this->isSelection;
00074 }
00075
00076
00077 function isValidSelection()
00078 {
00079
00080 return $this->isValidSelection;
00081
00082 }
00083
00084
00085 function generateSelection()
00086 {
00087 global $ilSetting;
00088
00089
00090
00091 $selectElement = '';
00092
00093 if (!$this->IDPList)
00094 {
00095 $idp_list = $this->getIDPList();
00096 }
00097 else
00098 {
00099 $idp_list = $this->IDPList;
00100 }
00101
00102 $idp_cookie = $this->generateCookieArray($_COOKIE['_saml_idp']);
00103
00104 $lng = new ilLanguage($_GET["lang"]);
00105
00106 if (count($idp_cookie) > 0 && isset($idp_list[end($idp_cookie)]))
00107 {
00108 $selectedIDP = end($idp_cookie);
00109 $selectElement = '
00110 <select name="idp_selection">
00111 <option value="-">'.$lng->txt("shib_member_of").'</option>';
00112 }
00113 else
00114 {
00115 $selectElement = '
00116 <select name="idp_selection">
00117 <option value="-" selected="selected">'.$lng->txt("shib_member_of").'</option>';
00118 }
00119
00120 foreach ($idp_list as $idp_id => $idp_data){
00121
00122 if ($idp_id == $selectedIDP)
00123 {
00124 $selectElement .= '<option value="'.$idp_id.'" selected="selected">'.$idp_data[0].'</option>';
00125 }
00126 else
00127 {
00128 $selectElement .= '<option value="'.$idp_id.'">'.$idp_data[0].'</option>';
00129 }
00130 }
00131
00132 $selectElement .= '
00133 </select>';
00134
00135 return $selectElement;
00136 }
00137
00138
00139
00140 function redirect()
00141 {
00142 if (!$this->IDPList)
00143 {
00144 $idp_list = $this->getIDPList();
00145 }
00146 else
00147 {
00148 $idp_list = $this->IDPList;
00149 }
00150
00151
00152 $target = trim(ILIAS_HTTP_PATH, '/').'/shib_login.php';
00153
00154 $idp_data = $idp_list[$this->selectedIDP];
00155 if (isset($idp_data[1]))
00156 {
00157 ilUtil::redirect($idp_data[1].'?providerId='.urlencode($this->selectedIDP).'&target='.urlencode($target));
00158 }
00159 else
00160 {
00161 ilUtil::redirect('/Shibboleth.sso?providerId='.urlencode($this->selectedIDP).'&target='.urlencode($target));
00162 }
00163
00164 }
00165
00166
00167
00168 function setSAMLCookie()
00169 {
00170 if (isset($_COOKIE['_saml_idp']))
00171 {
00172 $IDPArray = $this->generateCookieArray($_COOKIE['_saml_idp']);
00173 }
00174 else
00175 {
00176 $IDPArray = array();
00177 }
00178 $IDPArray = $this->appendCookieValue($this->selectedIDP, $IDPArray);
00179 setcookie ('_saml_idp', $this->generateCookieValue($IDPArray), time() + (100*24*3600), '/');
00180 }
00181
00182
00183 function showNotice()
00184 {
00185 $lng = new ilLanguage($_GET["lang"]);
00186
00187 if (!$this->isSelection() or $this->isValidSelection())
00188 {
00189 return '';
00190 }
00191 else
00192 {
00193 return $lng->txt("shib_invalid_home_organization");
00194 }
00195 }
00196
00197
00198 function getIDPList()
00199 {
00200 global $ilSetting;
00201
00202 $idp_list = array();
00203
00204 $idp_raw_list = split("\n", $ilSetting->get("shib_idp_list"));
00205
00206 foreach ($idp_raw_list as $idp_line){
00207 $idp_data = split(',', $idp_line);
00208 if (isset($idp_data[2]))
00209 {
00210 $idp_list[trim($idp_data[0])] = array(trim($idp_data[1]),trim($idp_data[2]));
00211 }
00212 elseif(isset($idp_data[1]))
00213 {
00214 $idp_list[trim($idp_data[0])] = array(trim($idp_data[1]));
00215 }
00216 }
00217
00218 return $idp_list;
00219 print_r($idp_list);exit;
00220 }
00221
00222
00223 function generateCookieArray($value)
00224 {
00225
00226
00227 $CookieArray = split(' ', $value);
00228 $CookieArray = array_map('base64_decode', $CookieArray);
00229
00230 return $CookieArray;
00231 }
00232
00233
00234 function generateCookieValue($CookieArray)
00235 {
00236
00237
00238 $CookieArray = array_map('base64_encode', $CookieArray);
00239 $value = implode(' ', $CookieArray);
00240 return $value;
00241 }
00242
00243
00244 function appendCookieValue($value, $CookieArray)
00245 {
00246
00247 array_push($CookieArray, $value);
00248 $CookieArray = array_reverse($CookieArray);
00249 $CookieArray = array_unique($CookieArray);
00250 $CookieArray = array_reverse($CookieArray);
00251
00252 return $CookieArray;
00253 }
00254
00255 }
00256 ?>