getAttributeSet() public method

Returns the attribute set of the entry. All base and subtype variants of all attributes are returned. The LdapAttributeSet returned may be empty if there are no attributes in the entry.
public getAttributeSet ( ) : LdapAttributeSet
return LdapAttributeSet
        /// <summary> Build the attribuite list from an LdapEntry.
        ///
        /// </summary>
        /// <param name="entry">The LdapEntry associated with this add request.
        /// </param>
        private static RfcAttributeList makeRfcAttrList(LdapEntry entry)
        {
            // convert Java-API LdapEntry to RFC2251 AttributeList
            LdapAttributeSet attrSet  = entry.getAttributeSet();
            RfcAttributeList attrList = new RfcAttributeList(attrSet.Count);
            IEnumerator      itr      = attrSet.GetEnumerator();

            while (itr.MoveNext())
            {
                LdapAttribute attr     = (LdapAttribute)itr.Current;
                Asn1SetOf     vals     = new Asn1SetOf(attr.size());
                IEnumerator   attrEnum = attr.ByteValues;
                while (attrEnum.MoveNext())
                {
                    vals.add(new RfcAttributeValue((sbyte[])attrEnum.Current));
                }
                attrList.add(new RfcAttributeTypeAndValues(new RfcAttributeDescription(attr.Name), vals));
            }
            return(attrList);
        }
示例#2
0
        /// <summary>
        ///     Constructs an LdapSchema object from attributes of an LdapEntry.
        ///     The object is empty if the entry parameter contains no schema
        ///     attributes.  The recognized schema attributes are the following:
        ///     <pre>
        ///         <code>
        /// "attributeTypes", "objectClasses", "ldapSyntaxes",
        /// "nameForms", "dITContentRules", "dITStructureRules",
        /// "matchingRules","matchingRuleUse"
        /// </code>
        ///     </pre>
        /// </summary>
        /// <param name="ent">
        ///     An LdapEntry containing schema information.
        /// </param>
        public LdapSchema(LdapEntry ent) : base(ent.DN, ent.getAttributeSet())
        {
            InitBlock();
            //reset all definitions
            for (var i = 0; i < schemaTypeNames.Length; i++)
            {
                idTable[i]   = new Hashtable();
                nameTable[i] = new Hashtable();
            }
            var itr = getAttributeSet().GetEnumerator();

            while (itr.MoveNext())
            {
                var    attr = (LdapAttribute)itr.Current;
                string value_Renamed, attrName = attr.Name;
                var    enumString = attr.StringValues;

                if (attrName.ToUpper().Equals(schemaTypeNames[OBJECT_CLASS].ToUpper()))
                {
                    LdapObjectClassSchema classSchema;
                    while (enumString.MoveNext())
                    {
                        value_Renamed = (string)enumString.Current;
                        try
                        {
                            classSchema = new LdapObjectClassSchema(value_Renamed);
                        }
                        catch (Exception e)
                        {
                            Logger.Log.LogWarning("Exception swallowed", e);
                            continue; //Error parsing: do not add this definition
                        }
                        addElement(OBJECT_CLASS, classSchema);
                    }
                }
                else if (attrName.ToUpper().Equals(schemaTypeNames[ATTRIBUTE].ToUpper()))
                {
                    LdapAttributeSchema attrSchema;
                    while (enumString.MoveNext())
                    {
                        value_Renamed = (string)enumString.Current;
                        try
                        {
                            attrSchema = new LdapAttributeSchema(value_Renamed);
                        }
                        catch (Exception e)
                        {
                            Logger.Log.LogWarning("Exception swallowed", e);
                            continue; //Error parsing: do not add this definition
                        }
                        addElement(ATTRIBUTE, attrSchema);
                    }
                }
                else if (attrName.ToUpper().Equals(schemaTypeNames[SYNTAX].ToUpper()))
                {
                    LdapSyntaxSchema syntaxSchema;
                    while (enumString.MoveNext())
                    {
                        value_Renamed = (string)enumString.Current;
                        syntaxSchema  = new LdapSyntaxSchema(value_Renamed);
                        addElement(SYNTAX, syntaxSchema);
                    }
                }
                else if (attrName.ToUpper().Equals(schemaTypeNames[MATCHING].ToUpper()))
                {
                    LdapMatchingRuleSchema matchingRuleSchema;
                    while (enumString.MoveNext())
                    {
                        value_Renamed      = (string)enumString.Current;
                        matchingRuleSchema = new LdapMatchingRuleSchema(value_Renamed, null);
                        addElement(MATCHING, matchingRuleSchema);
                    }
                }
                else if (attrName.ToUpper().Equals(schemaTypeNames[MATCHING_USE].ToUpper()))
                {
                    LdapMatchingRuleUseSchema matchingRuleUseSchema;
                    while (enumString.MoveNext())
                    {
                        value_Renamed         = (string)enumString.Current;
                        matchingRuleUseSchema = new LdapMatchingRuleUseSchema(value_Renamed);
                        addElement(MATCHING_USE, matchingRuleUseSchema);
                    }
                }
                else if (attrName.ToUpper().Equals(schemaTypeNames[DITCONTENT].ToUpper()))
                {
                    LdapDITContentRuleSchema dITContentRuleSchema;
                    while (enumString.MoveNext())
                    {
                        value_Renamed        = (string)enumString.Current;
                        dITContentRuleSchema = new LdapDITContentRuleSchema(value_Renamed);
                        addElement(DITCONTENT, dITContentRuleSchema);
                    }
                }
                else if (attrName.ToUpper().Equals(schemaTypeNames[DITSTRUCTURE].ToUpper()))
                {
                    LdapDITStructureRuleSchema dITStructureRuleSchema;
                    while (enumString.MoveNext())
                    {
                        value_Renamed          = (string)enumString.Current;
                        dITStructureRuleSchema = new LdapDITStructureRuleSchema(value_Renamed);
                        addElement(DITSTRUCTURE, dITStructureRuleSchema);
                    }
                }
                else if (attrName.ToUpper().Equals(schemaTypeNames[NAME_FORM].ToUpper()))
                {
                    LdapNameFormSchema nameFormSchema;
                    while (enumString.MoveNext())
                    {
                        value_Renamed  = (string)enumString.Current;
                        nameFormSchema = new LdapNameFormSchema(value_Renamed);
                        addElement(NAME_FORM, nameFormSchema);
                    }
                }
                //All non schema attributes are ignored.
            }
        }
示例#3
0
        //public LdapUser(LdapSettings ldapSettings, String userName)
        //{
        //    // in some cases with Active Directory
        //    // we can't actually retrieve ldap entries
        //    // we really just need to create a mojoportal user
        //    // from the ldap user so if we can't read it, just create an ldap user
        //    // with the properties we do have
        //    // Active Directory allows us to bind a connection for authentication
        //    // even if we can't query for entries
        //    email = new LdapAttribute("email", userName + "@" + ldapSettings.Domain);
        //    commonname = new LdapAttribute("commonname", userName);
        //    userid = new LdapAttribute("userid", userName);
        //}
        public LdapUser(LdapEntry entry)
        {
            dn = entry.DN;

            LdapAttributeSet las = entry.getAttributeSet();

            foreach(LdapAttribute a in las)
            {
                switch(a.Name)
                {
                    case "mail":
                        this.email = a;
                        break;
                    case "cn":
                        this.commonname = a;
                        break;
                    case "userPassword":
                        this.password = a;
                        break;
                    case "uidNumber":
                        this.uidNumber = a;
                        break;
                    case "uid":
                        this.userid = a;
                        break;
                    case "sAMAccountName":
                        this.userid = a;
                        break;
                    case "givenName":
                        this.firstName = a.StringValue;
                        break;
                    case "sn":
                        this.lastName = a.StringValue;
                        break;
                }
            }
        }
示例#4
0
		/// <summary> Constructs an LdapSchema object from attributes of an LdapEntry.
		/// The object is empty if the entry parameter contains no schema
		/// attributes.  The recognized schema attributes are the following: 
		/// <pre><code>
		/// "attributeTypes", "objectClasses", "ldapSyntaxes",
		/// "nameForms", "dITContentRules", "dITStructureRules",
		/// "matchingRules","matchingRuleUse"
		/// </code></pre>
		/// </summary>
		/// <param name="ent">         An LdapEntry containing schema information.
		/// </param>
		public LdapSchema(LdapEntry ent):base(ent.DN, ent.getAttributeSet())
		{
			InitBlock();
			//reset all definitions
			for (int i = 0; i < schemaTypeNames.Length; i++)
			{
				idTable[i] = new System.Collections.Hashtable();
				nameTable[i] = new System.Collections.Hashtable();
			}
			System.Collections.IEnumerator itr = base.getAttributeSet().GetEnumerator();
			while (itr.MoveNext())
			{
				
				LdapAttribute attr = (LdapAttribute) itr.Current;
				System.String value_Renamed, attrName = attr.Name;
				System.Collections.IEnumerator enumString = attr.StringValues;
				
				if (attrName.ToUpper().Equals(schemaTypeNames[OBJECT_CLASS].ToUpper()))
				{
					LdapObjectClassSchema classSchema;
					while (enumString.MoveNext())
					{
						value_Renamed = ((System.String) enumString.Current);
						try
						{
							classSchema = new LdapObjectClassSchema(value_Renamed);
						}
						catch (System.Exception e)
						{
							continue; //Error parsing: do not add this definition
						}
						addElement(OBJECT_CLASS, classSchema);
					}
				}
				else if (attrName.ToUpper().Equals(schemaTypeNames[ATTRIBUTE].ToUpper()))
				{
					LdapAttributeSchema attrSchema;
					while (enumString.MoveNext())
					{
						value_Renamed = ((System.String) enumString.Current);
						try
						{
							attrSchema = new LdapAttributeSchema(value_Renamed);
						}
						catch (System.Exception e)
						{
							continue; //Error parsing: do not add this definition
						}
						addElement(ATTRIBUTE, attrSchema);
					}
				}
				else if (attrName.ToUpper().Equals(schemaTypeNames[SYNTAX].ToUpper()))
				{
					LdapSyntaxSchema syntaxSchema;
					while (enumString.MoveNext())
					{
						value_Renamed = ((System.String) enumString.Current);
						syntaxSchema = new LdapSyntaxSchema(value_Renamed);
						addElement(SYNTAX, syntaxSchema);
					}
				}
				else if (attrName.ToUpper().Equals(schemaTypeNames[MATCHING].ToUpper()))
				{
					LdapMatchingRuleSchema matchingRuleSchema;
					while (enumString.MoveNext())
					{
						value_Renamed = ((System.String) enumString.Current);
						matchingRuleSchema = new LdapMatchingRuleSchema(value_Renamed, null);
						addElement(MATCHING, matchingRuleSchema);
					}
				}
				else if (attrName.ToUpper().Equals(schemaTypeNames[MATCHING_USE].ToUpper()))
				{
					LdapMatchingRuleUseSchema matchingRuleUseSchema;
					while (enumString.MoveNext())
					{
						value_Renamed = ((System.String) enumString.Current);
						matchingRuleUseSchema = new LdapMatchingRuleUseSchema(value_Renamed);
						addElement(MATCHING_USE, matchingRuleUseSchema);
					}
				}
				else if (attrName.ToUpper().Equals(schemaTypeNames[DITCONTENT].ToUpper()))
				{
					LdapDITContentRuleSchema dITContentRuleSchema;
					while (enumString.MoveNext())
					{
						value_Renamed = ((System.String) enumString.Current);
						dITContentRuleSchema = new LdapDITContentRuleSchema(value_Renamed);
						addElement(DITCONTENT, dITContentRuleSchema);
					}
				}
				else if (attrName.ToUpper().Equals(schemaTypeNames[DITSTRUCTURE].ToUpper()))
				{
					LdapDITStructureRuleSchema dITStructureRuleSchema;
					while (enumString.MoveNext())
					{
						value_Renamed = ((System.String) enumString.Current);
						dITStructureRuleSchema = new LdapDITStructureRuleSchema(value_Renamed);
						addElement(DITSTRUCTURE, dITStructureRuleSchema);
					}
				}
				else if (attrName.ToUpper().Equals(schemaTypeNames[NAME_FORM].ToUpper()))
				{
					LdapNameFormSchema nameFormSchema;
					while (enumString.MoveNext())
					{
						value_Renamed = ((System.String) enumString.Current);
						nameFormSchema = new LdapNameFormSchema(value_Renamed);
						addElement(NAME_FORM, nameFormSchema);
					}
				}
				//All non schema attributes are ignored.
				continue;
			}
		}
示例#5
0
    /**
     * Prints the DN and attributes in an LDAPEntry to System.out.
     * This method used TreeSet to sort the attributes by name.
     */
    public static void PrintEntry(LdapEntry entry)
    {
        /* To print an entry,
         *   -- Loop through all the attributes
         *   -- Loop through all the attribute values
         */

        Console.WriteLine(entry.DN);
        Console.WriteLine("\tAttributes: ");

        LdapAttributeSet attributeSet = entry.getAttributeSet();
        IEnumerator allAttributes = attributeSet.GetEnumerator();

        while(allAttributes.MoveNext())
        {
            LdapAttribute attribute = (LdapAttribute)(allAttributes.Current);
            string attributeName = attribute.Name;

            Console.WriteLine("\t\t" + attributeName);

            IEnumerator allValues = attribute.StringValues;

            if( allValues != null)
            {
                while(allValues.MoveNext())
                {
                    String Value = (String) allValues.Current;
                    Console.WriteLine("\t\t\t" + Value);
                }
            }
        }
        return;
    }
示例#6
0
		/// <summary> Build the attribuite list from an LdapEntry.
		/// 
		/// </summary>
		/// <param name="entry">The LdapEntry associated with this add request.
		/// </param>
		private static RfcAttributeList makeRfcAttrList(LdapEntry entry)
		{
			// convert Java-API LdapEntry to RFC2251 AttributeList
			LdapAttributeSet attrSet = entry.getAttributeSet();
			RfcAttributeList attrList = new RfcAttributeList(attrSet.Count);
			System.Collections.IEnumerator itr = attrSet.GetEnumerator();
			while (itr.MoveNext())
			{
				LdapAttribute attr = (LdapAttribute) itr.Current;
				Asn1SetOf vals = new Asn1SetOf(attr.size());
				System.Collections.IEnumerator attrEnum = attr.ByteValues;
				while (attrEnum.MoveNext())
				{
					vals.add(new RfcAttributeValue((sbyte[]) attrEnum.Current));
				}
				attrList.add(new RfcAttributeTypeAndValues(new RfcAttributeDescription(attr.Name), vals));
			}
			return attrList;
		}
示例#7
0
        public void Run(LdapEntry lhs, LdapEntry rhs)
        {
            Log.Debug ("Starting LdapEntryAnalyzer");

            if (lhs.CompareTo (rhs) != 0) {
                Log.Debug ("Entry DNs don't match\nlhs: {0}\nrhs: {1}", lhs.DN, rhs.DN);
                return;
            }

            LdapAttributeSet las = lhs.getAttributeSet ();
            foreach (LdapAttribute la in las) {
                LdapAttribute rla = rhs.getAttribute (la.Name);
                if (rla == null){

                    Log.Debug ("Delete attribute {0} from {1}", la.Name, lhs.DN);
                    LdapAttribute a = new LdapAttribute (la.Name);
                    LdapModification m = new LdapModification (LdapModification.DELETE, a);
                    mods.Add (m);

                } else {

                    if (rla.StringValueArray.Length > 1) {

                        Log.Debug ("Replacing attribute {0} with multiple values", la.Name);
                        LdapAttribute a = new LdapAttribute (la.Name, rla.StringValueArray);
                        LdapModification m = new LdapModification (LdapModification.REPLACE, a);
                        mods.Add (m);

                    } else if (la.StringValue != rla.StringValue) {

                        LdapAttribute newattr;
                        LdapModification lm;

                        if (rla.StringValue == "" || rla.StringValue == null) {
                            Log.Debug ("Delete attribute {0} from {1}", la.Name, lhs.DN);
                            newattr = new LdapAttribute (la.Name);
                            lm = new LdapModification (LdapModification.DELETE, newattr);
                        } else {
                            Log.Debug ("Replace attribute {0} value from {1} to {2} ", la.Name, la.StringValue, rla.StringValue);
                            newattr = new LdapAttribute (la.Name, rla.StringValue);
                            lm = new LdapModification (LdapModification.REPLACE, newattr);
                        }

                        mods.Add (lm);
                    }
                }
            }

            LdapAttributeSet rlas = rhs.getAttributeSet ();
            foreach (LdapAttribute la in rlas) {
                LdapAttribute lla = lhs.getAttribute (la.Name);
                if (lla == null && la.StringValue != string.Empty) {
                    Log.Debug ("Add attribute {0} value [{1}] to {2}", la.Name, la.StringValue, lhs.DN);
                    LdapAttribute a = new LdapAttribute (la.Name, la.StringValue);
                    LdapModification m = new LdapModification (LdapModification.ADD, a);
                    mods.Add (m);
                }
            }

            Log.Debug ("End LdapEntryAnalyzer");
        }
示例#8
0
        public void Show(Connection connection, LdapEntry entry, bool showAll)
        {
            displayAll = showAll;
            conn = connection;
            currentDN = entry.DN;
            currentAttributes = new NameValueCollection ();

            // FIXME: crashes after an apply if I don't re-create the store;
            store = new ListStore (typeof (string), typeof(string));
            store.SetSortColumnId (0, SortType.Ascending);
            tv.Model = store;

            //			store.Clear ();

            allAttrs = new List<string> ();
            LdapAttribute a = entry.getAttribute ("objectClass");

            for (int i = 0; i < a.StringValueArray.Length; i++) {

                string o = (string) a.StringValueArray[i];
                store.AppendValues ("objectClass", o);
                currentAttributes.Add ("objectClass", o);

                string[] attrs = conn.Data.GetAllAttributes (o);
                if (attrs != null) {
                    foreach (string at in attrs)
                        if (!allAttrs.Contains (at))
                            allAttrs.Add (at);
                } else {
                    Log.Debug("Could not retrieve any attribute for objectClass " + o);
                }
            }

            LdapAttributeSet attributeSet = entry.getAttributeSet ();

            // Fedora Directory Server supports an Access Control Item (ACI)
            // but it is not listed as "allowed attribute" for any objectClass
            // found in Fedora's LDAP schema.
            if (showAll && conn.Settings.ServerType == LdapServerType.FedoraDirectory) {
                LdapEntry[] acientries = conn.Data.Search(	currentDN,
                                                        LdapConnection.SCOPE_BASE,
                                                        "objectclass=*",
                                                        new string[] {"aci"} );

                if (acientries.Length > 0) {
                    LdapEntry acientry = acientries[0];
                    LdapAttribute aciattr = acientry.getAttribute("aci");
                    if (aciattr != null)
                        if (attributeSet.Add(aciattr) == false)
                            Log.Debug ("Could not add ACI attribute.");
                }
            }

            foreach (LdapAttribute attr in attributeSet) {

                if (allAttrs.Contains (attr.Name))
                    allAttrs.Remove (attr.Name);

                if (attr.Name.ToLower() == "objectclass")
                    continue;

                try {

                    foreach (string s in attr.StringValueArray) {
                        store.AppendValues (attr.Name, s);
                        currentAttributes.Add (attr.Name, s);
                    }

                } catch (ArgumentOutOfRangeException e) {
                    // FIXME: this only happens with gmcs
                    store.AppendValues (attr.Name, "");
                    Log.Debug ("Show attribute arugment out of range: {0}", attr.Name);
                    Log.Debug (e.Message);
                }
            }

            if (!showAll)
                return;

            foreach (string n in allAttrs)
                store.AppendValues (n, "");
        }