server/sources/ldapuser.py
branchstable
changeset 5800 2bc88fb424bc
parent 5789 0f969e5c579a
child 5827 aad4496a279a
equal deleted inserted replaced
5799:93f4b4d2fecf 5800:2bc88fb424bc
   240                         ldapemailaddr = unicode(ldapemailaddr)
   240                         ldapemailaddr = unicode(ldapemailaddr)
   241                         for emaileid, emailaddr, in rset:
   241                         for emaileid, emailaddr, in rset:
   242                             if emailaddr == ldapemailaddr:
   242                             if emailaddr == ldapemailaddr:
   243                                 break
   243                                 break
   244                         else:
   244                         else:
   245                             self.info('updating email address of user %s to %s',
   245                             self.debug('updating email address of user %s to %s',
   246                                       extid, ldapemailaddr)
   246                                       extid, ldapemailaddr)
   247                             emailrset = execute('EmailAddress A WHERE A address %(addr)s',
   247                             emailrset = execute('EmailAddress A WHERE A address %(addr)s',
   248                                                 {'addr': ldapemailaddr})
   248                                                 {'addr': ldapemailaddr})
   249                             if emailrset:
   249                             if emailrset:
   250                                 execute('SET U use_email X WHERE '
   250                                 execute('SET U use_email X WHERE '
   502         #conn.sasl_interactive_bind_s('', sasl.gssapi())
   502         #conn.sasl_interactive_bind_s('', sasl.gssapi())
   503 
   503 
   504     def _search(self, session, base, scope,
   504     def _search(self, session, base, scope,
   505                 searchstr='(objectClass=*)', attrs=()):
   505                 searchstr='(objectClass=*)', attrs=()):
   506         """make an ldap query"""
   506         """make an ldap query"""
   507         self.info('ldap search %s %s %s %s %s', self.uri, base, scope, searchstr, list(attrs))
   507         self.debug('ldap search %s %s %s %s %s', self.uri, base, scope, searchstr, list(attrs))
   508         cnx = session.pool.connection(self.uri).cnx
   508         cnx = session.pool.connection(self.uri).cnx
   509         try:
   509         try:
   510             res = cnx.search_s(base, scope, searchstr, attrs)
   510             res = cnx.search_s(base, scope, searchstr, attrs)
   511         except ldap.PARTIAL_RESULTS:
   511         except ldap.PARTIAL_RESULTS:
   512             res = cnx.result(all=0)[1]
   512             res = cnx.result(all=0)[1]
   562         table yet.
   562         table yet.
   563 
   563 
   564         This method must return the an Entity instance representation of this
   564         This method must return the an Entity instance representation of this
   565         entity.
   565         entity.
   566         """
   566         """
   567         self.info('ldap before entity insertion')
   567         self.debug('ldap before entity insertion')
   568         entity = super(LDAPUserSource, self).before_entity_insertion(session, lid, etype, eid)
   568         entity = super(LDAPUserSource, self).before_entity_insertion(session, lid, etype, eid)
   569         res = self._search(session, lid, BASE)[0]
   569         res = self._search(session, lid, BASE)[0]
   570         for attr in entity.e_schema.indexable_attributes():
   570         for attr in entity.e_schema.indexable_attributes():
   571             entity[attr] = res[self.user_rev_attrs[attr]]
   571             entity[attr] = res[self.user_rev_attrs[attr]]
   572         return entity
   572         return entity
   573 
   573 
   574     def after_entity_insertion(self, session, dn, entity):
   574     def after_entity_insertion(self, session, dn, entity):
   575         """called by the repository after an entity stored here has been
   575         """called by the repository after an entity stored here has been
   576         inserted in the system table.
   576         inserted in the system table.
   577         """
   577         """
   578         self.info('ldap after entity insertion')
   578         self.debug('ldap after entity insertion')
   579         super(LDAPUserSource, self).after_entity_insertion(session, dn, entity)
   579         super(LDAPUserSource, self).after_entity_insertion(session, dn, entity)
   580         for group in self.user_default_groups:
   580         for group in self.user_default_groups:
   581             session.execute('SET X in_group G WHERE X eid %(x)s, G name %(group)s',
   581             session.execute('SET X in_group G WHERE X eid %(x)s, G name %(group)s',
   582                             {'x': entity.eid, 'group': group})
   582                             {'x': entity.eid, 'group': group})
   583         # search for existant email first
   583         # search for existant email first