Limit dependency on python-ldap.
This commit is contained in:
parent
64c19f2043
commit
de35da3b08
|
@ -260,11 +260,18 @@ def load_or_create_user_profile(user=None, no_cleanup=False):
|
|||
% user)
|
||||
profile = UserAttributeProfile.objects.get(user=user)
|
||||
except ObjectDoesNotExist:
|
||||
profile = UserAttributeProfile(user=user)
|
||||
profile.save()
|
||||
logger.info('load_or_create_user_profile: \
|
||||
profile with id %s for user %s created' \
|
||||
% (str(profile.id), user))
|
||||
try:
|
||||
profile = UserAttributeProfile(user=user)
|
||||
profile.save()
|
||||
logger.info('load_or_create_user_profile: \
|
||||
profile with id %s for user %s created' \
|
||||
% (str(profile.id), user))
|
||||
except:
|
||||
profile = UserAttributeProfile()
|
||||
profile.save()
|
||||
logger.debug('load_or_create_user_profile: \
|
||||
profile with id %s for an anonymous user created' \
|
||||
% str(profile.id))
|
||||
else:
|
||||
if no_cleanup:
|
||||
logger.debug('load_or_create_user_profile: Existing user \
|
||||
|
|
|
@ -26,6 +26,10 @@ from cPickle import loads, dumps
|
|||
from django.utils.translation import ugettext as _
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
try:
|
||||
import ldap
|
||||
except ImportError:
|
||||
ldap = None
|
||||
|
||||
from acs.attribute_aggregator.signals import any_attributes_call, \
|
||||
listed_attributes_call, listed_attributes_with_source_call
|
||||
|
@ -77,37 +81,36 @@ def get_all_sources():
|
|||
except:
|
||||
return None
|
||||
|
||||
if ldap:
|
||||
class LdapSource(AttributeSource):
|
||||
server = models.CharField(
|
||||
verbose_name = _("Server"),
|
||||
max_length=200, unique=True)
|
||||
user = models.CharField(
|
||||
verbose_name = _("User"),
|
||||
max_length=200, blank=True, null=True)
|
||||
password = models.CharField(
|
||||
verbose_name = _("Password"),
|
||||
max_length=200, blank=True, null=True)
|
||||
base = models.CharField(
|
||||
verbose_name = _("Base"),
|
||||
max_length=200)
|
||||
port = models.IntegerField(
|
||||
verbose_name = _("Port"),
|
||||
default=389)
|
||||
ldaps = models.BooleanField(
|
||||
verbose_name = _("LDAPS"),
|
||||
default=False)
|
||||
certificate = models.TextField(
|
||||
verbose_name = _("Certificate"),
|
||||
blank=True)
|
||||
is_auth_backend = models.BooleanField(
|
||||
verbose_name = _("Is it used for authentication?"),
|
||||
default=False)
|
||||
|
||||
class LdapSource(AttributeSource):
|
||||
server = models.CharField(
|
||||
verbose_name = _("Server"),
|
||||
max_length=200, unique=True)
|
||||
user = models.CharField(
|
||||
verbose_name = _("User"),
|
||||
max_length=200, blank=True, null=True)
|
||||
password = models.CharField(
|
||||
verbose_name = _("Password"),
|
||||
max_length=200, blank=True, null=True)
|
||||
base = models.CharField(
|
||||
verbose_name = _("Base"),
|
||||
max_length=200)
|
||||
port = models.IntegerField(
|
||||
verbose_name = _("Port"),
|
||||
default=389)
|
||||
ldaps = models.BooleanField(
|
||||
verbose_name = _("LDAPS"),
|
||||
default=False)
|
||||
certificate = models.TextField(
|
||||
verbose_name = _("Certificate"),
|
||||
blank=True)
|
||||
is_auth_backend = models.BooleanField(
|
||||
verbose_name = _("Is it used for authentication?"),
|
||||
default=False)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(LdapSource, self).__init__(*args, **kwargs)
|
||||
self.namespace = "X500"
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(LdapSource, self).__init__(*args, **kwargs)
|
||||
self.namespace = "X500"
|
||||
|
||||
class UserAliasInSource(models.Model):
|
||||
name = models.CharField(
|
||||
|
|
|
@ -18,7 +18,10 @@
|
|||
'''
|
||||
|
||||
|
||||
import ldap_sources
|
||||
try:
|
||||
import ldap_sources
|
||||
except ImportError:
|
||||
ldap_sources = None
|
||||
import user_profile
|
||||
|
||||
from django.dispatch import Signal
|
||||
|
@ -29,9 +32,10 @@ listed_attributes_call = Signal(providing_args = ["user", "definitions"])
|
|||
listed_attributes_with_source_call = Signal(providing_args = \
|
||||
["user", "definitions", "source"])
|
||||
|
||||
any_attributes_call.connect(ldap_sources.get_attributes)
|
||||
listed_attributes_call.connect(ldap_sources.get_attributes)
|
||||
listed_attributes_with_source_call.connect(ldap_sources.get_attributes)
|
||||
if ldap_sources:
|
||||
any_attributes_call.connect(ldap_sources.get_attributes)
|
||||
listed_attributes_call.connect(ldap_sources.get_attributes)
|
||||
listed_attributes_with_source_call.connect(ldap_sources.get_attributes)
|
||||
|
||||
any_attributes_call.connect(user_profile.get_attributes)
|
||||
listed_attributes_call.connect(user_profile.get_attributes)
|
||||
|
|
Reference in New Issue