~therp-nl/therp-addons/7.0_lp1215631

« back to all changes in this revision

Viewing changes to users_ldap_groups/users_ldap_groups_operators.py

  • Committer: Holger Brunn
  • Date: 2013-01-28 11:01:51 UTC
  • mto: This revision was merged to the branch mainline in revision 77.
  • Revision ID: hbrunn@therp.nl-20130128110151-o5fsiihrptsh2ywp
[ADD] operator 'query', allowing group mappings for the typical posixAccount
setup

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
19
#
20
20
##############################################################################
 
21
from string import Template
21
22
 
22
23
class LDAPOperator:
23
24
  pass
24
25
 
25
26
class contains(LDAPOperator):
26
 
  def check_value(self, ldap_entry, attribute, value):
 
27
  def check_value(self, ldap_entry, attribute, value, ldap_config, company,
 
28
          logger):
27
29
    return (attribute in ldap_entry[1]) and (value in ldap_entry[1][attribute])
28
30
 
29
31
class equals(LDAPOperator):
30
 
  def check_value(self, ldap_entry, attribute, value):
 
32
  def check_value(self, ldap_entry, attribute, value, ldap_config, company,
 
33
          logger):
31
34
    return (attribute in ldap_entry[1]) and (str(value)==str(ldap_entry[1][attribute]))
 
35
 
 
36
class query(LDAPOperator):
 
37
  def check_value(self, ldap_entry, attribute, value, ldap_config, company,
 
38
          logger):
 
39
      query_string=Template(value).safe_substitute(dict([(attribute, 
 
40
          ldap_entry[1][attribute][0]) for attribute in ldap_entry[1]]))
 
41
      logger.debug('evaluating query group mapping, filter: %s'%query_string)
 
42
      results=company.query(ldap_config, query_string)
 
43
      logger.debug(results)
 
44
      return bool(results)