22
33namespace SimpleSAML \Module \perun \Auth \Process ;
44
5+ use SimpleSAML \Auth \ProcessingFilter ;
56use SimpleSAML \Module \perun \Adapter ;
6- use SimpleSAML \Module \perun \AttributeUtils ;
77use SimpleSAML \Error \Exception ;
88use SimpleSAML \Logger ;
9+ use SimpleSAML \Module \perun \model \User ;
910
1011/**
1112 * Class PerunAttributes
1920 *
2021 * @author Ondrej Velisek <[email protected] > 2122 */
22- class PerunAttributes extends \ SimpleSAML \ Auth \ ProcessingFilter
23+ class PerunAttributes extends ProcessingFilter
2324{
2425 private $ attrMap ;
2526 private $ interface ;
@@ -63,8 +64,6 @@ public function __construct($config, $reserved)
6364
6465 public function process (&$ request )
6566 {
66- assert (is_array ($ request ));
67-
6867 if (isset ($ request ['perun ' ]['user ' ])) {
6968 $ user = $ request ['perun ' ]['user ' ];
7069 } else {
@@ -81,17 +80,42 @@ public function process(&$request)
8180 } elseif ($ this ->mode === self ::MODE_PARTIAL ) {
8281 // Check if attribute has some value
8382 foreach ($ this ->attrMap as $ attrName => $ attrValue ) {
84- if (isset ($ request ['Attributes ' ][$ attrValue ])) {
85- $ attr = $ request ['Attributes ' ][$ attrValue ];
86- if (empty ($ attr )) {
83+ if (!is_array ($ attrValue )) {
84+ $ attrValue = [$ attrValue ];
85+ }
86+ foreach ($ attrValue as $ value ) {
87+ if (empty ($ request ['Attributes ' ][$ value ])) {
8788 array_push ($ attributes , $ attrName );
89+ break ;
8890 }
89- } else {
90- array_push ($ attributes , $ attrName );
9191 }
9292 }
9393 }
9494
95+ if (empty ($ attributes )) {
96+ return ;
97+ }
98+
99+ $ this ->processAttributes ($ user , $ attributes );
100+ }
101+
102+ private function hasStringKeys ($ array ): bool
103+ {
104+ if (!is_array ($ array )) {
105+ return false ;
106+ }
107+ return count (array_filter (array_keys ($ array ), 'is_string ' )) > 0 ;
108+ }
109+
110+ /**
111+ * Method process attributes from Perun system and store them to request
112+ * @param User $user
113+ * @param array $attributes List of attributes which will be loaded from Perun system
114+ * @throws Exception
115+ */
116+ private function processAttributes (User $ user , array $ attributes ): void
117+ {
118+
95119 $ attrs = $ this ->adapter ->getUserAttributesValues ($ user , $ attributes );
96120
97121 foreach ($ attrs as $ attrName => $ attrValue ) {
@@ -137,12 +161,4 @@ public function process(&$request)
137161 }
138162 }
139163 }
140-
141- private function hasStringKeys ($ array )
142- {
143- if (!is_array ($ array )) {
144- return false ;
145- }
146- return count (array_filter (array_keys ($ array ), 'is_string ' )) > 0 ;
147- }
148164}
0 commit comments