Пример #1
0
def account_from_door_code(settings, door_code):
    query = "(&(objectCategory=person)(objectClass=user)(pinNumber=%s)" \
            "(!(userAccountControl:1.2.840.113556.1.4.803:=2))" \
            "(memberOf:1.2.840.113556.1.4.1941:=CN=Door Access,OU=" \
            "Security Groups,OU=MyBusiness,DC=synapsedev,DC=com))" % door_code

    # TODO Generalize this here and in ldap_provider.py
    r = connect_and_search_ldap(settings, settings['ou_to_search'], query,
                   ['cn', 'sAMAccountName', 'objectGUID'])

    # There should be no more and no less than one result per door code
    if not len(r) == 1:
        return None

    for dn, user in r:
        guid = ''.join(['%02X' % ord(c) for c in user['objectGUID'][0]])

        return (user['sAMAccountName'][0], guid, user['cn'][0])
Пример #2
0
    def get_user_ldap_info(self):
        """Extract user information from our ldap server"""

        r = connect_and_search_ldap(self.settings,
                self.settings['ou_to_search'],
                "(sAMAccountName=*)",
                ['sAMAccountName', 'cn', 'objectGUID', 'manager', 'department',
                    'givenName', 'sn', 'mail'])

        users = []

        for dn, user in r:
            guid = ''.join(['%02X' % ord(c) for c in user['objectGUID'][0]])

            # In case a desired property is missing
            user = defaultdict(lambda: [''], user)

            users.append(User(account=user['sAMAccountName'][0], guid=guid,
                display_name=user['cn'][0], first_name=user['givenName'][0],
                last_name=user['sn'][0], department=user['department'][0],
                email=user['mail'][0], provider=self))

        return users