Re: Authorization against AD using MC++

From: albier (albier_at_discussions.microsoft.com)
Date: 08/02/05

  • Next message: albier: "Re: Authorization against AD using MC++"
    Date: Tue, 2 Aug 2005 14:07:01 -0700
    
    

    Joe,
    Thanks for the pointers but I still don't know how to use the
    IEnumerable::GetEnumerator to be able to loop over the list of objects I
    have. I have tried the following code but got an error in for trying to
    type-cast groups.

    ArrayList* usersList = new ArrayList();
    System::Object* groups = de->Invoke("Groups", NULL);
                                    
    while (((IEnumerator*)groups)->MoveNext())
    {
    DirectoryEntry* groupEntry = new
    DirectoryEntry(((IEnumerator*)groups)->Current);
    usersList->Add(groupEntry->Name);
    }

    It would be great if you can just show me how to use the
    IEnumerable::GetEnumerator in order to loop over the list of objects I have
    (groups*). Thanks again for your time,
    Albier

    "Joe Kaplan (MVP - ADSI)" wrote:

    > You should probably just call the IEnumerable::GetEnumerator method and then
    > use its MoveNext and Current members to enumerate the group collection.
    > That is all foreach does under the hood.
    >
    > Note that the actual approach you are using may not work for nested group
    > membership or the user's primary group. It is a better idea to do this kind
    > of authorization based on the user's logon token and the token_groups
    > structure inside of it.
    >
    > Joe K.
    >
    > "albier" <albier@discussions.microsoft.com> wrote in message
    > news:7067232E-4D89-42DC-B7CA-7A58A72587B9@microsoft.com...
    > >I wrote a code with C# to authorize users against AD. Here is the code:
    > >
    > > ArrayList usersList = new ArrayList();
    > > object groups = user.Invoke("Groups",null);
    > > foreach (object group in (IEnumerable)groups)
    > > {
    > > DirectoryEntry groupEntry = new DirectoryEntry(group);
    > > usersList.Add(groupEntry.Name);
    > > }
    > >
    > > This code is working perfectly. I'm having problems writing the same code
    > > using Managed C++. A similar code would be:
    > >
    > > ArrayList* usersList = new ArrayList();
    > > System::Object* groups = de->Invoke("Groups", NULL);
    > > while (groups != NULL)
    > > {
    > > DirectoryEntry* groupEntry = new DirectoryEntry(groups);
    > > usersList->Add(groupEntry->Name);
    > > groups++;
    > > }
    > >
    > > This code doesn't work since pointers in MC++ cannot be incremented and I
    > > cannot use them to refer to the variable they are pointing to. Since these
    > > pointers are __gc type (Garbage Collected), I cannot say *groups to refer
    > > to
    > > the value the pointer groups is pointing to. I also cannot say groups++ to
    > > increment the pointer so that groups would point to the next object in the
    > > list of objects. Please notice that the Invoke "Group" function would
    > > return
    > > a list of objects and I need to loop over this list. Do you have a
    > > solution
    > > for this problem? Do you have any other idea of how to implement the C#
    > > code
    > > above?
    > > Thanks for your help,
    > > Albier Michaiel
    > >
    > >
    >
    >
    >


  • Next message: albier: "Re: Authorization against AD using MC++"