Beispiel #1
0
        public static void UpdateDirectoryObjectProperties(DirectoryObjectCollection exportedItems, DirectoryBindingInfo targetDirectoryBindingInfo)
        {
            DirectoryObjectCollection directoryObjectCollection;

            using (SearchResultCollection schema = OrganizationMigrationManager.GetSchema(null, "(|(objectClass=attributeSchema)(objectClass=classSchema))", targetDirectoryBindingInfo))
            {
                directoryObjectCollection = new DirectoryObjectCollection("Schema", schema);
            }
            foreach (DirectoryObject directoryObject in exportedItems)
            {
                using (ActiveDirectorySchemaClass activeDirectorySchemaClass = ActiveDirectorySchemaClass.FindByName(targetDirectoryBindingInfo.GetDirectoryContext(DirectoryContextType.Forest), directoryObject.Properties["objectclass"][directoryObject.Properties["objectclass"].Values.Count - 1].ToString()))
                {
                    foreach (object obj in activeDirectorySchemaClass.MandatoryProperties)
                    {
                        ActiveDirectorySchemaProperty activeDirectorySchemaProperty = (ActiveDirectorySchemaProperty)obj;
                        if (directoryObject.Properties.Contains(activeDirectorySchemaProperty.Name))
                        {
                            directoryObject.Properties[activeDirectorySchemaProperty.Name].IsRequired = true;
                        }
                    }
                    foreach (object obj2 in activeDirectorySchemaClass.GetAllProperties())
                    {
                        ActiveDirectorySchemaProperty activeDirectorySchemaProperty2 = (ActiveDirectorySchemaProperty)obj2;
                        if (directoryObject.Properties.Contains(activeDirectorySchemaProperty2.Name))
                        {
                            directoryObject.Properties[activeDirectorySchemaProperty2.Name].Syntax = activeDirectorySchemaProperty2.Syntax;
                        }
                    }
                }
                foreach (DirectoryProperty directoryProperty in directoryObject.Properties)
                {
                    DirectoryObject directoryObjectByLdapDisplayName = directoryObjectCollection.GetDirectoryObjectByLdapDisplayName(directoryProperty.Name);
                    if (directoryObjectByLdapDisplayName != null)
                    {
                        if (directoryObjectByLdapDisplayName.Properties.Contains("linkID") && directoryObjectByLdapDisplayName.Properties["linkID"].Values != null && int.Parse(directoryObjectByLdapDisplayName.Properties["linkID"][0].ToString()) % 2 != 0)
                        {
                            directoryProperty.IsBackLink = true;
                        }
                        if (directoryObjectByLdapDisplayName.Properties.Contains("attributeSyntax") && directoryObjectByLdapDisplayName.Properties["attributeSyntax"].Values != null && directoryObjectByLdapDisplayName.Properties["attributeSyntax"][0].ToString().CompareTo("2.5.5.1") == 0)
                        {
                            directoryProperty.IsLink = true;
                        }
                        if (directoryObjectByLdapDisplayName.Properties.Contains("systemOnly") && directoryObjectByLdapDisplayName.Properties["systemOnly"].Values != null && directoryObjectByLdapDisplayName.Properties["systemOnly"][0].ToString().ToLower() == "true")
                        {
                            directoryProperty.IsSystemOnly = true;
                        }
                    }
                }
            }
        }
        static void Main(string[] args)
        {
            DirectorySearcher          deSearch   = new DirectorySearcher();
            ActiveDirectorySchema      currSchema = ActiveDirectorySchema.GetCurrentSchema();
            ActiveDirectorySchemaClass collection = currSchema.FindClass("user");
            ReadOnlyActiveDirectorySchemaPropertyCollection properties = collection.GetAllProperties();
            IEnumerator enumerator = properties.GetEnumerator();

            while (enumerator.MoveNext())
            {
                try
                {
                    deSearch.PropertiesToLoad.Add(enumerator.Current.ToString());
                }
                catch (Exception ex)
                {
                    // MessageBox.Show(ex.Message);
                }
            }
        }
Beispiel #3
0
        public List <String> GetAllADUserProperties(string domain) //"dcs.azdcs.gov"
        {
            List <String> properties = new List <String>();

            IPAddress[] ips = Dns.GetHostAddresses(domain).Where(w => w.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).ToArray();
            if (ips.Length > 0)
            {
                DirectoryContext           directoryContext = new DirectoryContext(DirectoryContextType.Forest);//DirectoryContextType.DirectoryServer, ips[0].ToString() + ":389", Username, Password);
                ActiveDirectorySchema      adschema         = ActiveDirectorySchema.GetSchema(directoryContext);
                ActiveDirectorySchemaClass adschemaclass    = adschema.FindClass("User");

                // Read the OptionalProperties & MandatoryProperties
                ReadOnlyActiveDirectorySchemaPropertyCollection propcol = adschemaclass.GetAllProperties();

                foreach (ActiveDirectorySchemaProperty schemaProperty in propcol)
                {
                    properties.Add(schemaProperty.Name.ToLower());
                }
            }

            return(properties);
        }
Beispiel #4
0
        public void buttonRunQuery_Click(object sender, EventArgs e)
        {
            Setup  setup      = new Setup();
            String OldOraHome = Environment.GetEnvironmentVariable("ORACLE_HOME");

            if (!String.IsNullOrEmpty(setup.textBoxOraHome.Text))
            {
                Environment.SetEnvironmentVariable("ORACLE_HOME", setup.textBoxOraHome.Text);
            }
            OracleConnection conn = new OracleConnection(setup.ConnectionStringOracle);

            try
            {
                conn.Open();
                OracleCommand cmd = new OracleCommand();
                cmd.Connection  = conn;
                cmd.CommandText = "SELECT column_name FROM all_tab_columns WHERE upper(table_name) = upper('" +
                                  setup.textBoxOraView.Text + "') ORDER BY column_name ASC";
                cmd.CommandType = CommandType.Text;
                OracleDataReader dr = cmd.ExecuteReader();
                m_Fields.Clear();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        try
                        {
                            m_Fields.Add(dr[0].ToString());
                        }
                        catch
                        {
                        }
                    }
                }

                m_Fields.Add("*BRANCO*");
                m_Fields.Sort();
                dr.Close();
                conn.Dispose();
                dataGridView.Rows.Clear();
                DataGridViewComboBoxColumn column = dataGridView.Columns["CampoOrigem"] as DataGridViewComboBoxColumn;
                if (column != null)
                {
                    column.DataSource = m_Fields;
                }

                List <String> properties = new List <String>();
                properties.Clear();
                IPAddress[] ips =
                    Dns.GetHostAddresses(setup.textBoxLdapServer.Text)
                    .Where(w => w.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    .ToArray();
                if (ips.Length > 0)
                {
                    DirectoryContext directoryContext = new DirectoryContext(DirectoryContextType.DirectoryServer,
                                                                             ips[0].ToString() + ":389", setup.textBoxLdapUsername.Text, setup.textBoxLdapPassword.Text);
                    ActiveDirectorySchema      adschema      = ActiveDirectorySchema.GetSchema(directoryContext);
                    ActiveDirectorySchemaClass adschemaclass = adschema.FindClass("User");

                    // Read the OptionalProperties & MandatoryProperties
                    ReadOnlyActiveDirectorySchemaPropertyCollection propcol = adschemaclass.GetAllProperties();

                    foreach (ActiveDirectorySchemaProperty schemaProperty in propcol)
                    {
                        properties.Add(schemaProperty.Name.ToLower());
                    }
                }
                DataGridViewComboBoxColumn column2 = dataGridView.Columns["CampoDestino"] as DataGridViewComboBoxColumn;
                if (column2 != null)
                {
                    column2.DataSource = properties;
                }

                try
                {
                    FileInfo file = new FileInfo(Path.Combine(Application.StartupPath, "DePara.xml"));
                    if (file.Exists)
                    {
                        Dictionary <Int32, Dictionary <String, String> > data =
                            new Dictionary <int, Dictionary <string, string> >();
                        XmlReader xr = XmlReader.Create(file.FullName);
                        xr.MoveToContent();
                        while (xr.Read())
                        {
                            Dictionary <String, String> attributes = new Dictionary <string, string>();
                            while (xr.MoveToNextAttribute())
                            {
                                if (xr.Name != "CampoOrigem" && xr.Name != "CampoDestino")
                                {
                                    continue;
                                }
                                attributes.Add(xr.Name, xr.Value);
                            }
                            if (attributes.Count > 0)
                            {
                                data.Add(data.Count, attributes);
                            }
                        }
                        xr.Close();
                        foreach (KeyValuePair <Int32, Dictionary <String, String> > kp in data)
                        {
                            dataGridView.Rows.Add(kp.Value["CampoOrigem"], kp.Value["CampoDestino"]);
                        }
                    }
                }
                catch
                {
                }
            }
            catch (Exception exc)
            {
                try
                {
                    MessageBox.Show(exc.Message, "Erro ao conectar com o BD", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch
                {
                }
            }
            if (!String.IsNullOrEmpty(setup.textBoxOraHome.Text))
            {
                Environment.SetEnvironmentVariable("ORACLE_HOME", OldOraHome);
            }
        }