Exemplo n.º 1
0
        private static bool VerifyAppliesToClasses(ADObject directoryObj, StringBuilder errorBuffer, CmdletSessionInfo cmdletSessionInfo)
        {
            bool flag = false;

            if (directoryObj.Contains("msDS-ClaimTypeAppliesToClass"))
            {
                ADSchemaUtil aDSchemaUtil = new ADSchemaUtil(cmdletSessionInfo.ADSessionInfo);
                string[]     valueList    = directoryObj["msDS-ClaimTypeAppliesToClass"].ValueList as string[];
                string[]     strArrays    = valueList;
                for (int i = 0; i < (int)strArrays.Length; i++)
                {
                    string           str = strArrays[i];
                    HashSet <string> allParentClassesForSchemaClassDN = aDSchemaUtil.GetAllParentClassesForSchemaClassDN(str);
                    allParentClassesForSchemaClassDN.IntersectWith(ADClaimTypeFactory <T> .ValidAppliesToClasses);
                    if (allParentClassesForSchemaClassDN.Count == 0)
                    {
                        flag = true;
                        object[] objArray = new object[1];
                        objArray[0] = str;
                        errorBuffer.AppendLine(string.Format(CultureInfo.CurrentCulture, StringResources.SPCTInvalidAppliesToClassWarning, objArray));
                    }
                }
                if (directoryObj.Contains("msDS-ClaimAttributeSource"))
                {
                    string value = directoryObj["msDS-ClaimAttributeSource"].Value as string;
                    ADSchemaObjectFactory <ADSchemaObject> aDSchemaObjectFactory = new ADSchemaObjectFactory <ADSchemaObject>();
                    aDSchemaObjectFactory.SetCmdletSessionInfo(cmdletSessionInfo);
                    ADSchemaObject aDSchemaObject = new ADSchemaObject();
                    aDSchemaObject.Identity = value;
                    string[] strArrays1 = new string[1];
                    strArrays1[0] = "lDAPDisplayName";
                    ADObject extendedObjectFromIdentity = aDSchemaObjectFactory.GetExtendedObjectFromIdentity(aDSchemaObject, cmdletSessionInfo.ADRootDSE.SchemaNamingContext, strArrays1);
                    if (extendedObjectFromIdentity.Contains("lDAPDisplayName"))
                    {
                        string   value1     = extendedObjectFromIdentity["lDAPDisplayName"].Value as string;
                        string[] strArrays2 = valueList;
                        for (int j = 0; j < (int)strArrays2.Length; j++)
                        {
                            string           str1 = strArrays2[j];
                            HashSet <string> attributeListForSchemaClassDN = aDSchemaUtil.GetAttributeListForSchemaClassDN(str1);
                            if (!attributeListForSchemaClassDN.Contains(value1))
                            {
                                flag = true;
                                object[] objArray1 = new object[2];
                                objArray1[0] = str1;
                                objArray1[1] = value1;
                                errorBuffer.AppendLine(string.Format(CultureInfo.CurrentCulture, StringResources.SPCTAttributeNotFoundInSchemaClass, objArray1));
                            }
                        }
                    }
                    else
                    {
                        flag = true;
                        object[] objArray2 = new object[1];
                        objArray2[0] = value;
                        errorBuffer.AppendLine(string.Format(CultureInfo.CurrentCulture, StringResources.SPCTSourceAttributeLdapDisplayNameError, objArray2));
                    }
                }
            }
            return(!flag);
        }
Exemplo n.º 2
0
 internal static void ToDirectoryFromSourceAttributeToDN(string extendedAttribute, string[] directoryAttributes, ADPropertyValueCollection extendedData, ADEntity directoryObj, CmdletSessionInfo cmdletSessionInfo)
 {
     if (extendedData == null || extendedData.Value == null)
     {
         directoryObj.ForceRemove(directoryAttributes[0]);
         return;
     }
     else
     {
         ADSchemaObjectFactory <ADSchemaObject> aDSchemaObjectFactory = new ADSchemaObjectFactory <ADSchemaObject>();
         aDSchemaObjectFactory.SetCmdletSessionInfo(cmdletSessionInfo);
         ADSchemaObject aDSchemaObject = new ADSchemaObject();
         aDSchemaObject.Identity = extendedData.Value;
         ADObject extendedObjectFromIdentity = aDSchemaObjectFactory.GetExtendedObjectFromIdentity(aDSchemaObject, cmdletSessionInfo.ADRootDSE.SchemaNamingContext, ADClaimTypeFactory <T> .SchemaAttributeProperties);
         if (extendedObjectFromIdentity != null)
         {
             if (!extendedObjectFromIdentity.Contains("lDAPDisplayName") || !extendedObjectFromIdentity.Contains("attributeSyntax"))
             {
                 object[] value = new object[1];
                 value[0] = extendedData.Value;
                 throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.SPCTInvalidSourceAttribute, value));
             }
             else
             {
                 string           str    = (string)extendedObjectFromIdentity["lDAPDisplayName"].Value;
                 string           value1 = (string)extendedObjectFromIdentity["attributeSyntax"].Value;
                 HashSet <string> strs   = new HashSet <string>(ADClaimTypeFactory <T> .BlockedAttributes, StringComparer.OrdinalIgnoreCase);
                 if (!strs.Contains(str))
                 {
                     if (!extendedObjectFromIdentity.Contains("systemFlags") || ((int)extendedObjectFromIdentity["systemFlags"].Value & ADClaimTypeFactory <T> .FLAG_ATTR_NOT_REPLICATED) == 0)
                     {
                         if (!extendedObjectFromIdentity.Contains("searchFlags") || ((int)extendedObjectFromIdentity["searchFlags"].Value & ADClaimTypeFactory <T> .RODCFilteredAttribute) == 0)
                         {
                             if (!extendedObjectFromIdentity.Contains("isDefunct") || !(bool)extendedObjectFromIdentity["isDefunct"].Value)
                             {
                                 ADClaimValueType aDClaimValueType = ADClaimValueType.Invalid;
                                 HashSet <string> strs1            = new HashSet <string>(ADClaimTypeFactory <T> .ValidAttributeSyntaxInt, StringComparer.OrdinalIgnoreCase);
                                 HashSet <string> strs2            = new HashSet <string>(ADClaimTypeFactory <T> .ValidAttributeSyntaxString, StringComparer.OrdinalIgnoreCase);
                                 if (!strs2.Contains(value1))
                                 {
                                     if (!strs1.Contains(value1))
                                     {
                                         if (string.Compare(value1, ADClaimTypeFactory <T> .ValidAttributeSyntaxUInt, true, CultureInfo.InvariantCulture) != 0)
                                         {
                                             if (string.Compare(value1, ADClaimTypeFactory <T> .ValidBooleanAttributeSyntax, true, CultureInfo.InvariantCulture) != 0)
                                             {
                                                 throw new ADException(StringResources.SPCTInvalidAttributeSyntax);
                                             }
                                             else
                                             {
                                                 aDClaimValueType = ADClaimValueType.Boolean;
                                             }
                                         }
                                         else
                                         {
                                             aDClaimValueType = ADClaimValueType.UInt64;
                                         }
                                     }
                                     else
                                     {
                                         aDClaimValueType = ADClaimValueType.Int64;
                                     }
                                 }
                                 else
                                 {
                                     aDClaimValueType = ADClaimValueType.String;
                                 }
                                 directoryObj[directoryAttributes[0]].Value = extendedObjectFromIdentity.DistinguishedName;
                                 if (!directoryObj.Contains("msDS-ClaimValueType"))
                                 {
                                     directoryObj.Add("msDS-ClaimValueType", (long)aDClaimValueType);
                                 }
                                 else
                                 {
                                     long?nullable = (long?)(directoryObj["msDS-ClaimValueType"].Value as long?);
                                     if ((ADClaimValueType)nullable.Value != aDClaimValueType)
                                     {
                                         throw new ADException(StringResources.CTSourceAttributeValueTypeError);
                                     }
                                 }
                                 directoryObj.InternalProperties[directoryAttributes[0]].Value = str;
                                 return;
                             }
                             else
                             {
                                 throw new ADException(StringResources.SPCTDefuctSourceAttr);
                             }
                         }
                         else
                         {
                             throw new ADException(StringResources.SPCTRODCFilteredSourceAttr);
                         }
                     }
                     else
                     {
                         throw new ADException(StringResources.SPCTNonREPLSourceAttrError);
                     }
                 }
                 else
                 {
                     throw new ADException(StringResources.SPCTBlockedSourceAttribute);
                 }
             }
         }
         else
         {
             throw new ADException(StringResources.SPCTInvalidSourceAttributeName);
         }
     }
 }