本文整理汇总了Python中placard.client.LDAPClient类的典型用法代码示例。如果您正苦于以下问题:Python LDAPClient类的具体用法?Python LDAPClient怎么用?Python LDAPClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LDAPClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_account
def create_account(self, person, default_project):
ua = super(AccountDataStore, self).create_account(person, default_project)
conn = LDAPClient()
ldap_attrs = __import__(settings.LDAP_ATTRS, {}, {}, [''])
data = conn.get_user('sAMAccountName=%s' % person.username).__dict__
data['cluster_account'] = True
data['objectClass'] = settings.ACCOUNT_OBJECTCLASS
data['default_project'] = default_project
data['person'] = person
conn.update_user(
'sAMAccountName=%s' % person.username,
objectClass=settings.ACCOUNT_OBJECTCLASS,
uidNumber=ldap_attrs.GENERATED_USER_ATTRS['uidNumber'](data),
gidNumber=ldap_attrs.GENERATED_USER_ATTRS['gidNumber'](data),
unixHomeDirectory=ldap_attrs.GENERATED_USER_ATTRS['unixHomeDirectory'](data),
loginShell=ldap_attrs.GENERATED_USER_ATTRS['loginShell'](data),
uid=person.username,
msSFU30Name=person.username,
msSFU30NisDomain=settings.LDAP_NISDOMAIN,
unixUserPassword='ABCD!efgh12345$67890',
)
del(conn)
return ua
示例2: user_exists
def user_exists(self, username):
conn = LDAPClient()
try:
conn.get_user('uid=%s' % username)
return True
except DoesNotExistException:
return False
示例3: test_delete_activate_user
def test_delete_activate_user(self):
logged_in = self.client.login(username='kgsuper', password='aq12ws')
user = Person.objects.get(user__username='kgtestuser3')
self.assertEqual(user.is_active, True)
self.assertEqual(user.project_set.count(), 1)
self.assertEqual(user.useraccount_set.count(), 1)
self.assertEqual(user.useraccount_set.all()[0].date_deleted, None)
lcon = LDAPClient()
luser = lcon.get_user('uid=kgtestuser3')
self.assertEqual(luser.givenName, 'Test')
response = self.client.get(reverse('admin_delete_user', args=[user.username]))
self.failUnlessEqual(response.status_code, 200)
# Test deleting
response = self.client.post(reverse('admin_delete_user', args=[user.username]))
self.failUnlessEqual(response.status_code, 302)
user = Person.objects.get(user__username='kgtestuser3')
self.assertEqual(user.is_active, False)
self.assertEqual(user.project_set.count(), 0)
self.assertEqual(user.useraccount_set.count(), 1)
self.assertEqual(user.useraccount_set.all()[0].date_deleted, datetime.date.today())
self.failUnlessRaises(placard_exceptions.DoesNotExistException, lcon.get_user, 'uid=kgtestuser3')
# Test activating
response = self.client.post(reverse('admin_activate_user', args=[user.username]))
self.failUnlessEqual(response.status_code, 302)
user = Person.objects.get(user__username='kgtestuser3')
self.assertEqual(user.is_active, True)
luser = lcon.get_user('uid=kgtestuser3')
self.assertEqual(luser.givenName, 'Test')
示例4: test_add_remove_user_to_project
def test_add_remove_user_to_project(self):
lcon = LDAPClient()
luser = lcon.get_user('uid=kgtestuser2')
self.client.login(username='kgsuper', password='aq12ws')
project = Project.objects.get(pk='TestProject1')
self.assertEqual(project.users.count(), 1)
response = self.client.get(reverse('kg_project_detail', args=[project.pid]))
self.failUnlessEqual(response.status_code, 200)
ldap_members = LDAPClient().get_group_members('cn=%s' % project.pid)
self.assertFalse(luser in ldap_members)
new_user = Person.objects.get(user__username='kgtestuser2')
response = self.client.post(reverse('kg_project_detail', args=[project.pid]), { 'person': new_user.id} )
self.failUnlessEqual(response.status_code, 302)
project = Project.objects.get(pk='TestProject1')
self.assertEqual(project.users.count(), 2)
ldap_members = LDAPClient().get_group_members('cn=%s' % project.pid)
self.assertTrue(luser in ldap_members)
# remove user
response = self.client.post(reverse('kg_remove_project_member', args=[project.pid, new_user.username]))
self.failUnlessEqual(response.status_code, 302)
project = Project.objects.get(pk='TestProject1')
self.assertEqual(project.users.count(), 1)
ldap_members = LDAPClient().get_group_members('cn=%s' % project.pid)
self.assertFalse(luser in ldap_members)
示例5: get_members
def get_members(self, software):
conn = LDAPClient()
try:
return conn.get_group_members('gidNumber=%s' % software.gid)
except:
return []
del(conn)
示例6: get_name
def get_name(self, software):
conn = LDAPClient()
try:
ldap_group = conn.get_group('gidNumber=%s' % software.gid)
return ldap_group.cn
except DoesNotExistException:
return 'No LDAP Group'
示例7: delete_software
def delete_software(self, software):
conn = LDAPClient()
try:
conn.delete_group('cn=%s' % software.pid)
except DoesNotExistException:
pass
del(conn)
示例8: test_admin_edit_project
def test_admin_edit_project(self):
project = Project.objects.get(pk='TestProject1')
self.assertEqual(project.is_active, True)
self.assertEqual(project.name, 'Test Project 1')
self.assertTrue(Person.objects.get(pk=1) in project.leaders.all())
self.assertTrue(Person.objects.get(pk=3) in project.users.all())
self.client.login(username='kgsuper', password='aq12ws')
response = self.client.get(reverse('kg_edit_project', args=['TestProject1']))
self.failUnlessEqual(response.status_code, 200)
form_data = {
'name': 'Test Project 1 was 4',
'description': 'Test',
'institute': 1,
'leaders': [2,3],
'machine_category': 1,
'machine_categories': [1,],
'start_date': project.start_date,
}
response = self.client.post(reverse('kg_edit_project', args=['TestProject1']), form_data)
self.failUnlessEqual(response.status_code, 302)
project = Project.objects.get(pk='TestProject1')
self.assertEqual(project.is_active, True)
self.assertTrue(Person.objects.get(pk=2) in project.leaders.all())
self.assertTrue(Person.objects.get(pk=3) in project.leaders.all())
lcon = LDAPClient()
lgroup = lcon.get_group('cn=%s' % project.pid)
self.assertEqual(lgroup.cn, project.pid)
示例9: test_admin_add_project_pid
def test_admin_add_project_pid(self):
projects = Project.objects.count()
self.client.login(username='kgsuper', password='aq12ws')
response = self.client.get(reverse('kg_add_project'))
self.failUnlessEqual(response.status_code, 200)
form_data = {
'pid': "Enrico",
'name': 'Test Project 4',
'description': 'Test',
'institute': 1,
'leaders': [2,3],
'machine_category': 1,
'machine_categories': [1,],
'start_date': datetime.date.today(),
}
response = self.client.post(reverse('kg_add_project'), form_data)
self.failUnlessEqual(response.status_code, 302)
project = Project.objects.get(pid="Enrico")
self.assertEqual(project.is_active, True)
self.assertEqual(project.date_approved, datetime.date.today())
self.assertEqual(project.approved_by, Person.objects.get(user__username='kgsuper'))
self.assertEqual(project.pid, 'Enrico')
self.assertTrue(Person.objects.get(pk=2) in project.leaders.all())
self.assertTrue(Person.objects.get(pk=3) in project.leaders.all())
lcon = LDAPClient()
lgroup = lcon.get_group('cn=%s' % project.pid)
self.assertEqual(lgroup.cn, project.pid)
示例10: delete_user
def delete_user(self, person):
super(PersonalDataStore, self).delete_user(person)
conn = LDAPClient()
try:
conn.delete_user('uid=%s' % person.user.username)
except DoesNotExistException:
pass
示例11: get_next_uid
def get_next_uid(data):
if 'posixAccount' in data['objectClass']:
from placard.client import LDAPClient
conn = LDAPClient()
uidNumber = conn.get_new_uid()
return str(uidNumber)
else:
return ''
示例12: unlock_user
def unlock_user(self, person):
super(PersonalDataStore, self).unlock_user(person)
conn = LDAPClient()
conn.update_user(
'sAMAccountName=%s' % person.username,
userAccountControl=512,
)
示例13: lock_user
def lock_user(self, person):
super(PersonalDataStore, self).lock_user(person)
conn = LDAPClient()
conn.update_user(
'uid=%s' % person.username,
nsRoleDN=settings.LDAP_LOCK_DN,
)
del(conn)
示例14: is_locked
def is_locked(self, person):
super(ldap_datastore.PersonalDataStore, self).is_locked(person)
conn = LDAPClient()
try:
ldap_user = conn.get_user('uid=%s' % person.username)
except DoesNotExistException:
return True
return conn.is_locked('uid=%s' % person.username)
示例15: loginShell
def loginShell(self):
conn = LDAPClient()
try:
ldap_user = conn.get_user('uid=%s' % self.username)
except:
return ''
try:
return ldap_user.loginShell
except:
return ''