/// <summary>
 /// Get superclasslist according to DC and classId.
 /// </summary>
 /// <param name="dc">A controller of Model Domain.</param>
 /// <param name="classId">An unique ID of a class.</param>
 /// <returns>Returns a list of super classes.</returns>
 public static Sequence <string> GetSuperClassList(ModelDomainController dc, string classId)
 {
     if (classId == StandardNames.topGovernsId || classId == StandardNames.top)
     {
         return(new Sequence <string>().Add(classId));
     }
     else
     {
         ModelObject classObject = dc.GetClass(classId);
         return(GetSuperClassList(dc, (string)classObject[StandardNames.subClassOf]).Add(classId));
     }
 }
 static List <string> GetSuperClassChain(ModelDomainController dc, string classId)
 {
     if (classId == StandardNames.topGovernsId || classId == StandardNames.top)
     {
         return(new List <string>());
     }
     else
     {
         ModelObject classObject    = dc.GetClass(classId);
         var         superClassList = GetSuperClassChain(dc, (string)classObject[StandardNames.subClassOf]);
         superClassList.Add(classId);
         return(superClassList);
     }
 }
        /// <summary>
        /// Constructs a new replica.
        /// </summary>
        /// <param name="dc">Domain controller</param>
        /// <param name="kind">Replica kind.</param>
        /// <param name="dn">Distinguished name.</param>
        /// <param name="partial">Is it partial replica</param>
        public Replica(ModelDomainController dc, ReplicaKind kind, string dn, bool partial)
        {
            this.dc      = dc;
            this.kind    = kind;
            this.dn      = dn;
            this.partial = partial;
            this.root    = new ModelObject();
            root.dc      = dc;
            AttributeContext objectClassContext =
                new AttributeContext(
                    null,
                    StandardNames.objectClass,
                    Syntax.StringObjectIdentifier,
                    false,
                    null);
            AttributeContext cnContext =
                new AttributeContext(
                    null,
                    StandardNames.cn,
                    Syntax.StringUnicode);

            switch (kind)
            {
            case ReplicaKind.Domain:
                root[StandardNames.objectClass] =
                    objectClassContext.Parse(StandardNames.top + ";" + StandardNames.domainDNS);
                break;

            case ReplicaKind.Application:
                root[StandardNames.objectClass] =
                    objectClassContext.Parse(StandardNames.top + ";" + StandardNames.domainDNS);
                break;

            case ReplicaKind.Configuration:
                root[StandardNames.cn]          = cnContext.Parse("Configuration");
                root[StandardNames.objectClass] =
                    objectClassContext.Parse(StandardNames.top + ";" + StandardNames.configuration);
                break;

            case ReplicaKind.Schema:
                root[StandardNames.cn]          = cnContext.Parse("Schema");
                root[StandardNames.objectClass] =
                    objectClassContext.Parse(StandardNames.top + ";" + StandardNames.dMD);
                break;
            }
        }
        public static List <string> GetMsdsAuxiliaryClasses(string ldapDisplayName, ModelDomainController dcModel)
        {
            List <string> testMsdsAuxiliaryClasses = new List <string>();
            List <string> objectClassValues        = new List <string>();
            ModelObject   reqEntry = null;

            //Get the model object corresponding to ldapDisplayName passed to this method.
            while (reqEntry == null)
            {
                dcModel.TryGetClass(ldapDisplayName, out reqEntry);
            }

            //Get object class of this entry.
            foreach (string entry in reqEntry.attributes["objectclass"].UnderlyingValues)
            {
                objectClassValues.Add(entry);
            }

            //First condition, take all entries in SchemaNC.
            IDictionary <string, ModelObject> allSchemaEntries = dcModel.schemaReplica.root.childs;

            //All Conditions
            foreach (KeyValuePair <string, ModelObject> schemaEntry in allSchemaEntries)
            {
                ModelObject entry = schemaEntry.Value;

                if (objectClassValues.Contains(entry.attributes["ldapdisplayname"].UnderlyingValues.ElementAt(0).ToString().ToLower()))
                {
                    ConstructedAttributeHelper helper = new ConstructedAttributeHelper();
                    ModelObject tempModelObject       = null;
                    dcModel.TryGetClass(objectClassValues.Last(), out tempModelObject);
                    List <string> tempSuperClasses = helper.GetSuperClassesList(tempModelObject, true, dcModel);
                    tempSuperClasses.Add(entry.attributes["ldapdisplayname"].UnderlyingValues.ElementAt(0).ToString());

                    if (!tempSuperClasses.Contains(entry.attributes["ldapdisplayname"].UnderlyingValues.ElementAt(0).ToString()))
                    {
                        testMsdsAuxiliaryClasses.Add(entry.attributes["ldapdisplayname"].UnderlyingValues.ElementAt(0).ToString().ToLower());
                    }
                }
            }

            return(testMsdsAuxiliaryClasses);
        }
Beispiel #5
0
        /// <summary>
        /// Finds super class chain of object.
        /// </summary>
        /// <param name="requiredObject">The required object.</param>
        /// <param name="isFirstTime">Whether is it the first time.</param>
        /// <param name="dcModel">The domain controller of model.</param>
        /// <returns>Returns a list of super classes.</returns>
        public List <string> GetSuperClassesList(ModelObject requiredObject, bool isFirstTime, ModelDomainController dcModel)
        {
            string tempCNName = (string)requiredObject.attributes[StandardNames.cn].UnderlyingValues.ElementAt(0);

            //If it is first time, we have to initialize this superClassList.
            if (isFirstTime)
            {
                SuperClassList = new List <string>();
            }
            //This is not first time, so add this obj name in superClassList.
            else
            {
                SuperClassList.Add(tempCNName);
            }
            //If this obj name is top, return new empty list.
            if (tempCNName.ToLower().Equals("top"))
            {
                return(new List <string>());
            }
            else
            {
                //If this obj has some more subClassValue, call again this method with its subClassOf value.
                if (requiredObject.attributes.Keys.Contains("subclassof"))
                {
                    //Get the subClassOf value of this obj from model and server.
                    string subClassOfValue = (string)requiredObject.attributes["subclassof"].UnderlyingValues.ElementAt(0);
                    subClassOfValue = subClassOfValue.Replace("-", String.Empty).ToLower();
                    ModelObject subClassOfObject = null;

                    dcModel.TryGetClass(subClassOfValue, out subClassOfObject);
                    if (subClassOfObject == null)
                    {
                        subClassOfValue = (string)requiredObject.attributes["subclassof"].UnderlyingValues.ElementAt(0);
                        subClassOfValue = subClassOfValue.ToLower();
                        dcModel.TryGetClass(subClassOfValue, out subClassOfObject);
                    }

                    //Call SuperClasses method with this subClassOfObject.
                    GetSuperClassesList(subClassOfObject, false, dcModel);
                }
            }
            //Finally return this superClassList.
            return(SuperClassList);
        }
Beispiel #6
0
        /// <summary>
        /// Finds possSuperiors of a given object.
        /// </summary>
        /// <param name="requiredObject">The required object.</param>
        /// <param name="dcModel">The domain controller of model.</param>
        /// <returns>Returns a list of poss superior.</returns>
        public List <string> GetPossSuperiorsList(ModelObject requiredObject, ModelDomainController dcModel)
        {
            //DirectoryEntry serverObj = null;
            List <string> superClasses;
            List <string> auxiliaryClasses;

            //Collect all systemPossSuperiors value of this object.
            if (requiredObject.attributes.Keys.Contains("systemposssuperiors"))
            {
                foreach (string element in requiredObject.attributes["systemposssuperiors"].UnderlyingValues)
                {
                    possSuperiorList.Add(element);
                }
            }

            //Collect all possSuperiors value of this object.
            if (requiredObject.attributes.Keys.Contains("posssuperiors"))
            {
                foreach (string element in requiredObject.attributes["posssuperiors"].UnderlyingValues)
                {
                    possSuperiorList.Add(element);
                }
            }

            //Collect this object's super class List.
            superClasses = GetSuperClassesList(requiredObject, true, dcModel);

            //For each super class,
            foreach (string supClass in superClasses)
            {
                //Get the object from server.
                ModelObject supClassOfObject = null;
                string      className        = supClass.Replace("-", String.Empty).ToLower();

                dcModel.TryGetClass(className, out supClassOfObject);
                //Remove the minus sign and retry
                if (supClassOfObject == null)
                {   //Modified to support Windows Server 2012
                    //Only class names in the format of, eg. msds-claimtype, can be found
                    if (className.Contains("msds"))
                    {
                        className = className.Insert(className.IndexOf("msds") + 4, "-");
                    }
                    else if (supClass.Contains("-"))
                    {
                        className = supClass.Remove(supClass.IndexOf('-'), 1);
                    }
                    dcModel.TryGetClass(className, out supClassOfObject);
                }

                //Call PossSuperiors method with this super class object.
                GetPossSuperiorsList(supClassOfObject, dcModel);
            }

            //Collect auxiliary classes of this object.
            auxiliaryClasses = GetAuxiliaryClassesList(requiredObject, true, dcModel);

            //For each auxiliary class,
            foreach (string auxClass in auxiliaryClasses)
            {
                //Get the object from server.
                ModelObject auxClassOfObject;
                dcModel.TryGetClass(auxClass, out auxClassOfObject);

                //Call PossSuperiors method with this auxiliary class object.
                GetPossSuperiorsList(auxClassOfObject, dcModel);
            }
            //Finally return the possSuperior list.
            return(possSuperiorList);
        }
Beispiel #7
0
        /// <summary>
        /// Finds all Auxiliary classes.
        /// </summary>
        /// <param name="requiredObject">The required object.</param>
        /// <param name="isFirstTime">Whether is it the first time.</param>
        /// <param name="dcModel">The domain controller of model.</param>
        /// <returns>Returns a list of auxiliary classes.</returns>
        public List <string> GetAuxiliaryClassesList(ModelObject requiredObject, bool isFirstTime, ModelDomainController dcModel)
        {
            List <string> superClasses;

            //If it is first time, initialize all variables.
            if (isFirstTime)
            {
                auxiliaryClassLsit  = new List <string>();
                seenAuxiliarClasses = new List <string>();
            }
            //Collect all systemauxiliaryclass of this object.
            if (requiredObject.attributes.Keys.Contains("systemauxiliaryclass"))
            {
                foreach (string element in requiredObject.attributes["systemauxiliaryclass"].UnderlyingValues)
                {
                    auxiliaryClassLsit.Add(element);
                }
            }
            //Collect all auxiliaryclass of this object.
            if (requiredObject.attributes.Keys.Contains("auxiliaryclass"))
            {
                foreach (string element in requiredObject.attributes["auxiliaryclass"].UnderlyingValues)
                {
                    auxiliaryClassLsit.Add(element);
                }
            }
            //For auxiliary classes,
            if (auxiliaryClassLsit.Count != 0)
            {
                List <string> tempAuxiliaryClassLsit = new List <string>();
                foreach (string element in auxiliaryClassLsit)
                {
                    tempAuxiliaryClassLsit.Add(element);
                }

                //For all auxiliary classes, find out their auxiliaryClass and systemAuxiliaryClass values.
                foreach (string auxClass in tempAuxiliaryClassLsit)
                {
                    //If already we did not find the auxiliary and systemAuxiliary class for this class continue.
                    if (!seenAuxiliarClasses.Contains(auxClass.ToLower()))
                    {
                        //Add this auxClass name in seenAuxiliarClasses.
                        seenAuxiliarClasses.Add(auxClass.ToLower());

                        //Find this object in server.
                        ModelObject auxClassOfObject;
                        string      className = auxClass.Replace("-", String.Empty).ToLower();
                        if (dcModel.TryGetClass(className, out auxClassOfObject))
                        {
                            //Call AuxiliaryClasses method for this auxClass.
                            GetAuxiliaryClassesList(auxClassOfObject, false, dcModel);
                        }
                    }
                }
            }

            //Find superClasses of this object.
            superClasses = GetSuperClassesList(requiredObject, true, dcModel);
            //For each super class,
            foreach (string supClass in superClasses)
            {
                //If already we did not find the auxiliary and systemAuxiliary class for this class continue.
                if (!seenAuxiliarClasses.Contains(supClass.ToLower()))
                {
                    //Add this supClass name in seenAuxiliarClasses.
                    seenAuxiliarClasses.Add(supClass.ToLower());
                    //Find this object from server.
                    ModelObject supClassOfObject = null;
                    string      className        = supClass.Replace("-", String.Empty).ToLower();

                    dcModel.TryGetClass(className, out supClassOfObject);
                    //Remove the minus sign and retry
                    if (supClassOfObject == null)
                    {   //Modified to support Windows Server 2012
                        //Only class names in the format of, eg. msds-claimtype, can be found
                        if (className.Contains("msds"))
                        {
                            className = className.Insert(className.IndexOf("msds") + 4, "-");
                        }
                        else if (supClass.Contains("-"))
                        {
                            className = supClass.Remove(supClass.IndexOf('-'), 1);
                        }
                        dcModel.TryGetClass(className, out supClassOfObject);
                    }

                    //Call AuxiliaryClasses method for this supClass object.
                    GetAuxiliaryClassesList(supClassOfObject, false, dcModel);
                }
            }
            //Finally return auxiliary class list.
            return(auxiliaryClassLsit);
        }
        public static void ClassInitialize(TestContext testContext)
        {
            TestClassBase.Initialize(testContext);

            // Initializing the ITestSite object
            if (null == DataSchemaSite)
            {
                DataSchemaSite = TestClassBase.BaseTestSite;
            }
            adAdapter = new ADDataSchemaAdapter();
            adAdapter.Initialize(DataSchemaSite);

            //Model for AD/DS
            dcModel = new ModelDomainController(adAdapter.rootDomainDN, null);

            //Protocol Short Name.
            DataSchemaSite.DefaultProtocolDocShortName = "MS-ADTS-Schema";

            //Specifying the windows version
            ServerVersion serverVersion = (ServerVersion)adAdapter.PDCOSVersion;

            if (serverVersion == ServerVersion.Win2003)
            {
                serverOS = OSVersion.WinSvr2003;
            }
            else if (serverVersion == ServerVersion.Win2008)
            {
                serverOS = OSVersion.WinSvr2008;
            }
            else if (serverVersion == ServerVersion.Win2008R2)
            {
                serverOS = OSVersion.WinSvr2008R2;
            }
            else if (serverVersion == ServerVersion.Win2012)
            {
                serverOS = OSVersion.WinSvr2012;
            }
            else if (serverVersion == ServerVersion.Win2012R2)
            {
                serverOS = OSVersion.WinSvr2012R2;
            }
            else if (serverVersion == ServerVersion.Win2016)
            {
                serverOS = OSVersion.Win2016;
            }
            else if (serverVersion == ServerVersion.Winv1803)
            {
                serverOS = OSVersion.Winv1803;
            }
            else
            {
                serverOS = OSVersion.OtherOS;
            }

            //Storing the XML paths.
            string[] tdSources;
            if (serverVersion <= ServerVersion.Win2012R2)
            {
                tdSources = adAdapter.TDXmlPath.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            }
            else
            {
                tdSources = adAdapter.OpenXmlPath.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            }

            Map <string, string> rootDomainDNSubs = new Map <string, string>().Add("<RootDomainDN>", adAdapter.rootDomainDN);

            DSSchemaLoadResult = dcModel.LoadSchema(
                SchemaReader.ReadSchema(
                    tdSources,
                    null,
                    true,
                    serverOS),
                rootDomainDNSubs,
                serverOS);

            if (adAdapter.RunLDSTestCases)
            {
                string[] ldsTdSource;
                if (serverVersion <= ServerVersion.Win2012R2)
                {
                    ldsTdSource = adAdapter.LdsTDXmlPath.Split(',');
                }
                else
                {
                    ldsTdSource = adAdapter.LdsOpenXmlPath.Split(',');
                }
                //Model for AD/LDS
                adamModel = new ModelDomainController(adAdapter.LDSRootObjectName, null);
                Map <string, string> adamRootDomainDNSubs = new Map <string, string>().Add("<RootDomainDN>", adAdapter.LDSRootObjectName);

                LDSSchemaLoadResult = adamModel.LoadSchema(
                    SchemaReader.ReadSchema(
                        ldsTdSource,
                        null,
                        true,
                        serverOS),
                    adamRootDomainDNSubs,
                    serverOS);
            }
        }
        /// <summary>
        /// This method is used to get the possible inferiors of the particula object.
        /// </summary>
        /// <param name="ldapDisplayName">LDAP display name of the particular object.</param>
        /// <param name="dcModel">System Model object</param>
        /// <returns>On success it returns the List of allowed attributes, else null.</returns>
        public static List <string> GetPossibleInferiors(string ldapDisplayName, ModelDomainController dcModel)
        {
            List <string> testPossInferiors = new List <string>();
            ModelObject   reqEntry          = null;

            //Get the model object corresponding to ldapDisplayName passed to this method.
            while (reqEntry == null)
            {
                dcModel.TryGetClass(ldapDisplayName, out reqEntry);
            }


            //First condition, take all entries in SchemaNC.
            IDictionary <string, ModelObject> allSchemaEntries = dcModel.schemaReplica.root.childs;

            foreach (KeyValuePair <string, ModelObject> schemaEntry in allSchemaEntries)
            {
                ModelObject entry = schemaEntry.Value;
                testPossInferiors.Add((string)entry.attributes["ldapdisplayname"].UnderlyingValues.ElementAt(0));
            }

            //Get required entry's class name.
            string className = (string)reqEntry.attributes["ldapdisplayname"].UnderlyingValues.ElementAt(0);

            //All Conditions
            foreach (KeyValuePair <string, ModelObject> schemaEntry in allSchemaEntries)
            {
                ModelObject entry        = schemaEntry.Value;
                string      tempLdapName = (string)entry.attributes["ldapdisplayname"].UnderlyingValues.ElementAt(0);

                #region 2. objectClass value must be classSchema.

                object[] objectClassValues   = entry.attributes["objectclass"].UnderlyingValues.ToArray();
                string   structuralClassName = (string)objectClassValues[objectClassValues.Length - 1];

                if (!structuralClassName.ToLower().Equals("classschema"))
                {
                    if (testPossInferiors.Contains(tempLdapName))
                    {
                        testPossInferiors.Remove(tempLdapName);
                        continue;
                    }
                }
                #endregion

                #region 3. entry must not systemOnly.

                if (entry.attributes.Keys.Contains("systemonly"))
                {
                    bool isSystemOnly = (bool)entry.attributes["systemonly"].UnderlyingValues.ElementAt(0);

                    if (isSystemOnly)
                    {
                        if (testPossInferiors.Contains(tempLdapName))
                        {
                            testPossInferiors.Remove(tempLdapName);
                            continue;
                        }
                    }
                }

                #endregion

                #region 4. objectClassCategory must not be 2 or 3.
                if (entry.attributes.Keys.Contains("objectclasscategory"))
                {
                    int value = (int)entry.attributes["objectclasscategory"].UnderlyingValues.ElementAt(0);

                    if (value == 2 || value == 3)
                    {
                        if (testPossInferiors.Contains(tempLdapName))
                        {
                            testPossInferiors.Remove(tempLdapName);
                            continue;
                        }
                    }
                }

                #endregion

                #region 5. entry's class name must be in POSSSUPERIORS(allSchemaNCObjects).

                if (entry.attributes.Keys.Contains("governsid"))
                {
                    ConstructedAttributeHelper helper = new ConstructedAttributeHelper();
                    helper.possSuperiorList = new List <string>();
                    //helper.AuxiliaryClasses(entry, true, dcModel);
                    List <string> possSuperiors = helper.GetPossSuperiorsList(entry, dcModel);

                    if (possSuperiors.Contains(className.ToLower()))
                    {
                        continue;
                    }
                    else
                    {
                        if (testPossInferiors.Contains(tempLdapName))
                        {
                            testPossInferiors.Remove(tempLdapName);
                        }
                        continue;
                    }
                }
                #endregion
            }
            return(testPossInferiors);
        }
        /// <summary>
        /// This method is used to get allowed attributes of a particular object.
        /// </summary>
        /// <param name="ldapDisplayName">LDAP display name of the particular object.</param>
        /// <param name="dcModel">System Model object</param>
        /// <returns>On success it returns the List of allowed attributes, else null.</returns>
        public static List <string> GetAllowedAttributes(string ldapDisplayName, ModelDomainController dcModel)
        {
            List <string>      testAllowedAttributes     = new List <string>();
            List <ModelObject> reqEntryObjectClassValues = new List <ModelObject>();
            ModelObject        reqEntry = null;

            //Get the model object corresponding to ldapDisplayName passed to this method.
            while (reqEntry == null)
            {
                dcModel.TryGetClass(ldapDisplayName, out reqEntry);
                if (reqEntry == null)
                {
                    dcModel.TryGetAttribute(ldapDisplayName, out reqEntry);
                }
            }

            if (reqEntry.attributes.Keys.Contains("objectclass"))
            {
                foreach (string value in reqEntry.attributes["objectclass"].UnderlyingValues)
                {
                    ModelObject tempObject = null;

                    while (tempObject == null)
                    {
                        dcModel.TryGetClass(value, out tempObject);
                    }
                    reqEntryObjectClassValues.Add(tempObject);
                }
            }

            //First condition, take all entries in SchemaNC.
            IDictionary <string, ModelObject> allSchemaEntries = dcModel.schemaReplica.root.childs;

            foreach (KeyValuePair <string, ModelObject> schemaEntry in allSchemaEntries)
            {
                ModelObject entry = schemaEntry.Value;

                testAllowedAttributes.Add((string)entry.attributes["ldapdisplayname"].UnderlyingValues.ElementAt(0));
            }



            //All Conditions
            foreach (KeyValuePair <string, ModelObject> schemaEntry in allSchemaEntries)
            {
                ModelObject entry        = schemaEntry.Value;
                string      tempLdapName = (string)entry.attributes["ldapdisplayname"].UnderlyingValues.ElementAt(0);

                #region 2. objectClass value must be attributeSchema.

                object[] objectClassValues   = entry.attributes["objectclass"].UnderlyingValues.ToArray();
                string   structuralClassName = (string)objectClassValues[objectClassValues.Length - 1];

                if (!structuralClassName.ToLower().Equals("attributeschema"))
                {
                    if (testAllowedAttributes.Contains(tempLdapName))
                    {
                        testAllowedAttributes.Remove(tempLdapName);
                        continue;
                    }
                }
                #endregion

                #region 3. Link id is even or it should not be present

                #endregion

                #region 4. SystemFlag bit 0X4 should not be set.

                #endregion

                #region 5. there exists C in TO!objectClass such that O is in CLASSATTS(C)).

                ConstructedAttributeHelper helper = new ConstructedAttributeHelper();
                bool isExist = true;

                foreach (ModelObject classObj in reqEntryObjectClassValues)
                {
                    helper.classAttributesList = new List <string>();
                    List <string> attributeList = helper.ClassAttributes(classObj, dcModel);
                    if (attributeList.Contains(tempLdapName.ToLower()))
                    {
                        isExist = true;
                        break;
                    }
                    else
                    {
                        isExist = false;
                    }
                }
                if (!isExist && testAllowedAttributes.Contains(tempLdapName))
                {
                    testAllowedAttributes.Remove(tempLdapName);
                }

                #endregion
            }

            return(testAllowedAttributes);
        }