473,409 Members | 1,970 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

How to get memberOf groups for a user in ldap ?

Hi,

I am trying to autheticate a user in ldap and get a list of all the groups
the the use is a member of. My problem is that i only get one groups from the
request, although i know i am memeber of several groups.

Can anyone see what i am doing wrong here?

public bool IsAuthenticated(string domain, string username, string pwd)
{
//using System.DirectoryServices;

string domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd);

try
{
DirectorySearcher search = new DirectorySearcher(entry);

search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();

if(null == result)
{
return false;
}
_path = result.Path; //Update the new path to the user in the directory.
//_filterAttribute = (string)result.Properties["cn"][0];
}
catch (Exception ex)
{
label4.Text = ex.Message;
return false;
}

ListMemberOfGroups(_path);
return true;
}

public void ListMemberOfGroups(string path)
{
DirectoryEntry entry = new DirectoryEntry(path);
DirectorySearcher search = new DirectorySearcher(entry);

search.PropertiesToLoad.Add("memberOf");

try
{
foreach(System.DirectoryServices.SearchResult resEnt
in search.FindAll())
{
string res =
resEnt.GetDirectoryEntry().Properties["memberOf"].Value.ToString();
lb1.Items.Add(res);
}
}
catch(Exception ex)
{
lb1.Items.Add(ex.Message);
}
}
--
Henrik
Nov 16 '05 #1
1 25311
you are best asking the two Joes in the microsoft.public.adsi.general

HTH

Ollie Riches

"Henrik" <He****@discussions.microsoft.com> wrote in message
news:1E**********************************@microsof t.com...
Hi,

I am trying to autheticate a user in ldap and get a list of all the groups
the the use is a member of. My problem is that i only get one groups from
the
request, although i know i am memeber of several groups.

Can anyone see what i am doing wrong here?

public bool IsAuthenticated(string domain, string username, string pwd)
{
//using System.DirectoryServices;

string domainAndUsername = domain + @"\" + username;
DirectoryEntry entry = new DirectoryEntry(_path, domainAndUsername, pwd);

try
{
DirectorySearcher search = new DirectorySearcher(entry);

search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();

if(null == result)
{
return false;
}
_path = result.Path; //Update the new path to the user in the directory.
//_filterAttribute = (string)result.Properties["cn"][0];
}
catch (Exception ex)
{
label4.Text = ex.Message;
return false;
}

ListMemberOfGroups(_path);
return true;
}

public void ListMemberOfGroups(string path)
{
DirectoryEntry entry = new DirectoryEntry(path);
DirectorySearcher search = new DirectorySearcher(entry);

search.PropertiesToLoad.Add("memberOf");

try
{
foreach(System.DirectoryServices.SearchResult resEnt
in search.FindAll())
{
string res =
resEnt.GetDirectoryEntry().Properties["memberOf"].Value.ToString();
lb1.Items.Add(res);
}
}
catch(Exception ex)
{
lb1.Items.Add(ex.Message);
}
}
--
Henrik

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Brian Denning via .NET 247 | last post by:
I have a program that I have created (VB.NET 2003) that takes anexcel spread sheet and creates a user based on what is in theSS. This is working properly. Now, I want the be able to takeanother...
1
by: Access | last post by:
Here is my function to change a users permission level in the database. This relates to an Access database secured using Access security. This function is called if the end user changes a staff...
1
by: uiranejeb | last post by:
How can I determine the windows groups from a domain? How can I determine all the windows groups to which a user belongs to? (WindowsPrincipal says if a user belongs to a specific group. I need a...
3
by: Andy_Alpha | last post by:
Here's code,that i think,add user in group .... DirectoryEntry grp=new DirectoryEntry(GroupName); MessageBox.Show(GroupName,"group to add"); try { if (grp!=null) { grp.Invoke("Add",new...
3
by: Dennis Dobslaf | last post by:
I try to do some authentication with LDAP. But it's a bit different to the sample in msdn. I wrote a class LdapAuthentication with a method public bool IsAuthenticated(String domain, String...
10
by: Jeff Williams | last post by:
How can I get a list of the Groups both Local and Domain groups a User belongs to.
10
by: Chris Noble | last post by:
I am not sure that I have picked the right newsgroup for this post. I am writing a program in C# VS 2005 to create user accounts for our students in Active Directory. This is to replace a...
0
by: Structured Chaos | last post by:
I am looking for example code and articles on creating a custom tab in AD Users & Groups user properties (like the Exchange add-in). Any direction is greatly appreciated. TIA
0
by: Arajeh | last post by:
Hello, Can anybody help me on how to change iplanet users groups throw LDAP using System.DirectoryServices??
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.