Esempio n. 1
0
        protected bool AddClassSchemaType(AttributeMap attribute_map)
        {
            LdapValue[] ldapvalues = getFirstValue(attribute_map, CN_TAG);
            string      cName      = null;

            if (ldapvalues != null && ldapvalues.Length > 0)
            {
                cName = ldapvalues[0].stringData;
            }

            ldapvalues = getFirstValue(attribute_map, ATTR_SYNTAX_TAG);
            string attributeSyntax = null;

            if (ldapvalues != null && ldapvalues.Length > 0)
            {
                attributeSyntax = ldapvalues[0].stringData;
            }

            ldapvalues = getFirstValue(attribute_map, IS_SINGLE_VALUED_TAG);
            string isSingleValued = null;

            if (ldapvalues != null && ldapvalues.Length > 0)
            {
                isSingleValued = ldapvalues[0].stringData;
            }

            ldapvalues = getFirstValue(attribute_map, ATTR_DISPLAYNAME_TAG);
            string attributeDisplayName = null;

            if (ldapvalues != null && ldapvalues.Length > 0)
            {
                attributeDisplayName = ldapvalues[0].stringData;
            }

            ldapvalues = getFirstValue(attribute_map, SUBCLASS_OF_TAG);
            string superClassName = null;

            if (ldapvalues != null && ldapvalues.Length > 0)
            {
                superClassName = ldapvalues[0].stringData;
            }

            string[] systemMustContain = GetAttrsWithTag(attribute_map, SYSTEM_MUST_CONTAIN_TAG);
            string[] systemMayContain  = GetAttrsWithTag(attribute_map, SYSTEM_MAY_CONTAIN_TAG);

            //5th Parameter is Mandatory and 6th Parameter is Optional atrributes.
            LdapClassType schemaType = new LdapClassType(
                cName,
                attributeSyntax,
                attributeDisplayName,
                superClassName,
                systemMustContain,
                systemMayContain
                );

            schemaType.Tag = attribute_map;

            if (String.Compare(isSingleValued, "TRUE") == 0)
            {
                schemaType.IsSingleValued = true;
            }
            else
            {
                schemaType.IsSingleValued = false;
            }

            if (!_classTypeLookup.ContainsKey(cName.ToLower()))
            {
                _classTypeLookup.Add(cName.ToLower(), schemaType);
            }

            if (!_dnTypeLookup.ContainsKey(attributeDisplayName.ToLower()))
            {
                _dnTypeLookup.Add(attributeDisplayName.ToLower(), schemaType);
            }

            return(true);
        }
Esempio n. 2
0
        public static LDAPSchemaCache Build(DirectoryContext ldapContext)
        {
            DateTime BuildTimer = DateTime.Now;

            LDAPSchemaCache result = null;

            List <LdapEntry> ldapEntries = new List <LdapEntry>();
            Dictionary <string, LdapEntry> ldapEntriesDic = new Dictionary <string, LdapEntry>();

            string[] search_attrs = { null };

            DateTime timer = Logger.StartTimer();

            Logger.Log(
                "Started building schema cache",
                Logger.ldapLogLevel);

            int ret = ldapContext.ListChildEntriesSynchronous(
                string.Concat("cn=Schema,", ldapContext.ConfigurationNamingContext),
                LdapAPI.LDAPSCOPE.SUB_TREE,
                "(objectClass=*)",
                search_attrs,
                false,
                out ldapEntries);

            if (ldapEntries != null && ldapEntries.Count > 0)
            {
                Logger.TimerMsg(ref timer,
                                String.Format(
                                    "schema cache: {0} entries read from LDAP",
                                    ldapEntries.Count));
                result        = new LDAPSchemaCache();
                result.rootDN = ldapContext.RootDN;
                int entryIndex = 0;

                foreach (LdapEntry entry in ldapEntries)
                {
                    LdapValue[] attrName = entry.GetAttributeValues("lDAPDisplayName", ldapContext);
                    if (attrName != null)
                    {
                        ldapEntriesDic.Add(attrName[0].stringData, entry);
                    }
                }

                foreach (LdapEntry ldapNextEntry in ldapEntries)
                {
                    AttributeMap attrmap = new AttributeMap();

                    string dn = ldapNextEntry.GetDN();

                    Logger.Log(String.Format(
                                   "LDAPSchemaCache.Build: ldapEntry[{0}]: DN = " + dn,
                                   entryIndex++),
                               Logger.ldapLogLevel);

                    //Getting 'objectClasss' value instead 'subClassOf' attribute
                    //becuase 'subClassOf' attribute is not giving the all mandatory attribute for the selected object.
                    LdapValue[] objectClasses = ldapNextEntry.GetAttributeValues("objectClass", ldapContext);
                    foreach (LdapValue Oclass in objectClasses)
                    {
                        if (ldapEntriesDic.ContainsKey(Oclass.stringData))
                        {
                            attrmap.ObjectClasses.Add(Oclass.stringData, ldapEntriesDic[Oclass.stringData]);
                        }
                    }
                    attrmap.ldapContext = ldapContext;
                    attrmap.Tag         = ldapNextEntry;

                    string[] attrs = ldapNextEntry.GetAttributeNames();

                    foreach (string attr in attrs)
                    {
                        LdapValue[] values = ldapNextEntry.GetAttributeValues(attr, ldapContext);

                        attrmap.Add(attr, values);
                    }

                    result.AddSchemaType(attrmap);
                }

                Logger.TimerMsg(ref timer,
                                String.Format(
                                    "LDAPSchemaCache.Build({0})-- finished building the schemaCache",
                                    ldapContext.RootDN));

                result.reportSchemaCache(Logger.ldapLogLevel);
            }


            return(result);
        }
Esempio n. 3
0
        protected bool AddAttributeSchemaType(AttributeMap attribute_map)
        {
            LdapValue[] ldapvalues = getFirstValue(attribute_map, CN_TAG);
            string      cName      = null;

            if (ldapvalues != null && ldapvalues.Length > 0)
            {
                cName = ldapvalues[0].stringData;
            }

            ldapvalues = getFirstValue(attribute_map, ATTR_SYNTAX_TAG);
            string attributeSyntax = null;

            if (ldapvalues != null && ldapvalues.Length > 0)
            {
                attributeSyntax = ldapvalues[0].stringData;
            }

            ldapvalues = getFirstValue(attribute_map, IS_SINGLE_VALUED_TAG);
            string isSingleValued = null;

            if (ldapvalues != null && ldapvalues.Length > 0)
            {
                isSingleValued = ldapvalues[0].stringData;
            }

            ldapvalues = getFirstValue(attribute_map, ATTR_DISPLAYNAME_TAG);
            string attributeDisplayName = null;

            if (ldapvalues != null && ldapvalues.Length > 0)
            {
                attributeDisplayName = ldapvalues[0].stringData;
            }


            if ((attributeSyntax == null) || (isSingleValued == null))
            {
                Logger.Log("Add one entry in schemacache failed", Logger.ldapLogLevel);
                return(false);
            }

            LdapAttributeType schemaType = new LdapAttributeType(cName, attributeSyntax, attributeDisplayName);

            schemaType.Tag = attribute_map;

            if (String.Compare(isSingleValued, "TRUE") == 0)
            {
                schemaType.IsSingleValued = true;
            }
            else
            {
                schemaType.IsSingleValued = false;
            }

            if (!_attrTypeLookup.ContainsKey(cName.ToLower()))
            {
                _attrTypeLookup.Add(cName.ToLower(), schemaType);
            }
            if (!_dnTypeLookup.ContainsKey(attributeDisplayName.ToLower()))
            {
                _dnTypeLookup.Add(attributeDisplayName.ToLower(), schemaType);
            }

            return(true);
        }