22
33namespace SimpleSAML \Module \perun ;
44
5+ use SimpleSAML \Module \discopower \PowerIdPDisco ;
56use SimpleSAML \Utils \HTTP ;
67use SimpleSAML \Error \Exception ;
78use SimpleSAML \Auth \State ;
2021 * @author Ondrej Velisek <[email protected] > 2122 * @author Pavel Vyskocil <[email protected] > 2223 */
23- class Disco extends \ SimpleSAML \ Module \ discopower \ PowerIdPDisco
24+ class Disco extends PowerIdPDisco
2425{
2526 const CONFIG_FILE_NAME = 'module_perun.php ' ;
2627 const PROPNAME_DISABLE_WHITELISTING = 'disco.disableWhitelisting ' ;
@@ -66,9 +67,6 @@ public function __construct(array $metadataSets, $instance)
6667 $ this ->originalsp = $ state ['SPMetadata ' ];
6768 }
6869
69- $ this ->service = IdpListsService::getInstance ();
70- $ this ->whitelist = $ this ->service ->getWhitelistEntityIds ();
71- $ this ->greylist = $ this ->service ->getGreylistEntityIds ();
7270 }
7371
7472 /**
@@ -135,11 +133,7 @@ protected function filterList($list)
135133 || !$ this ->originalsp ['disco.doNotFilterIdps ' ]
136134 ) {
137135 $ list = parent ::filterList ($ list );
138- $ list = $ this ->scoping ($ list );
139- if (!$ disableWhitelisting ) {
140- $ list = $ this ->whitelisting ($ list );
141- }
142- $ list = $ this ->greylisting ($ list );
136+ self ::doFilter ($ list , $ disableWhitelisting , $ this ->scopedIDPList );
143137 $ list = $ this ->greylistingPerSP ($ list , $ this ->originalsp );
144138 }
145139
@@ -150,6 +144,34 @@ protected function filterList($list)
150144 return $ list ;
151145 }
152146
147+ /**
148+ * Filter out IdP which:
149+ * 1. are not in SAML2 Scoping attribute list (SAML2 feature)
150+ * 2. are not whitelisted (if whitelisting is allowed)
151+ * 3. are greylisted
152+ *
153+ * @param array $list A map of entities to filter.
154+ * @param bool $disableWhitelisting
155+ * @param array $scopedIdPList
156+ *
157+ * @return array The list in $list after filtering entities.
158+ * @throws Exception In case
159+ */
160+ public static function doFilter ($ list , $ disableWhitelisting = false , $ scopedIdPList = [])
161+ {
162+ $ service = IdpListsService::getInstance ();
163+ $ whitelist = $ service ->getWhitelistEntityIds ();
164+ $ greylist = $ service ->getGreylistEntityIds ();
165+
166+ $ list = self ::scoping ($ list , $ scopedIdPList );
167+ if (!$ disableWhitelisting ) {
168+ $ list = self ::whitelisting ($ list , $ whitelist );
169+ }
170+ $ list = self ::greylisting ($ list , $ greylist );
171+
172+ return $ list ;
173+ }
174+
153175 /**
154176 * Filter a list of entities for addInstitution app according to if entityID is whitelisted or not
155177 *
@@ -159,8 +181,10 @@ protected function filterList($list)
159181 */
160182 protected function filterAddInstitutionList ($ list )
161183 {
184+ $ service = IdpListsService::getInstance ();
185+ $ whitelist = $ service ->getWhitelistEntityIds ();
162186 foreach ($ list as $ entityId => $ idp ) {
163- if (in_array ($ entityId , $ this -> whitelist )) {
187+ if (in_array ($ entityId , $ whitelist )) {
164188 unset($ list [$ entityId ]);
165189 }
166190 }
@@ -174,30 +198,41 @@ protected function filterAddInstitutionList($list)
174198
175199 /**
176200 * Filter out IdP which are not in SAML2 Scoping attribute list (SAML2 feature)
177- * @param $list
178- * @return array of idps
201+ *
202+ * @param array $list A map of entities to filter.
203+ * @param array $scopedIDPList
204+ *
205+ * @return array The list in $list after filtering entities.
179206 */
180- protected function scoping ($ list )
207+ protected static function scoping ($ list, $ scopedIDPList )
181208 {
182- if (!empty ($ this -> scopedIDPList )) {
209+ if (!empty ($ scopedIDPList )) {
183210 foreach ($ list as $ entityId => $ idp ) {
184- if (!in_array ($ entityId , $ this -> scopedIDPList )) {
211+ if (!in_array ($ entityId , $ scopedIDPList )) {
185212 unset($ list [$ entityId ]);
186213 }
187214 }
188215 }
189- //SimpleSAML\Logger::debug(
190- //'perun.Disco.filterList: Idps after SAML2 Scoping: ' . var_export(array_keys($list), true)
191- //);
192216 return $ list ;
193217 }
194218
195- protected function whitelisting ($ list )
219+ /**
220+ * Filter out IdP which:
221+ * 1. are not whitelisted
222+ * 2. are not supported research and scholarship
223+ * 3. are not supported code of conduct
224+ *
225+ * @param array $list A map of entities to filter.
226+ * @param array $whitelist The list of whitelisted IdPs
227+ *
228+ * @return array The list in $list after filtering entities.
229+ */
230+ protected static function whitelisting ($ list , $ whitelist )
196231 {
197232 foreach ($ list as $ entityId => $ idp ) {
198233 $ unset = true ;
199234
200- if (in_array ($ entityId , $ this -> whitelist )) {
235+ if (in_array ($ entityId , $ whitelist )) {
201236 $ unset = false ;
202237 }
203238 if (isset ($ idp ['EntityAttributes ' ]['http://macedir.org/entity-category-support ' ])) {
@@ -223,23 +258,25 @@ protected function whitelisting($list)
223258 unset($ list [$ entityId ]);
224259 }
225260 }
226- //SimpleSAML\Logger::debug(
227- //'perun.Disco.filterList: Idps after Whitelisting: ' . var_export(array_keys($list), true)
228- //);
229261 return $ list ;
230262 }
231263
232- protected function greylisting ($ list )
264+ /**
265+ * Filter out IdP which are greylisted
266+ *
267+ * @param array $list A map of entities to filter.
268+ * @param array $greylist The list of greylisted IdPs
269+ *
270+ * @return array The list in $list after filtering entities.
271+ */
272+ protected static function greylisting ($ list , $ greylist )
233273 {
234274 foreach ($ list as $ entityId => $ idp ) {
235- if (in_array ($ entityId , $ this -> greylist )) {
275+ if (in_array ($ entityId , $ greylist )) {
236276 unset($ list [$ entityId ]);
237277 }
238278 }
239279
240- //SimpleSAML\Logger::debug(
241- //'perun.Disco.filterList: Idps after Greylisting: ' . var_export(array_keys($list), true)
242- //);
243280 return $ list ;
244281 }
245282
@@ -253,9 +290,6 @@ protected function greylistingPerSP($list, $sp)
253290 }
254291 }
255292
256- //SimpleSAML\Logger::debug(
257- //'perun.Disco.filterList: Idps after Greylisting per SP: ' . var_export(array_keys($list), true)
258- //);
259293 return $ list ;
260294 }
261295
0 commit comments