public ActiveDirectoryClient(Configuration config) { AppSettingsSection amSection, adSection, groupMappingsSection, fieldMappingsSection; this.config = config; amSection = (AppSettingsSection)config.Sections["AMSettings"]; adSection = (AppSettingsSection)config.Sections["ADSettings"]; groupMappingsSection = (AppSettingsSection)config.Sections["GroupMappings"]; fieldMappingsSection = (AppSettingsSection)config.Sections["FieldMappings"]; this.activeDirectoryUsers = new ArrayList(); this.alertMediaGroups = new ArrayList(); this.groupMappings = new Hashtable(); this.userFieldMappings = new Hashtable(); this.amServer = amSection.Settings["BaseUrl"].Value; this.clientId = amSection.Settings["ClientID"].Value; this.clientSecret = amSection.Settings["ClientSecret"].Value; this.groupMappingType = amSection.Settings["GroupMappingType"].Value; this.adUserFieldForGroupMapping = amSection.Settings["ADUserFieldForGroupMapping"].Value; this.ignoreDeleteUserList = amSection.Settings["IgnoreDeleteUserList"].Value; AlertMediaClient.setBaseUrl(this.amServer); AlertMediaClient.setClientId(this.clientId); AlertMediaClient.setClientKey(this.clientSecret); this.ldapUrl = adSection.Settings["LdapUrl"].Value; this.username = adSection.Settings["UserName"].Value; this.password = adSection.Settings["Password"].Value; this.adEmailField = fieldMappingsSection.Settings["email"].Value; this.adMobileNumberField = fieldMappingsSection.Settings["mobile_phone"].Value; foreach (var key in groupMappingsSection.Settings.AllKeys) { this.alertMediaGroups.Add(key); this.groupMappings.Add(key, groupMappingsSection.Settings[key].Value); } foreach (var key in fieldMappingsSection.Settings.AllKeys) { this.userFieldMappings.Add(key, fieldMappingsSection.Settings[key].Value); } if (this.userSearcher == null) { connectToActiveDirectory(); } }
public static void Main(string[] args) { AlertMediaClient.setBaseUrl(ConfigurationManager.AppSettings["BaseUrl"]); AlertMediaClient.setClientId(ConfigurationManager.AppSettings["ClientID"]); AlertMediaClient.setClientKey(ConfigurationManager.AppSettings["ClientKey"]); string customerId = AlertMediaClient.Customer.getCustomerId(); Console.ReadLine(); // Create Group /* * Hashtable args2 = new Hashtable (); * args2.Add ("name","Nag group"); * args2.Add ("customer","3"); * args2.Add ("description","This is a group created by Nag"); * Hashtable response = AlertMediaClient.Group.create (args2); * foreach(string key in response.Keys) { * Console.WriteLine(String.Format("{0}: {1}", key, response[key])); * } */ // List all groups for customer 3 // Update group // Hashtable args2 = new Hashtable(); // args2.Add("customer","3"); // args2.Add ("name", "Nag group 12312312"); // args2.Add ("description", "Nag from enfini"); // Hashtable response = AlertMediaClient.Group.update ("635", args2); // foreach(string key in response.Keys) { // Console.WriteLine(String.Format("{0}: {1}", key, response[key])); // } // Delete group // Hashtable response = AlertMediaClient.Group.delete ("635"); // foreach(string key in response.Keys) { // Console.WriteLine(String.Format("{0}: {1}", key, response[key])); // } // Get Group Details // Hashtable response = AlertMediaClient.Group.get ("635"); // foreach(string key in response.Keys) { // Console.WriteLine(String.Format("{0}: {1}", key, response[key])); // } // List users in group // ArrayList args2 = new ArrayList (); // args2.Add ("635"); // Hashtable response = AlertMediaClient.Group.listGroupUsers (args2); // foreach(string key in response.Keys) { // Console.WriteLine(String.Format("{0}: {1}", key, response[key])); // } // Add user to group // ArrayList args2 = new ArrayList (); // args2.Add ("29041"); // Hashtable response = AlertMediaClient.Group.addUsersToGroup ("635", args2); // foreach(string key in response.Keys) { // Console.WriteLine(String.Format("{0}: {1}", key, response[key])); // } // Delete users from group // ArrayList args2 = new ArrayList (); // args2.Add ("29041"); // Hashtable response = AlertMediaClient.Group.deleteUsersFromGroup ("635", args2); // foreach(string key in response.Keys) { // Console.WriteLine(String.Format("{0}: {1}", key, response[key])); // } }
private void connectToAd_Button_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; adSection.Settings["LdapURL"].Value = adServerURLTB.Text; adSection.Settings["Username"].Value = adUsernameTB.Text; adSection.Settings["Password"].Value = adPasswordTB.Text; amSection.Settings["BaseUrl"].Value = amServerNameTB.Text; amSection.Settings["ClientId"].Value = amClientIdTB.Text; amSection.Settings["ClientSecret"].Value = amClientSecretTB.Text; AlertMediaClient.setBaseUrl(amServerNameTB.Text); AlertMediaClient.setClientId(amClientIdTB.Text); AlertMediaClient.setClientKey(amClientSecretTB.Text); try { amSection.Settings["Customer"].Value = AlertMediaClient.Customer.getCustomerId(); } catch (Exception ex) { using (StreamWriter w = File.AppendText("adsynclog.txt")) { alertmedia.activedirectory.Utils.Log(ex.ToString(), w); } MessageBox.Show("Not able to connect to AlertMedia servers. Please check you internet connection and try again. If problem persists, please get in touch with support."); Cursor.Current = Cursors.Default; return; } Hashtable args = new Hashtable(); args.Add("customer", amSection.Settings["customer"].Value); Hashtable returnObject = null; try { returnObject = AlertMediaClient.Group.list(args); } catch (Exception ex) { using (StreamWriter w = File.AppendText("adsynclog.txt")) { alertmedia.activedirectory.Utils.Log(ex.ToString(), w); } MessageBox.Show("Not able to connect to AlertMedia servers. Please check you internet connection and try again. If problem persists, please get in touch with support."); Cursor.Current = Cursors.Default; return; } Group[] groups = (Group[])returnObject["data"]; Dictionary <string, string> existingGroupValues = new Dictionary <string, string>(); for (int i = 0; i < groups.Length; i++) { string groupName = groups[i].id + "~" + groups[i].name; if (groupSection.Settings.AllKeys.Contains(groupName)) { existingGroupValues.Add( groupName, groupSection.Settings[groupName].Value ); } } foreach (var tKey in groupSection.Settings.AllKeys) { groupSection.Settings.Remove(tKey); } for (int i = 0; i < groups.Length; i++) { if (!(groups[i].name.Equals("Everyone") || groups[i].name.Equals("Admins"))) { string groupName = groups[i].id + "~" + groups[i].name; if (existingGroupValues.Keys.Contains(groupName)) { groupSection.Settings.Add( new KeyValueConfigurationElement( groupName, existingGroupValues[groupName]) ); } else { groupSection.Settings.Add(new KeyValueConfigurationElement(groupName, "")); } } } config.Save(ConfigurationSaveMode.Minimal); parentForm.incrementPage(); parentForm.displayPanel(); Cursor.Current = Cursors.Default; }