@@ -91,6 +91,12 @@ def process(self, context, data):
91
91
clear_input_attributes = self .config ['clear_input_attributes' ]
92
92
else :
93
93
clear_input_attributes = False
94
+ if 'user_id_from_attrs' in config :
95
+ user_id_from_attrs = config ['user_id_from_attrs' ]
96
+ elif 'user_id_from_attrs' in self .config :
97
+ user_id_from_attrs = self .config ['user_id_from_attrs' ]
98
+ else :
99
+ user_id_from_attrs = []
94
100
95
101
except KeyError as err :
96
102
satosa_logging (logger , logging .ERROR , "{} Configuration '{}' is missing" .format (logprefix , err ), context .state )
@@ -153,15 +159,41 @@ def process(self, context, data):
153
159
satosa_logging (logger , logging .DEBUG , "{} Clearing values for these input attributes: {}" .format (logprefix , data .attributes ), context .state )
154
160
data .attributes = {}
155
161
156
- # Use a found record, if any, to populate attributes
162
+ # Use a found record, if any, to populate attributes and input for NameID
157
163
if record :
158
164
satosa_logging (logger , logging .DEBUG , "{} Using record with DN {}" .format (logprefix , record ["dn" ]), context .state )
159
165
satosa_logging (logger , logging .DEBUG , "{} Record with DN {} has attributes {}" .format (logprefix , record ["dn" ], record ["attributes" ]), context .state )
166
+
167
+ # Populate attributes as configured.
160
168
for attr in search_return_attributes .keys ():
161
169
if attr in record ["attributes" ]:
162
170
data .attributes [search_return_attributes [attr ]] = record ["attributes" ][attr ]
163
171
satosa_logging (logger , logging .DEBUG , "{} Setting internal attribute {} with values {}" .format (logprefix , search_return_attributes [attr ], record ["attributes" ][attr ]), context .state )
164
172
173
+ # Populate input for NameID if configured. SATOSA core does the hashing of input
174
+ # to create a persistent NameID.
175
+ if user_id_from_attrs :
176
+ userId = ""
177
+ for attr in user_id_from_attrs :
178
+ if attr in record ["attributes" ]:
179
+ value = record ["attributes" ][attr ]
180
+ if isinstance (value , list ):
181
+ # Use a default sort to ensure some predictability since the
182
+ # LDAP directory server may return multi-valued attributes
183
+ # in any order.
184
+ value .sort ()
185
+ for v in value :
186
+ userId += v
187
+ satosa_logging (logger , logging .DEBUG , "{} Added attribute {} with value {} to input for NameID" .format (logprefix , attr , v ), context .state )
188
+ else :
189
+ userId += value
190
+ satosa_logging (logger , logging .DEBUG , "{} Added attribute {} with value {} to input for NameID" .format (logprefix , attr , value ), context .state )
191
+ if not userId :
192
+ satosa_logging (logger , logging .WARNING , "{} Input for NameID is empty so not overriding default" .format (logprefix ), context .state )
193
+ else :
194
+ data .user_id = userId
195
+ satosa_logging (logger , logging .DEBUG , "{} Input for NameID is {}" .format (logprefix , data .user_id ), context .state )
196
+
165
197
else :
166
198
satosa_logging (logger , logging .WARN , "{} No record found in LDAP so no attributes will be added" .format (logprefix ), context .state )
167
199
0 commit comments