Пример #1
0
        /// <summary>
        /// initializes the wiazrd pages based on "systemMustContain" attribute value list for the selected objectclass
        /// Adds the wizard pages to the wizard dialog
        /// </summary>
        /// <param name="nodeText"></param>
        /// <param name="mandatoryAttributes"></param>
        private void AddWizardPages(string nodeText, String[] mandatoryAttributes)
        {
            treeView1.HideSelection    = false;
            _objectAddDlg.choosenClass = nodeText;
            _objectAddDlg.objectInfo.htMandatoryAttrList = new Hashtable();

            List <string> attrlist = new List <string>();

            _objectAddDlg.ClassAttributeList = new List <LdapAttributeType>();

            attrlist.Add("instanceType");
            attrlist.Add("objectCategory");
            attrlist.Add("objectClass");
            if (_objectAddDlg.choosenClass.Trim().Equals("user", StringComparison.InvariantCultureIgnoreCase) ||
                _objectAddDlg.choosenClass.Trim().Equals("group", StringComparison.InvariantCultureIgnoreCase) ||
                _objectAddDlg.choosenClass.Trim().Equals("computer", StringComparison.InvariantCultureIgnoreCase))
            {
                attrlist.Add("objectSid");
                attrlist.Add("sAMAccountName");
                if (!attrlist.Contains("cn"))
                {
                    attrlist.Add("cn");
                }
                if (mandatoryAttributes != null)
                {
                    foreach (string attr in mandatoryAttributes)
                    {
                        if (!attrlist.Contains(attr))
                        {
                            attrlist.Add(attr);
                        }
                    }
                }
            }

            LdapClassType classtype = _objectAddDlg.schemaCache.GetSchemaTypeByObjectClass(_objectAddDlg.choosenClass) as LdapClassType;

            AttributeMap attr_map  = classtype.Tag as AttributeMap;
            LdapEntry    ldapentry = attr_map.Tag as LdapEntry;

            string DN = ldapentry.GetDN();

            string[] attrs = { "name", "allowedAttributes", null };

            List <LdapEntry> innerLdapEntries = null;
            int ret = dirnode.LdapContext.ListChildEntriesSynchronous
                          (dirnode.DistinguishedName,
                          LdapAPI.LDAPSCOPE.BASE,
                          "(objectClass=*)",
                          attrs,
                          false,
                          out innerLdapEntries);

            ldapentry = innerLdapEntries[0];

            LdapValue[] ldapValues = ldapentry.GetAttributeValues("allowedAttributes", dirnode.LdapContext);
            if (ldapValues != null && ldapValues.Length > 0)
            {
                string[] optionalAttrs = new string[ldapValues.Length];
                foreach (LdapValue Oclass in ldapValues)
                {
                    string     attrValue  = Oclass.stringData;
                    SchemaType schematype = _objectAddDlg.schemaCache.GetSchemaTypeByDisplayName(attrValue) as SchemaType;
                    if (schematype != null)
                    {
                        schematype.AttributeType = "Optional";
                        _objectAddDlg.ClassAttributeList.Add(schematype as LdapAttributeType);
                    }
                }

                foreach (string strValue in attrlist)
                {
                    SchemaType schematype = _objectAddDlg.schemaCache.GetSchemaTypeByDisplayName(strValue) as SchemaType;
                    if (schematype != null)
                    {
                        schematype.AttributeType = "Mandatory";
                        _objectAddDlg.ClassAttributeList.Add(schematype as LdapAttributeType);
                    }
                }
            }

            if (_objectAddDlg.ClassAttributeList != null && _objectAddDlg.ClassAttributeList.Count != 0)
            {
                foreach (LdapAttributeType Attribute in _objectAddDlg.ClassAttributeList)
                {
                    AttributeInfo attributeInfo = new AttributeInfo();
                    attributeInfo.sAttributename  = Attribute.AttributeDisplayName;
                    attributeInfo.sAttributeValue = "<not set>";
                    attributeInfo.sAttributeType  = Attribute.AttributeType;
                    attributeInfo.schemaInfo      =
                        _objectAddDlg.schemaCache.GetSchemaTypeByCommonName(Attribute.CName);
                    if (!_objectAddDlg.objectInfo._AttributesList.ContainsKey(Attribute.AttributeDisplayName))
                    {
                        _objectAddDlg.objectInfo._AttributesList.Add(Attribute.AttributeDisplayName, attributeInfo);
                    }
                }
            }
            ObjectAddSinglePage ObjectAddSinglePage = null;

            _objectAddDlg.objectInfo.addedPages = new List <string>();
            ObjectInfo.PageIndex = 0;
            //for all objects we should prompt to ask for their cn
            if (nodeText.Equals("organizationalUnit", StringComparison.InvariantCultureIgnoreCase))
            {
                ObjectAddSinglePage = new ObjectAddSinglePage(_objectAddDlg, "ou");
                _objectAddDlg.AddPage(ObjectAddSinglePage);
                _objectAddDlg.objectInfo.addedPages.Add("ou");
            }
            else
            {
                ObjectAddSinglePage = new ObjectAddSinglePage(_objectAddDlg, "cn");
                _objectAddDlg.AddPage(ObjectAddSinglePage);
                _objectAddDlg.objectInfo.addedPages.Add("cn");
            }

            if (mandatoryAttributes != null && mandatoryAttributes.Length != 0)
            {
                for (int i = 0; i < mandatoryAttributes.Length; i++)
                {
                    if (!((mandatoryAttributes[i].Trim().ToLower().Equals("cn")) || (mandatoryAttributes[i].Trim().ToLower().Equals("ou"))))
                    {
                        ObjectAddSinglePage = new ObjectAddSinglePage(_objectAddDlg, mandatoryAttributes[i].Trim());
                        _objectAddDlg.AddPage(ObjectAddSinglePage);
                        _objectAddDlg.objectInfo.addedPages.Add(mandatoryAttributes[i].Trim());
                    }
                }
            }

            if (_objectAddDlg.choosenClass.Equals("computer", StringComparison.InvariantCultureIgnoreCase)
                ||
                _objectAddDlg.choosenClass.Equals("user", StringComparison.InvariantCultureIgnoreCase)
                ||
                _objectAddDlg.choosenClass.Equals("group", StringComparison.InvariantCultureIgnoreCase))
            {
                ObjectAddSinglePage = new ObjectAddSinglePage(_objectAddDlg, "sAMAccountName");
                _objectAddDlg.AddPage(ObjectAddSinglePage);
                _objectAddDlg.objectInfo.addedPages.Add("sAMAccountName");
            }

            //for all objects they all come to the end of final page
            _objectAddDlg.AddPage(new ObjectAddFinalPage(_objectAddDlg, _container, _parentPage));

            Wizard.enableButton(WizardDialog.WizardButton.Start);
        }
    /// <summary>
    /// initializes the wiazrd pages based on "systemMustContain" attribute value list for the selected objectclass
    /// Adds the wizard pages to the wizard dialog
    /// </summary>
    /// <param name="nodeText"></param>
    /// <param name="mandatoryAttributes"></param>
    private void AddWizardPages(string nodeText, String[] mandatoryAttributes)
    {
        treeView1.HideSelection = false;
        _objectAddDlg.choosenClass = nodeText;
        _objectAddDlg.objectInfo.htMandatoryAttrList = new Hashtable();

        List<string> attrlist = new List<string>();
        _objectAddDlg.ClassAttributeList = new List<LdapAttributeType>();

        attrlist.Add("instanceType");
        attrlist.Add("objectCategory");
        attrlist.Add("objectClass");
        if (_objectAddDlg.choosenClass.Trim().Equals("user", StringComparison.InvariantCultureIgnoreCase) ||
            _objectAddDlg.choosenClass.Trim().Equals("group", StringComparison.InvariantCultureIgnoreCase) ||
            _objectAddDlg.choosenClass.Trim().Equals("computer", StringComparison.InvariantCultureIgnoreCase))
        {
            attrlist.Add("objectSid");
            attrlist.Add("sAMAccountName");
            if (!attrlist.Contains("cn"))
            {
                attrlist.Add("cn");
            }
            if (mandatoryAttributes != null)
            {
                foreach (string attr in mandatoryAttributes)
                {
                    if (!attrlist.Contains(attr))
                    {
                        attrlist.Add(attr);
                    }
                }
            }
        }

        LdapClassType classtype = _objectAddDlg.schemaCache.GetSchemaTypeByObjectClass(_objectAddDlg.choosenClass) as LdapClassType;

        AttributeMap attr_map = classtype.Tag as AttributeMap;
        LdapEntry ldapentry = attr_map.Tag as LdapEntry;

        string DN = ldapentry.GetDN();
        string[] attrs = { "name", "allowedAttributes", null };

        List<LdapEntry> innerLdapEntries = null;
        int ret = dirnode.LdapContext.ListChildEntriesSynchronous
        (dirnode.DistinguishedName,
        LdapAPI.LDAPSCOPE.BASE,
        "(objectClass=*)",
        attrs,
        false,
        out innerLdapEntries);

        ldapentry = innerLdapEntries[0];

        LdapValue[] ldapValues = ldapentry.GetAttributeValues("allowedAttributes", dirnode.LdapContext);
        if (ldapValues != null && ldapValues.Length > 0)
        {
            string[] optionalAttrs = new string[ldapValues.Length];
            foreach (LdapValue Oclass in ldapValues)
            {
                string attrValue = Oclass.stringData;
                SchemaType schematype = _objectAddDlg.schemaCache.GetSchemaTypeByDisplayName(attrValue) as SchemaType;
                if (schematype != null)
                {
                    schematype.AttributeType = "Optional";
                    _objectAddDlg.ClassAttributeList.Add(schematype as LdapAttributeType);
                }
            }

            foreach (string strValue in attrlist)
            {
                SchemaType schematype = _objectAddDlg.schemaCache.GetSchemaTypeByDisplayName(strValue) as SchemaType;
                if (schematype != null)
                {
                    schematype.AttributeType = "Mandatory";
                    _objectAddDlg.ClassAttributeList.Add(schematype as LdapAttributeType);
                }
            }
        }

        if (_objectAddDlg.ClassAttributeList != null && _objectAddDlg.ClassAttributeList.Count != 0)
        {
            foreach (LdapAttributeType Attribute in _objectAddDlg.ClassAttributeList)
            {
                AttributeInfo attributeInfo = new AttributeInfo();
                attributeInfo.sAttributename = Attribute.AttributeDisplayName;
                attributeInfo.sAttributeValue = "<not set>";
                attributeInfo.sAttributeType = Attribute.AttributeType;
                attributeInfo.schemaInfo =
                    _objectAddDlg.schemaCache.GetSchemaTypeByCommonName(Attribute.CName);
                if (!_objectAddDlg.objectInfo._AttributesList.ContainsKey(Attribute.AttributeDisplayName))
                {
                    _objectAddDlg.objectInfo._AttributesList.Add(Attribute.AttributeDisplayName, attributeInfo);
                }
            }
        }
        ObjectAddSinglePage ObjectAddSinglePage = null;
        _objectAddDlg.objectInfo.addedPages = new List<string>();
        ObjectInfo.PageIndex = 0;
        //for all objects we should prompt to ask for their cn
        if (nodeText.Equals("organizationalUnit", StringComparison.InvariantCultureIgnoreCase))
        {
            ObjectAddSinglePage = new ObjectAddSinglePage(_objectAddDlg, "ou");
            _objectAddDlg.AddPage(ObjectAddSinglePage);
            _objectAddDlg.objectInfo.addedPages.Add("ou");
        }
        else
        {
            ObjectAddSinglePage = new ObjectAddSinglePage(_objectAddDlg, "cn");
            _objectAddDlg.AddPage(ObjectAddSinglePage);
            _objectAddDlg.objectInfo.addedPages.Add("cn");
        }

        if (mandatoryAttributes != null && mandatoryAttributes.Length != 0)
        {
            for (int i = 0; i < mandatoryAttributes.Length; i++)
            {
                if (!((mandatoryAttributes[i].Trim().ToLower().Equals("cn")) || (mandatoryAttributes[i].Trim().ToLower().Equals("ou"))))
                {
                    ObjectAddSinglePage = new ObjectAddSinglePage(_objectAddDlg, mandatoryAttributes[i].Trim());
                    _objectAddDlg.AddPage(ObjectAddSinglePage);
                    _objectAddDlg.objectInfo.addedPages.Add(mandatoryAttributes[i].Trim());
                }
            }
        }

        if (_objectAddDlg.choosenClass.Equals("computer", StringComparison.InvariantCultureIgnoreCase)
        ||
        _objectAddDlg.choosenClass.Equals("user", StringComparison.InvariantCultureIgnoreCase)
        ||
        _objectAddDlg.choosenClass.Equals("group", StringComparison.InvariantCultureIgnoreCase))
        {
            ObjectAddSinglePage = new ObjectAddSinglePage(_objectAddDlg, "sAMAccountName");
            _objectAddDlg.AddPage(ObjectAddSinglePage);
            _objectAddDlg.objectInfo.addedPages.Add("sAMAccountName");
        }

        //for all objects they all come to the end of final page
        _objectAddDlg.AddPage(new ObjectAddFinalPage(_objectAddDlg, _container, _parentPage));

        Wizard.enableButton(WizardDialog.WizardButton.Start);
    }