Ejemplo n.º 1
0
        public static void CreateNewClass()
        {
            // create a new class object
            ActiveDirectorySchemaClass newClass =
                new ActiveDirectorySchemaClass(
                    context,
                    newClassLdapDisplayName);

            // set the properties for this schema class
            newClass.CommonName = newClassCommonName;
            newClass.Oid        = newClassOid;
            newClass.SubClassOf = ActiveDirectorySchemaClass.FindByName(
                context,
                newClassSubClassOf);
            newClass.Type = SchemaClassType.Structural;
            // adding the previously created property as an optional property
            newClass.OptionalProperties.Add(
                ActiveDirectorySchemaProperty.FindByName(
                    context,
                    newClassOptionalProperty));

            // save the new class to the backend store
            try
            {
                newClass.Save();
            }
            catch (ActiveDirectoryObjectExistsException)
            {
                // a class by this name already exists
                Console.WriteLine("FAILED to created new class.");
                return;
            }
            Console.WriteLine("Class \"{0}\" created successfully.",
                              newClassLdapDisplayName);
        }
Ejemplo n.º 2
0
        public void TestSchemaClass()
        {
            using (ActiveDirectorySchemaClass orgClass = ActiveDirectorySchemaClass.FindByName(ActiveDirectoryContext, "organization"))
            {
                Assert.Equal("organization", orgClass.Name);
                Assert.Equal("Organization", orgClass.CommonName);
                Assert.Equal("2.5.6.4", orgClass.Oid);
                Assert.Equal("bf967aa3-0de6-11d0-a285-00aa003049e2", orgClass.SchemaGuid.ToString());
                Assert.Equal("top", orgClass.SubClassOf.Name);
                Assert.NotNull(orgClass.DefaultObjectSecurityDescriptor);
                string s = orgClass.Description; // it can be null
                Assert.False(orgClass.IsDefunct);

                Assert.True(orgClass.AuxiliaryClasses.Contains(ActiveDirectorySchemaClass.FindByName(ActiveDirectoryContext, "samDomainBase")));
                Assert.True(orgClass.PossibleInferiors.Contains(ActiveDirectorySchemaClass.FindByName(ActiveDirectoryContext, "user")));

                ActiveDirectorySchemaClass country = ActiveDirectorySchemaClass.FindByName(ActiveDirectoryContext, "country");
                Assert.True(orgClass.PossibleSuperiors.Contains(country));
                int index = orgClass.PossibleSuperiors.IndexOf(country);
                Assert.Equal(country.Name, orgClass.PossibleSuperiors[index].Name);

                Assert.True(orgClass.MandatoryProperties.Contains(ActiveDirectorySchemaProperty.FindByName(ActiveDirectoryContext, "ntSecurityDescriptor")));
                Assert.True(orgClass.OptionalProperties.Contains(ActiveDirectorySchemaProperty.FindByName(ActiveDirectoryContext, "description")));
                Assert.True(orgClass.MandatoryProperties.Contains(ActiveDirectorySchemaProperty.FindByName(ActiveDirectoryContext, "objectClass")));

                using (DirectoryEntry de = orgClass.GetDirectoryEntry())
                {
                    Assert.True("CN=Organization".Equals(de.Name, StringComparison.OrdinalIgnoreCase));
                }
            }
        }
Ejemplo n.º 3
0
        public static void GetSchemaClassData(string className)
        {
            Console.WriteLine("<--ADAM SCHEMA CLASS-->\n");

            ActiveDirectorySchemaClass schemaClass;

            try
            {
                // bind to an ADAM schema class object
                schemaClass = ActiveDirectorySchemaClass.FindByName(adamContext,
                                                                    className);
            }
            catch (ArgumentException e)
            {
                // this exception could be thrown if the current context
                // is not associated to an instance of ADAM
                Console.WriteLine(e.Message);
                return;
            }
            catch (ActiveDirectoryObjectNotFoundException)
            {
                Console.WriteLine("Schema class \"{0}\" could not be found", className);
                return;
            }

            Console.WriteLine("Name: {0}", schemaClass.Name);
            Console.WriteLine("Oid: {0}", schemaClass.Oid);
            Console.WriteLine("Description: {0}", schemaClass.Description);
            Console.WriteLine("SchemaGuid: {0}", schemaClass.SchemaGuid);
            Console.WriteLine("\nMandatoryProperties:");

            foreach (ActiveDirectorySchemaProperty schemaProperty in
                     schemaClass.MandatoryProperties)
            {
                Console.WriteLine(schemaProperty);
            }

            Console.WriteLine("\nOptionalProperties:");
            foreach (ActiveDirectorySchemaProperty schemaProperty in
                     schemaClass.OptionalProperties)
            {
                Console.WriteLine(schemaProperty);
            }

            Console.WriteLine("\nPossible Superiors:");
            foreach (ActiveDirectorySchemaClass supClass in
                     schemaClass.PossibleSuperiors)
            {
                Console.WriteLine(supClass);
            }
            Console.WriteLine("\nSubClassOf: {0}", schemaClass.SubClassOf);
        }
Ejemplo n.º 4
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;
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public static void SchemaClassSample()
        {
            Console.WriteLine();
            Console.WriteLine("<---------SCHEMA CLASS Sample---------->\n");

            // Find the schema class in the current forest
            // and print it's properties

            ActiveDirectorySchemaClass schemaClass;

            try
            {
                schemaClass = ActiveDirectorySchemaClass.FindByName(context,
                                                                    className);
            }
            catch (ArgumentException e)
            {
                // this exception could be thrown if the current context
                // is not associated any domain/forest
                Console.WriteLine(e.Message);
                return;
            }
            catch (ActiveDirectoryObjectNotFoundException)
            {
                Console.WriteLine("Schema class \"{0}\" could not be found");
                return;
            }

            Console.WriteLine("Name: {0}", schemaClass.Name);
            Console.WriteLine("Oid: {0}", schemaClass.Oid);
            Console.WriteLine("Description: {0}", schemaClass.Description);
            Console.WriteLine();
            Console.WriteLine("MandatoryProperties:");
            foreach (ActiveDirectorySchemaProperty schemaProperty in
                     schemaClass.MandatoryProperties)
            {
                Console.WriteLine(schemaProperty);
            }
            Console.WriteLine();
            Console.WriteLine("Possible Superiors:");
            foreach (ActiveDirectorySchemaClass supClass in
                     schemaClass.PossibleSuperiors)
            {
                Console.WriteLine(supClass);
            }
            Console.WriteLine();
            Console.WriteLine("SubClassOf: {0}", schemaClass.SubClassOf);
            Console.WriteLine("SchemaGuid: {0}", schemaClass.SchemaGuid);
        }
        public static void GetSchemaClassData(string className)
        {
            Console.WriteLine("<--SCHEMA CLASS INFORMATION-->\n");

            // get a forest context
            DirectoryContext context = new DirectoryContext(
                DirectoryContextType.Forest);

            ActiveDirectorySchemaClass schemaClass;

            try
            {
                // bind to a class schema object
                schemaClass = ActiveDirectorySchemaClass.FindByName(context,
                                                                    className);
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
                return;
            }
            catch (ActiveDirectoryObjectNotFoundException)
            {
                Console.WriteLine("Schema class \"{0}\" could not be found", className);
                return;
            }

            Console.WriteLine("Name: {0}", schemaClass.Name);
            Console.WriteLine("Oid: {0}", schemaClass.Oid);
            Console.WriteLine("Description: {0}", schemaClass.Description);
            Console.WriteLine("\nMandatoryProperties:");

            foreach (ActiveDirectorySchemaProperty schemaProperty in
                     schemaClass.MandatoryProperties)
            {
                Console.WriteLine(schemaProperty);
            }

            Console.WriteLine("\nPossible Superiors:");
            foreach (ActiveDirectorySchemaClass supClass in
                     schemaClass.PossibleSuperiors)
            {
                Console.WriteLine(supClass);
            }

            Console.WriteLine("\nSubClassOf: {0}", schemaClass.SubClassOf);
            Console.WriteLine("SchemaGuid: {0}", schemaClass.SchemaGuid);
        }
Ejemplo n.º 7
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));
                }
            }
        }
        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);
            }
        }
Ejemplo n.º 9
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);
        }