Projet

Général

Profil

0001-LDAP-user-get-attributes-NG-before-mapping-65064.patch

Benjamin Renard, 10 mai 2022 11:07

Télécharger (2,06 ko)

Voir les différences:

Subject: [PATCH] LDAP user: get attributes NG before mapping (#65064)

License: MIT
 src/authentic2/backends/ldap_backend.py | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
src/authentic2/backends/ldap_backend.py
48 48
from authentic2 import app_settings
49 49
from authentic2.a2_rbac.models import OrganizationalUnit, Role
50 50
from authentic2.a2_rbac.utils import get_default_ou
51
from authentic2.attributes_ng.engine import get_attributes as get_attributes_ng
51 52
from authentic2.backends import is_user_authenticable
52 53
from authentic2.compat_lasso import lasso
53 54
from authentic2.ldap_utils import FilterFormatter
......
824 825
            # attributes are missing to build the username
825 826
            return None
826 827

  
827
    def populate_user_attributes(self, user, block, attributes):
828
    def populate_user_attributes(self, user, block, ldap_attributes):
829
        # retreive and merge attributes NG
830
        attributes_ng = get_attributes_ng({'user': user})
831
        attributes = {}
832
        for attr in list(set(list(attributes_ng.keys()) + list(attributes.keys()))):
833
            if attr == 'user':
834
                continue
835
            if attributes_ng.get(attr):
836
                attributes[attr] = (
837
                    [attributes_ng[attr]]
838
                    if not isinstance(attributes_ng[attr], list)
839
                    else attributes_ng[attr]
840
                )
841
            elif ldap_attributes.get(attr):
842
                attributes[attr] = ldap_attributes[attr]
843

  
828 844
        # map legacy attributes (columns from Django user model)
829 845
        for legacy_attribute, legacy_field in (
830 846
            ('email', 'email_field'),
831
-