示例#1
0
        public void TestSchema()
        {
            using (ActiveDirectorySchema schema = ActiveDirectorySchema.GetSchema(ActiveDirectoryContext))
            {
                Assert.True(schema.FindAllClasses().Contains(ActiveDirectorySchemaClass.FindByName(ActiveDirectoryContext, "user")));
                Assert.True(schema.FindAllClasses().Contains(ActiveDirectorySchemaClass.FindByName(ActiveDirectoryContext, "samDomainBase")));
                Assert.NotNull(schema.FindAllDefunctClasses());
                Assert.NotNull(schema.FindAllDefunctProperties());
                Assert.True(schema.FindAllProperties(PropertyTypes.Indexed).Contains(ActiveDirectorySchemaProperty.FindByName(ActiveDirectoryContext, "ou")));
                Assert.True(schema.FindAllProperties().Contains(ActiveDirectorySchemaProperty.FindByName(ActiveDirectoryContext, "cn")));
                Assert.Equal("person", schema.FindClass("person").Name);
                Assert.Equal("cn", schema.FindProperty("cn").Name);

                using (DirectoryEntry de = schema.GetDirectoryEntry())
                {
                    Assert.True("CN=Schema".Equals(de.Name, StringComparison.OrdinalIgnoreCase));
                }
            }
        }
        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);
                }
            }
        }
示例#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);
        }
        public void GetSchemaViaSDSAD()
        {
            ActiveDirectorySchemaClass schema = ActiveDirectorySchemaClass.FindByName(
                new DirectoryContext(
                    DirectoryContextType.DirectoryServer,
                    TestUtils.Settings.Server), //note that SDS.AD doesn't like 'localhost'
                "organization"
                );

            Console.WriteLine("Possible Inferiors");
            Console.WriteLine("=============");
            foreach (ActiveDirectorySchemaClass adsc in
                     schema.PossibleInferiors)
            {
                Console.WriteLine("{0}", adsc.Name);
            }
            Console.WriteLine("=============");

            foreach (ActiveDirectorySchemaProperty prop in schema.MandatoryProperties)
            {
                Console.WriteLine("=============");
                Console.WriteLine("Attribute {0}", prop.Name);
                Console.WriteLine("Syntax: {0}", prop.Syntax);
                Console.WriteLine("Indexed: {0}", prop.IsIndexed);
                Console.WriteLine("In GC: {0}", prop.IsInGlobalCatalog);
            }

            foreach (ActiveDirectorySchemaProperty prop in schema.OptionalProperties)
            {
                Console.WriteLine("=============");
                Console.WriteLine("Attribute {0}", prop.Name);
                Console.WriteLine("Syntax: {0}", prop.Syntax);
                Console.WriteLine("Indexed: {0}", prop.IsIndexed);
                Console.WriteLine("In GC: {0}", prop.IsInGlobalCatalog);
            }
        }
 public int IndexOf(ActiveDirectorySchemaClass schemaClass)
 {
 }
 public void CopyTo(ActiveDirectorySchemaClass[] classes, int index)
 {
 }
 // Methods
 public bool Contains(ActiveDirectorySchemaClass schemaClass)
 {
 }
	public void Insert(int index, ActiveDirectorySchemaClass schemaClass) {}
	public void Remove(ActiveDirectorySchemaClass schemaClass) {}
示例#10
0
 // Methods
 public bool Contains(ActiveDirectorySchemaClass schemaClass)
 {
 }
示例#11
0
        public static void CreateNewClass()
        {
            // specify a common name
            string newClassCommonName = "new-Class";

            // specify an lDAPDisplayName
            string newClassLdapDisplayName = "newClass";

            // specify an OID value. The root name was generated by oidgen.exe
            string newClassOid =
                "1.2.840.113556.1.5.7000.111.28688.28684.8.240397.1734810.1181742.544876.1";

            string subClassOf = "top";

            string possibleSuperior = "organizationalUnit";

            // add an optional attribute to the new schema class object
            // This example adds the new attribute created in the CreateNewAttribute method
            string newClassOptionalAttribute = newAttributeLdapDisplayName;


            // create a new class object
            ActiveDirectorySchemaClass newClass =
                new ActiveDirectorySchemaClass(
                    adamContext,
                    newClassLdapDisplayName);

            // set the attribute values for this schema class object
            newClass.CommonName = newClassCommonName;
            newClass.Oid        = newClassOid;

            newClass.Type = SchemaClassType.Structural;

            // assign the parent class
            newClass.SubClassOf = ActiveDirectorySchemaClass.FindByName(adamContext,
                                                                        subClassOf);

            // add the previously created attribute as an optional attribute
            newClass.OptionalProperties.Add(
                ActiveDirectorySchemaProperty.FindByName(adamContext,
                                                         newClassOptionalAttribute));

            //add an OU as a possible superior so that this class can be
            //instantiated in an OU
            newClass.PossibleSuperiors.Add(
                ActiveDirectorySchemaClass.FindByName(adamContext,
                                                      possibleSuperior));

            // save the new class to the schema
            try
            {
                newClass.Save();
            }

            catch (ActiveDirectoryObjectExistsException e)
            {
                // an schema object by this name already exists in the schema
                Console.WriteLine("The schema object {0} was not created. {0}",
                                  newClassLdapDisplayName, e.Message);
                return;
            }

            catch (ActiveDirectoryOperationException e)
            {
                // a call to the underlying directory was rejected
                Console.WriteLine("The schema object {0} was not created. {0}",
                                  newClassLdapDisplayName, e.Message);
                return;
            }

            Console.WriteLine("Class \"{0}\" created successfully.",
                              newClassLdapDisplayName);
        }
示例#12
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);
            }
        }
 // Methods
 public int Add(ActiveDirectorySchemaClass schemaClass)
 {
 }
 public void Insert(int index, ActiveDirectorySchemaClass schemaClass)
 {
 }
 public void Remove(ActiveDirectorySchemaClass schemaClass)
 {
 }
	// Methods
	public int Add(ActiveDirectorySchemaClass schemaClass) {}
	public void AddRange(ActiveDirectorySchemaClass[] schemaClasses) {}
示例#18
0
 public int IndexOf(ActiveDirectorySchemaClass schemaClass)
 {
 }
示例#19
0
        private static void createSchemaClass(object domainDCs)
        {
            try
            {
                if (!DirectoryEntry.Exists("LDAP://CN=nmlsNetworkDriveClass,cn=Schema,cn=Configuration," + domainDCs))
                {
                    DirectoryContext ctx = new DirectoryContext(DirectoryContextType.Forest);

                    ActiveDirectorySchemaClass schemaClass = new ActiveDirectorySchemaClass(ctx, "nmlsNetworkDriveClass");
                    schemaClass.Oid        = "1.2.840.113556.1.8000.2554.61823.22188.26389.18272.44952.1599828.8363415.3.1";
                    schemaClass.SubClassOf = new ActiveDirectorySchemaClass(ctx, "top");
                    schemaClass.OptionalProperties.AddRange(new ActiveDirectorySchemaProperty[] {
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveA"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveB"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveC"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveD"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveE"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveF"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveG"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveH"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveI"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveJ"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveK"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveL"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveM"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveN"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveO"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveP"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveQ"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveR"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveS"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveT"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveU"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveV"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveW"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveX"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveY"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveZ"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelA"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelB"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelC"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelD"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelE"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelF"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelG"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelH"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelI"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelJ"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelK"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelL"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelM"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelN"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelO"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelP"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelQ"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelR"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelS"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelT"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelU"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelV"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelW"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelX"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelY"),
                        ActiveDirectorySchemaProperty.FindByName(ctx, "nmlsNetworkDriveDelZ")
                    });

                    schemaClass.Type = System.DirectoryServices.ActiveDirectory.SchemaClassType.Auxiliary;

                    schemaClass.Save();

                    //schemaClass
                }
                else
                {
                    Console.WriteLine("Class already exists");
                }

                DirectoryEntry userClass = new DirectoryEntry("LDAP://cn=User,cn=Schema,cn=Configuration," + domainDCs);

                if (!userClass.Properties["auxiliaryClass"].Contains("nmlsNetworkDriveClass"))
                {
                    userClass.Properties["auxiliaryClass"].Add("nmlsNetworkDriveClass");
                    userClass.CommitChanges();
                }
                else
                {
                    Console.WriteLine("User class already has auxiliary class nmlsNetworkDriveClass");
                }


                // Add NMLS class also OU objects.

                DirectoryEntry ouClass = new DirectoryEntry("LDAP://cn=Organizational-Unit,cn=Schema,cn=Configuration," + domainDCs);
                if (!ouClass.Properties["auxiliaryClass"].Contains("nmlsNetworkDriveClass"))
                {
                    ouClass.Properties["auxiliaryClass"].Add("nmlsNetworkDriveClass");
                    ouClass.CommitChanges();
                }
                else
                {
                    Console.WriteLine("OU class already has auxiliary class nmlsNetworkDriveClass");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }