Ejemplo n.º 1
0
    def ldap(self):
        if self._ldap is None:
            options = getattr(django.conf.settings, 'AUTH_LDAP_GLOBAL_OPTIONS', None)

            self._ldap = _LDAPConfig.get_ldap(options)

        return self._ldap
Ejemplo n.º 2
0
    def _get_ldap(self):
        if self._ldap is None:
            options = getattr(django.conf.settings, 'AUTH_LDAP_GLOBAL_OPTIONS', None)

            self._ldap = _LDAPConfig.get_ldap(options)

        return self._ldap
Ejemplo n.º 3
0
    def _get_ldap(self):
        if self._ldap is None:
            from django.conf import settings

            options = getattr(settings, 'AUTH_LDAP_GLOBAL_OPTIONS', None)

            self._ldap = _LDAPConfig.get_ldap(options)

        return self._ldap
Ejemplo n.º 4
0
    def ldap_module(self):
        """
        Requests the ldap module from _LDAPConfig. Under a test harness, this
        will be a mock object.
        """
        from django.conf import settings

        options = getattr(settings, "AUTH_LDAP_GLOBAL_OPTIONS", None)

        return _LDAPConfig.get_ldap(options)
Ejemplo n.º 5
0
    def ldap_module(self):
        """
        Requests the ldap module from _LDAPConfig. Under a test harness, this
        will be a mock object.
        """
        from django.conf import settings

        options = getattr(settings, 'AUTH_LDAP_GLOBAL_OPTIONS', None)

        return _LDAPConfig.get_ldap(options)
Ejemplo n.º 6
0
    def create_ldap_user(sender, instance, created, **kwargs):
        username = instance.first_name[0] + "".join(instance.last_name.split(" "))
        username = unidecode.unidecode(username.lower())
        
        if not created or User.objects.filter(username=username).count():
            return

        ldap_c = _LDAPConfig.get_ldap()

        ldap_settings = LDAPSettings()
        conn = ldap_c.initialize(django_settings.AUTH_LDAP_SERVER_URI)
        conn.simple_bind_s(django_settings.AUTH_LDAP_BIND_DN, django_settings.AUTH_LDAP_BIND_PASSWORD)
        for opt, value in ldap_settings.CONNECTION_OPTIONS.iteritems():
            conn.set_option(opt, value)

        uid = gid = 1500 + instance.id
        new_password = get_pronounceable_password()
        new_user_group = [
                    ('objectclass', ['posixGroup', 'top']),
                    ('gidNumber', str(gid)),
                    ]
        try:
            conn.add_s('cn=' + str(username) + ',ou=groups,dc=bomberos,dc=usb,dc=ve', new_user_group)
        except:
            pass

        new_user = [
                    ('objectclass', ['inetOrgPerson', 'posixAccount', 'top']),
                    ('gidNumber', str(gid)),
                    ('uidNumber', str(uid)),
                    ('sn', str(instance)),
                    ('givenName', str(instance.first_name.encode('UTF-8'))),
                    ('displayName', str(instance.first_name.encode('UTF-8')) + " " + str(instance.last_name.encode('UTF-8'))),
                    ('cn', str(instance.first_name.encode('UTF-8')) + " " + str(instance.last_name.encode('UTF-8'))),
                    ('homeDirectory', str('/home/') + str(username) + '/'),
                    ('loginShell', str('/bin/bash')),
                    ('userPassword', makeSecret(new_password)),
                    ('mail', username+"@bomberos.usb.ve"),
                    ]

        try:
            conn.add_s('uid=' + username + ',ou=users,dc=bomberos,dc=usb,dc=ve', new_user)
        except:
            pass
        mod_attrs = [(ldap_c.MOD_ADD, 'memberUid', username)]
        try:
            conn.modify_s('cn=cbvusb,ou=groups,dc=bomberos,dc=usb,dc=ve', mod_attrs)
        except:
            pass

        send_welcome_email(str(instance), username, new_password, instance.alternate_email)
        send_webmaster_email(username)
        instance.primary_email = username + "@bomberos.usb.ve"
        instance.save()
Ejemplo n.º 7
0
    def ldap_module(cls):
        """
        Requests the ldap module from _LDAPConfig. Under a test harness, this
        will be a mock object. We only do this once because this is where we
        apply AUTH_LDAP_GLOBAL_OPTIONS.
        """
        if cls.ldap is None:
            cls.ldap = _LDAPConfig.get_ldap()

            for opt, value in ldap_settings.AUTH_LDAP_GLOBAL_OPTIONS.iteritems():
                cls.ldap.set_option(opt, value)

        return cls.ldap
Ejemplo n.º 8
0
 def ldap_module(cls):
     """
     Requests the ldap module from _LDAPConfig. Under a test harness, this
     will be a mock object. We only do this once because this is where we
     apply AUTH_LDAP_GLOBAL_OPTIONS.
     """
     if cls.ldap is None:
         cls.ldap = _LDAPConfig.get_ldap()
         
         for opt, value in ldap_settings.AUTH_LDAP_GLOBAL_OPTIONS.iteritems():
             cls.ldap.set_option(opt, value)
     
     return cls.ldap
Ejemplo n.º 9
0
    def update_ldap_password(self):
        if not django_settings.AUTH_LDAP_BIND_PASSWORD:
            return
        
        ldap_c = _LDAPConfig.get_ldap()
        ldap_settings = LDAPSettings()
        conn = ldap_c.initialize(django_settings.AUTH_LDAP_SERVER_URI)
        conn.simple_bind_s(django_settings.AUTH_LDAP_BIND_DN, django_settings.AUTH_LDAP_BIND_PASSWORD)
        
        for opt, value in ldap_settings.AUTH_LDAP_CONNECTION_OPTIONS.iteritems():
            conn.set_option(opt, value)

        new_password = get_pronounceable_password()
        username = self.primary_email.split("@")[0]
        mod_attrs = [(ldap_c.MOD_REPLACE, 'userPassword', makeSecret(new_password))]
        conn.modify_s('uid='+username+',ou=users,dc=bomberos,dc=usb,dc=ve', mod_attrs)

        send_welcome_email(str(self), username, new_password, self.alternate_email)
Ejemplo n.º 10
0
    def update_ldap_password(self, password = None):
        if not django_settings.AUTH_LDAP_BIND_PASSWORD:
            return
        
        ldap_c = _LDAPConfig.get_ldap()
        ldap_settings = LDAPSettings()
        conn = ldap_c.initialize(django_settings.AUTH_LDAP_SERVER_URI)
        conn.simple_bind_s(django_settings.AUTH_LDAP_BIND_DN, django_settings.AUTH_LDAP_BIND_PASSWORD)
        
        for opt, value in ldap_settings.CONNECTION_OPTIONS.iteritems():
            conn.set_option(opt, value)
        
        new_password = get_pronounceable_password() if not password else password
        username = self.primary_email.split("@")[0]
        mod_attrs = [(ldap_c.MOD_REPLACE, 'userPassword', makeSecret(new_password))]
        conn.modify_s('uid='+username+',ou=users,dc=bomberos,dc=usb,dc=ve', mod_attrs)

        send_welcome_email(str(self), username, new_password, self.alternate_email)