ILIAS  release_8 Revision v8.24
ilShibbolethWAYF Class Reference

Class ShibbolethWAYF. More...

+ Collaboration diagram for ilShibbolethWAYF:

Public Member Functions

 __construct ()
 
 isSelection ()
 
 isValidSelection ()
 
 generateSelection ()
 
 redirect ()
 @description Redirects user to the local Shibboleth session initatiotor with already set GET arguments for the right IdP and return location. More...
 
 setSAMLCookie ()
 @description Sets the standard SAML domain cookie that is also used to preselect the right entry on the local wayf More...
 
 showNotice ()
 @description Show notice in case no IdP was selected More...
 
 getIdplist ()
 @description Generate array of IdPs from ILIAS Shibboleth settings More...
 
 generateCookieArray (?string $value)
 @description Generates an array of IDPs using the cookie value More...
 
 generateCookieValue (array $arr_cookie)
 @description Generate the value that is stored in the cookie using the list of IDPs More...
 
 appendCookieValue (string $value, array $arr_cookie)
 @description Append a value to the array of IDPs More...
 

Data Fields

const COOKIE_NAME_SAML_IDP = '_saml_idp'
 
bool $is_selection = false
 
bool $is_valid_selection = false
 
string $selected_idp = '-'
 
array $idp_list = []
 

Protected Attributes

WrapperFactory $wrapper
 
ilLanguage $lng
 
ilSetting $settings
 
ILIAS Refinery Factory $refinery
 

Detailed Description

Class ShibbolethWAYF.

This class handles the Home Organization selection (also called Where Are You From service) process for Shibboleth users.

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch

Definition at line 31 of file class.ilShibbolethWAYF.php.

Constructor & Destructor Documentation

◆ __construct()

ilShibbolethWAYF::__construct ( )

Definition at line 43 of file class.ilShibbolethWAYF.php.

44 {
45 global $DIC;
46
47 // Was the WAYF form submitted?
48 $this->wrapper = $DIC->http()->wrapper();
49 $this->refinery = $DIC->refinery();
50 $this->settings = $DIC->settings();
51 $this->is_selection = $this->wrapper->post()->has('home_organization_selection');
52 $this->lng = $DIC->isDependencyAvailable('language')
53 ? $DIC->language()
54 : new ilLanguage(
55 $this->wrapper->query()->has('lang')
56 ? $this->wrapper->query()->retrieve('lang', $DIC->refinery()->to()->string())
57 : null
58 );
59
60 // Was selected IdP a valid
61 $this->idp_list = $this->getIdplist();
62 $idp_selection = $this->wrapper->post()->has('idp_selection')
63 ? $this->wrapper->post()->retrieve('idp_selection', $DIC->refinery()->to()->string())
64 : null;
65 if ($idp_selection !== null
66 && $idp_selection !== '-'
67 && isset($this->idp_list[$idp_selection])
68 ) {
69 $this->is_valid_selection = true;
70 $this->selected_idp = $idp_selection;
71 } else {
72 $this->is_valid_selection = false;
73 }
74 }
language handling
getIdplist()
@description Generate array of IdPs from ILIAS Shibboleth settings
global $DIC
Definition: feed.php:28

References $DIC, getIdplist(), ILIAS\Repository\lng(), ILIAS\Repository\refinery(), and ILIAS\Repository\settings().

+ Here is the call graph for this function:

Member Function Documentation

◆ appendCookieValue()

ilShibbolethWAYF::appendCookieValue ( string  $value,
array  $arr_cookie 
)

@description Append a value to the array of IDPs

Returns
mixed[]

Definition at line 211 of file class.ilShibbolethWAYF.php.

211 : array
212 {
213 $arr_cookie[] = $value;
214 $arr_cookie = array_reverse($arr_cookie);
215 $arr_cookie = array_unique($arr_cookie);
216 return array_reverse($arr_cookie);
217 }

Referenced by setSAMLCookie().

+ Here is the caller graph for this function:

◆ generateCookieArray()

ilShibbolethWAYF::generateCookieArray ( ?string  $value)

@description Generates an array of IDPs using the cookie value

Returns
bool[]|string[]

Definition at line 189 of file class.ilShibbolethWAYF.php.

189 : array
190 {
191 if (null === $value) {
192 return [];
193 }
194 $arr_cookie = explode(' ', $value);
195 return array_map('base64_decode', $arr_cookie);
196 }

Referenced by generateSelection(), and setSAMLCookie().

+ Here is the caller graph for this function:

◆ generateCookieValue()

ilShibbolethWAYF::generateCookieValue ( array  $arr_cookie)

@description Generate the value that is stored in the cookie using the list of IDPs

Definition at line 201 of file class.ilShibbolethWAYF.php.

201 : string
202 {
203 $arr_cookie = array_map('base64_encode', $arr_cookie);
204 return implode(' ', $arr_cookie);
205 }

Referenced by setSAMLCookie().

+ Here is the caller graph for this function:

◆ generateSelection()

ilShibbolethWAYF::generateSelection ( )

Definition at line 86 of file class.ilShibbolethWAYF.php.

86 : string
87 {
88 $_saml_idp = $this->wrapper->cookie()->has(self::COOKIE_NAME_SAML_IDP)
89 ? $this->wrapper->cookie()->retrieve(
90 self::COOKIE_NAME_SAML_IDP,
91 $this->refinery->kindlyTo()->string()
92 )
93 : null;
94 $idp_cookie = $this->generateCookieArray($_saml_idp);
95
96 $selectedIDP = null;
97 if ($idp_cookie !== [] && isset($this->idp_list[end($idp_cookie)])) {
98 $selectedIDP = end($idp_cookie);
99 $selectElement = '
100 <select name="idp_selection">
101 <option value="-">' . $this->lng->txt("shib_member_of") . '</option>';
102 } else {
103 $selectElement = '
104 <select name="idp_selection">
105 <option value="-" selected="selected">' . $this->lng->txt("shib_member_of") . '</option>';
106 }
107
108 foreach ($this->idp_list as $idp_id => $idp_data) {
109 if ($idp_id == $selectedIDP) {
110 $selectElement .= '<option value="' . $idp_id . '" selected="selected">' . $idp_data[0] . '</option>';
111 } else {
112 $selectElement .= '<option value="' . $idp_id . '">' . $idp_data[0] . '</option>';
113 }
114 }
115
116 return $selectElement . '
117 </select>';
118 }
generateCookieArray(?string $value)
@description Generates an array of IDPs using the cookie value

References generateCookieArray(), ILIAS\Repository\lng(), and ILIAS\Repository\refinery().

+ Here is the call graph for this function:

◆ getIdplist()

ilShibbolethWAYF::getIdplist ( )

@description Generate array of IdPs from ILIAS Shibboleth settings

Returns
array<string, string[]>

Definition at line 169 of file class.ilShibbolethWAYF.php.

169 : array
170 {
171 $idp_list = [];
172 $idp_raw_list = explode("\n", $this->settings->get("shib_idp_list"));
173 foreach ($idp_raw_list as $idp_line) {
174 $idp_data = explode(',', $idp_line);
175 if (isset($idp_data[2])) {
176 $idp_list[trim($idp_data[0])] = array(trim($idp_data[1]), trim($idp_data[2]));
177 } elseif (isset($idp_data[1])) {
178 $idp_list[trim($idp_data[0])] = array(trim($idp_data[1]));
179 }
180 }
181
182 return $idp_list;
183 }

References $idp_list, and ILIAS\Repository\settings().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isSelection()

ilShibbolethWAYF::isSelection ( )

Definition at line 76 of file class.ilShibbolethWAYF.php.

76 : bool
77 {
79 }

References $is_selection.

Referenced by showNotice().

+ Here is the caller graph for this function:

◆ isValidSelection()

ilShibbolethWAYF::isValidSelection ( )

Definition at line 81 of file class.ilShibbolethWAYF.php.

81 : bool
82 {
84 }

References $is_valid_selection.

Referenced by showNotice().

+ Here is the caller graph for this function:

◆ redirect()

ilShibbolethWAYF::redirect ( )

@description Redirects user to the local Shibboleth session initatiotor with already set GET arguments for the right IdP and return location.

Definition at line 123 of file class.ilShibbolethWAYF.php.

123 : void
124 {
125 // Where to return after the authentication process
126 $target = $this->wrapper->post()->has('il_target')
127 ? $this->wrapper->post()->retrieve('il_target', $this->refinery->kindlyTo()->string())
128 : '';
129 $target = trim(ILIAS_HTTP_PATH, '/') . '/shib_login.php?target=' . $target;
130 $idp_data = $this->idp_list[$this->selected_idp];
131 if (isset($idp_data[1])) {
132 ilUtil::redirect($idp_data[1] . '?providerId=' . urlencode($this->selected_idp) . '&target='
133 . urlencode($target));
134 } else {
135 // TODO: This has to be changed to /Shibboleth.sso/DS?entityId= for
136 // Shibbolet 2.x sometime...
137 ilUtil::redirect('/Shibboleth.sso?providerId=' . urlencode($this->selected_idp) . '&target='
138 . urlencode($target));
139 }
140 }
static redirect(string $a_script)

References $selected_idp, ilUtil\redirect(), and ILIAS\Repository\refinery().

+ Here is the call graph for this function:

◆ setSAMLCookie()

ilShibbolethWAYF::setSAMLCookie ( )

@description Sets the standard SAML domain cookie that is also used to preselect the right entry on the local wayf

Definition at line 145 of file class.ilShibbolethWAYF.php.

145 : void
146 {
147 $_saml_idp = $this->wrapper->cookie()->retrieve(self::COOKIE_NAME_SAML_IDP, $this->refinery->kindlyTo()->string());
148 $arr_idps = $_saml_idp ? $this->generateCookieArray($_saml_idp) : [];
149 $arr_idps = $this->appendCookieValue($this->selected_idp, $arr_idps);
150 setcookie(self::COOKIE_NAME_SAML_IDP, $this->generateCookieValue($arr_idps), time() + (100 * 24 * 3600), '/');
151 }
generateCookieValue(array $arr_cookie)
@description Generate the value that is stored in the cookie using the list of IDPs
appendCookieValue(string $value, array $arr_cookie)
@description Append a value to the array of IDPs

References appendCookieValue(), generateCookieArray(), generateCookieValue(), and ILIAS\Repository\refinery().

+ Here is the call graph for this function:

◆ showNotice()

ilShibbolethWAYF::showNotice ( )

@description Show notice in case no IdP was selected

Definition at line 156 of file class.ilShibbolethWAYF.php.

156 : string
157 {
158 if (!$this->isSelection() || $this->isValidSelection()) {
159 return '';
160 }
161
162 return $this->lng->txt("shib_invalid_home_organization");
163 }

References isSelection(), isValidSelection(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

Field Documentation

◆ $idp_list

array ilShibbolethWAYF::$idp_list = []

Definition at line 37 of file class.ilShibbolethWAYF.php.

Referenced by getIdplist().

◆ $is_selection

bool ilShibbolethWAYF::$is_selection = false

Definition at line 34 of file class.ilShibbolethWAYF.php.

Referenced by isSelection().

◆ $is_valid_selection

bool ilShibbolethWAYF::$is_valid_selection = false

Definition at line 35 of file class.ilShibbolethWAYF.php.

Referenced by isValidSelection().

◆ $lng

ilLanguage ilShibbolethWAYF::$lng
protected

Definition at line 39 of file class.ilShibbolethWAYF.php.

◆ $refinery

ILIAS Refinery Factory ilShibbolethWAYF::$refinery
protected

Definition at line 41 of file class.ilShibbolethWAYF.php.

◆ $selected_idp

string ilShibbolethWAYF::$selected_idp = '-'

Definition at line 36 of file class.ilShibbolethWAYF.php.

Referenced by redirect().

◆ $settings

ilSetting ilShibbolethWAYF::$settings
protected

Definition at line 40 of file class.ilShibbolethWAYF.php.

◆ $wrapper

WrapperFactory ilShibbolethWAYF::$wrapper
protected

Definition at line 38 of file class.ilShibbolethWAYF.php.

◆ COOKIE_NAME_SAML_IDP

const ilShibbolethWAYF::COOKIE_NAME_SAML_IDP = '_saml_idp'

Definition at line 33 of file class.ilShibbolethWAYF.php.


The documentation for this class was generated from the following file: