Add Domain User¶
Add Domain User¶
1# This example creates some new domain (LDAP) users in the database.
2
3
4# Create a local variable for the output toolbox
5ot = impact.gui.output_toolbox
6db = impact.active_database
7
8# Retrieve the users from the DB
9users = db.users
10
11# Get the first site in the DB (may not be any though)
12sites = db.sites
13
14
15def describe_user(user):
16 ot.add(" LoginID: " + str(user.login_id))
17 ot.add(" Formatted Name: " + str(user.formatted_name))
18 ot.add(" User Group: " + str(user.user_group))
19 ot.add(" Email: " + str(user.email))
20
21
22# Clear the output toolbox
23ot.clear()
24
25if sites.count > 0:
26 site = sites.item(1)
27
28# Get the first user group from the DB
29mastersettings = db.find_master_tool_settings(ipMasterSettingType.mstUserGroup)
30usergroup = mastersettings.item(1)
31
32ot.add("UserGroup: " + str(usergroup.name))
33if not site.isNone():
34 ot.add("Site: " + str(site.full_name))
35
36publish_to_enterprise = False
37
38# Create a domain user without verifying against the LDAP service
39# You can optionally pass in a site and usergroup but these may later be overridden by LDAP user mappings
40LDAPUpdate = False
41
42domain_user1 = users.add_domain("user1@domain.com", ipUserType.utCAD, LDAPUpdate, site, usergroup, publish_to_enterprise)
43
44if not domain_user1.isNone():
45 ot.add("Successfully added domain user " + str(domain_user1.login_id))
46
47 # A domain user without an LDAPUpdate will not contain any useful user attributes
48 # When they first connect the user attributes will automatically be updated
49else:
50 ot.add("Failed to add domain user. " + str(db.errors.last.description))
51
52# Create a domain user and verify against the LDAP service
53LDAPUpdate = True
54
55domain_user2 = users.add_domain("user2@domain.com", ipUserType.utCAD, LDAPUpdate, None, None, publish_to_enterprise)
56
57if not domain_user2.isNone():
58 ot.add("Successfully added domain user " + str(domain_user2.login_id))
59
60 # A domain user with an LDAPUpdate will contain useful user attributes
61 describe_user(domain_user2)
62else:
63 ot.add("Failed to add domain user. " + str(db.errors.last.description))
64
65# Create a domain user without verifying against the LDAP service and update separately
66LDAPUpdate = False
67
68domain_user3 = users.add_domain("user3@domain.com", ipUserType.utCAD, LDAPUpdate, None, None, publish_to_enterprise)
69
70if not domain_user3.isNone():
71 ot.add("Successfully added domain user " + str(domain_user3.login_id))
72
73 if domain_user3.ldap_update():
74 ot.add("Successfully updated LDAP user attributes")
75 describe_user(domain_user3)
76 else:
77 ot.add("Failed to update LDAP user attributes. " + str(db.errors.last.description))
78
79else:
80 ot.add("Failed to add domain user. " + str(db.errors.last.description))
81