/// <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); }
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); }
/// <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); }
/// <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); }
/// <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); }