File: ModuleLdap.py

package info (click to toggle)
cherokee 0.7.2-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 8,808 kB
  • ctags: 6,577
  • sloc: ansic: 45,071; python: 9,628; sh: 9,468; makefile: 1,639; xml: 61; perl: 32
file content (54 lines) | stat: -rw-r--r-- 2,346 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from Table import *
from ModuleAuth import *

NOTE_SERVER      = 'LDAP server IP address.'
NOTE_PORT        = 'LDAP server port to connect to.'
NOTE_BIND_DOMAIN = 'Domain sent during the LDAP authentication operation.'
NOTE_BIND_PASSWD = 'Password for authenticating in the LDAP server.'
NOTE_BASE_DOMAIN = 'Base domain for the web server authentications.'
NOTE_FILTER      = 'Object filter. It can be empty.'
NOTE_USE_TLS     = 'Enable to use secure connections between the web and LDAP servers.'
NOTE_CA_FILE     = 'CA File for the TLS connections.'

class ModuleLdap (ModuleAuthBase):
    PROPERTIES = ModuleAuthBase.PROPERTIES + [
        'server', 'port', 
        'bind_dn', 'base_dn',
        'filter', 'tls', 
        'ca_file'
    ]

    METHODS = ['basic']

    def __init__ (self, cfg, prefix, submit):
        ModuleAuthBase.__init__ (self, cfg, prefix, 'ldap', submit)

    def _op_render (self):
        table = TableProps()
        self.AddPropEntry (table, "Server", "%s!server"%(self._prefix), NOTE_SERVER)
        self.AddPropEntry (table, "Port", "%s!port"%(self._prefix), NOTE_PORT)
        self.AddPropEntry (table, "Bind Domain", "%s!bind_dn"%(self._prefix), NOTE_BIND_DOMAIN)
        self.AddPropEntry (table, "Bind Password", "%s!bind_pw"%(self._prefix), NOTE_BIND_PASSWD)
        self.AddPropEntry (table, "Base Domain", "%s!base_dn"%(self._prefix), NOTE_BIND_DOMAIN)
        self.AddPropEntry (table, "Filter", "%s!filter"%(self._prefix), NOTE_FILTER)
        self.AddPropCheck (table, 'Use TLS', "%s!tls"%(self._prefix), False, NOTE_USE_TLS)
        self.AddPropEntry (table, "CA File", "%s!ca_file"%(self._prefix), NOTE_CA_FILE)

        txt  = ModuleAuthBase._op_render (self)
        txt += '<h2>LDAP connection</h2>'
        txt += self.Indent(table)
        return txt

    def _op_apply_changes (self, uri, post):
        # These values must be filled out
        for key, msg in [('server', 'Server'),
                         ('bind_dn', 'Bind Domain'),
                         ('base_dn', 'Base Domain')]:
            pre = '%s!%s' % (self._prefix, key)
            self.Validate_NotEmpty (post, pre, '%s can not be empty'%(msg))
            
        # Apply TLS
        self.ApplyChangesPrefix (self._prefix, ['tls'], post)
        post.pop('tls')

        ModuleAuthBase._op_apply_changes (self, uri, post)