backends: truncate user attributes before assigning them from LDAP values

This commit is contained in:
Benjamin Dauvergne 2017-11-24 15:56:39 +01:00
parent 983d3a9db9
commit 835f9dd206
1 changed files with 4 additions and 1 deletions

View File

@ -110,10 +110,13 @@ class CASBackend(PolynumBackendMixin, CASBackend):
attributes = self.ldap_attributes_to_unicode(r[0][1])
for key in attributes:
value = attributes[key][0]
setattr(user, key, value)
if key in self.USER_ATTRIBUTES:
max_length = User._meta.get_field(self.USER_ATTRIBUTES[key]).max_length
value = value[:max_length]
setattr(user, self.USER_ATTRIBUTES[key], value)
if key in self.PROFILE_ATTRIBUTES:
max_length = PolynumProfile._meta.get_field(self.PROFILE_ATTRIBUTES[key]).max_length
value = value[:max_length]
setattr(profile, self.PROFILE_ATTRIBUTES[key], value)
profile.save()
return user