예제 #1
0
        /// <summary>
        /// Gets all class attributes from the Schema template and add them to the treeview
        /// </summary>
        /// <param name="objectAddDlg"></param>
        public ObjectAddWelcomePage(ADObjectAddDlg objectAddDlg, ADUCDirectoryNode dirnode, IPlugInContainer container, StandardPage parentPage)
            : this()
        {
            this._objectAddDlg = objectAddDlg;
            this.dirnode       = dirnode;
            this._container    = container;
            this._parentPage   = parentPage;

            if (_objectAddDlg.objectClasses != null)
            {
                if (treeView1.Nodes != null)
                {
                    treeView1.Nodes.Clear();
                }

                foreach (string node in _objectAddDlg.objectClasses)
                {
                    if (node != null)
                    {
                        SchemaType    schemaType          = _objectAddDlg.schemaCache.GetSchemaTypeByObjectClass(node);
                        LdapClassType ldapClassType       = schemaType as LdapClassType;
                        String[]      mandatoryAttributes = ldapClassType.MandatoryAttributes;
                        TreeNode      schemeNode          = new TreeNode();
                        schemeNode.Text = schemaType.AttributeDisplayName;
                        schemeNode.Tag  = mandatoryAttributes;
                        treeView1.Nodes.Add(schemeNode);
                        treeView1.Sort();
                    }
                }
            }

            treeView1.HideSelection = true;
        }
예제 #2
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);
        }