1+ <?php
2+ /**
3+ * Class sspmod_perun_Auth_Process_IdPAttribute
4+ *
5+ * This class for each line in $attrMAp search the $key in IdP Metadata and save it to $request['Attributes'][$value]
6+ *
7+ * @author Pavel Vyskocil <[email protected] > 8+ */
9+ class sspmod_perun_Auth_Process_IdPAttribute extends SimpleSAML_Auth_ProcessingFilter
10+ {
11+ private $ attrMap ;
12+
13+ public function __construct ($ config , $ reserved )
14+ {
15+ parent ::__construct ($ config , $ reserved );
16+
17+ assert ('is_array($config) ' );
18+
19+ if (!isset ($ config ['attrMap ' ])) {
20+ throw new SimpleSAML_Error_Exception ("perun:IdPAttribute: missing mandatory configuration option 'attrMap'. " );
21+ }
22+
23+ $ this ->attrMap = (array ) $ config ['attrMap ' ];
24+ }
25+ public function process (&$ request )
26+ {
27+ assert ('is_array($request) ' );
28+
29+ $ metadataHandler = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler ();
30+ $ sourceIdpMeta = $ metadataHandler ->getMetaData ( $ request ['saml:sp:IdP ' ], 'saml20-idp-remote ' );
31+
32+ foreach ($ this ->attrMap as $ attributeKey => $ attributeValue ) {
33+ $ attributeNames = preg_split ('/:/ ' , $ attributeKey );
34+ $ key = array_shift ($ attributeNames );
35+
36+ if (!isset ($ sourceIdpMeta [$ key ])) {
37+ continue ;
38+ }
39+ $ value = $ sourceIdpMeta [$ key ];
40+
41+ foreach ($ attributeNames as $ attributeName ) {
42+ if (!isset ($ value [$ attributeName ])){
43+ continue ;
44+ }
45+ $ value = $ value [$ attributeName ];
46+ }
47+
48+ if (!is_array ($ value )) {
49+ $ value = array ($ value );
50+ }
51+
52+ if (!empty ($ value )) {
53+ $ request ['Attributes ' ][$ attributeValue ] = $ value ;
54+ }
55+ }
56+
57+ }
58+ }
0 commit comments