1818 * It relays on RetainIdPEntityID filter. Config it properly before this filter. (in SP context)
1919 *
2020 * @author Ondrej Velisek <[email protected] > 21+ * @author Michal Prochazka <[email protected] > 2122 */
2223class sspmod_perun_Auth_Process_PerunIdentity extends SimpleSAML_Auth_ProcessingFilter
2324{
24- const UID_ATTR = 'uidAttr ' ;
25+ const UIDS_ATTR = 'uidsAttr ' ;
2526 const VO_SHORTNAME = 'voShortName ' ;
2627 const REGISTER_URL = 'registerUrl ' ;
2728 const CALLBACK_PARAM_NAME = 'callbackParamName ' ;
2829 const INTERFACE_PROPNAME = 'interface ' ;
2930 const SOURCE_IDP_ENTITY_ID_ATTR = 'sourceIdPEntityIDAttr ' ;
3031 const FORCE_REGISTRATION_TO_GROUPS = 'forceRegistrationToGroups ' ;
3132
32- private $ uidAttr ;
33+ private $ uidsAttr ;
3334 private $ registerUrl ;
3435 private $ voShortName ;
3536 private $ callbackParamName ;
@@ -47,8 +48,8 @@ public function __construct($config, $reserved)
4748 {
4849 parent ::__construct ($ config , $ reserved );
4950
50- if (!isset ($ config [self ::UID_ATTR ])) {
51- throw new SimpleSAML_Error_Exception ("perun:PerunIdentity: missing mandatory config option ' " .self ::UID_ATTR ."'. " );
51+ if (!isset ($ config [self ::UIDS_ATTR ])) {
52+ throw new SimpleSAML_Error_Exception ("perun:PerunIdentity: missing mandatory config option ' " .self ::UIDS_ATTR ."'. " );
5253 }
5354 if (!isset ($ config [self ::REGISTER_URL ])) {
5455 throw new SimpleSAML_Error_Exception ("perun:PerunIdentity: missing mandatory config option ' " .self ::REGISTER_URL ."'. " );
@@ -69,7 +70,7 @@ public function __construct($config, $reserved)
6970 $ config [self ::FORCE_REGISTRATION_TO_GROUPS ] = false ;
7071 }
7172
72- $ this ->uidAttr = ( string ) $ config [self ::UID_ATTR ];
73+ $ this ->uidsAttr = $ config [self ::UIDS_ATTR ];
7374 $ this ->registerUrl = (string ) $ config [self ::REGISTER_URL ];
7475 $ this ->voShortName = (string ) $ config [self ::VO_SHORTNAME ];
7576 $ this ->callbackParamName = (string ) $ config [self ::CALLBACK_PARAM_NAME ];
@@ -84,11 +85,17 @@ public function process(&$request)
8485 {
8586 assert ('is_array($request) ' );
8687
87- if (isset ($ request ['Attributes ' ][$ this ->uidAttr ][0 ])) {
88- $ uid = $ request ['Attributes ' ][$ this ->uidAttr ][0 ];
89- } else {
88+ # Store all user ids in an array
89+ $ uids = array ();
90+
91+ foreach ($ this ->uidsAttr as $ uidAttr ) {
92+ if (isset ($ request ['Attributes ' ][$ uidAttr ][0 ])) {
93+ array_push ($ uids ,$ request ['Attributes ' ][$ uidAttr ][0 ]);
94+ }
95+ }
96+ if (empty ($ uids )) {
9097 throw new SimpleSAML_Error_Exception ("perun:PerunIdentity: " .
91- "missing mandatory attribute " . $ this ->uidAttr . " in request. " );
98+ "missing one of the mandatory attribute " . implode ( ' , ' , $ this ->uidsAttr ) . " in request. " );
9299 }
93100
94101 if (isset ($ request ['Attributes ' ][$ this ->sourceIdPEntityIDAttr ][0 ])) {
@@ -129,10 +136,10 @@ public function process(&$request)
129136
130137 SimpleSAML_Logger::debug ("SP GROUPs - " .var_export ($ spGroups , true ));
131138
132- $ user = $ this ->adapter ->getPerunUser ($ idpEntityId , $ uid );
139+ $ user = $ this ->adapter ->getPerunUser ($ idpEntityId , $ uids );
133140
134141 if ($ user === null ) {
135- SimpleSAML_Logger::info ('Perun user with identity: ' .$ uid .' has NOT been found. He is being redirected to register. ' );
142+ SimpleSAML_Logger::info ('Perun user with identity/ies : ' . implode ( ' , ' , $ uids ) .' has NOT been found. He is being redirected to register. ' );
136143 $ this ->register ($ request , $ this ->registerUrl , $ this ->callbackParamName , $ vo , $ spGroups , $ this ->interface );
137144 }
138145
@@ -145,11 +152,11 @@ public function process(&$request)
145152 $ groups = $ this ->intersectById ($ spGroups , $ memberGroups );
146153
147154 if (empty ($ groups )) {
148- SimpleSAML_Logger::warning ('Perun user with identity: ' .$ uid .' is not member of any assigned group for resource ( ' . $ spEntityId . ') ' );
155+ SimpleSAML_Logger::warning ('Perun user with identity/ies : ' . implode ( ' , ' , $ uids ) .' is not member of any assigned group for resource ( ' . $ spEntityId . ') ' );
149156 $ this ->unauthorized ($ request );
150157 }
151158
152- SimpleSAML_Logger::info ('Perun user with identity: ' .$ uid .' has been found and SP has sufficient rights to get info about him. ' .
159+ SimpleSAML_Logger::info ('Perun user with identity/ies : ' . implode ( ' , ' , $ uids ) .' has been found and SP has sufficient rights to get info about him. ' .
153160 'User ' .$ user ->getName ().' with id: ' .$ user ->getId ().' is being set to request ' );
154161
155162 if (!isset ($ request ['perun ' ])) {
@@ -176,7 +183,7 @@ public function process(&$request)
176183 protected function register ($ request , $ registerUrl , $ callbackParamName , $ vo , $ groups , $ interface ) {
177184
178185 $ request ['config ' ] = array (
179- self ::UID_ATTR => $ this ->uidAttr ,
186+ self ::UIDS_ATTR => $ this ->uidsAttr ,
180187 self ::VO_SHORTNAME => $ this ->voShortName ,
181188 self ::REGISTER_URL => $ this ->registerUrl ,
182189 self ::CALLBACK_PARAM_NAME => $ this ->callbackParamName ,
0 commit comments