|
security
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Authorization against AD using MC++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 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. Show quoteHide quote "albier" <alb***@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 > > 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 Show quoteHide quote "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" <alb***@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 > > > > > > > I also tried the following code but got more or less the same problem:
ArrayList* usersList = new ArrayList(); Object* groups = de->Invoke("Groups", NULL); while (((IEnumerable*)groups)->GetEnumerator()->MoveNext()) { DirectoryEntry* groupEntry = new DirectoryEntry(((IEnumerable*)groups)->GetEnumerator()->Current); usersList->Add(groupEntry->Name); } Your help is appreciated. Albier Show quoteHide quote "albier" wrote: > 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" <alb***@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 > > > > > > > > > > > > I believe you need to call GetEnumerator once, not in the loop body, and
then enumerate instance returned by it. I'm not really an MC++ guy though, I'm the directory services programming guy, so someone else with more experience here might be able to help. Joe K. Show quoteHide quote "albier" <alb***@discussions.microsoft.com> wrote in message news:7ACDD09C-CEBF-4FB3-9A2C-3ABCA0E2CAFC@microsoft.com... >I also tried the following code but got more or less the same problem: > > ArrayList* usersList = new ArrayList(); > Object* groups = de->Invoke("Groups", NULL); > > while (((IEnumerable*)groups)->GetEnumerator()->MoveNext()) > { > DirectoryEntry* groupEntry = new > DirectoryEntry(((IEnumerable*)groups)->GetEnumerator()->Current); > usersList->Add(groupEntry->Name); > } > > Your help is appreciated. > Albier > > "albier" wrote: > >> 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" <alb***@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 >> > > >> > > >> > >> > >> >
LogonUser Succeeds - but fails later
HttpWebRequest.GetRequestStream - Trust Failure In Windows Service Forms Authentication Not Redirecting To Login Page Why defaultcredential doesn't use the impersonated user? Java security api - DCE 128bit encryption with .NET SecurityException: Request Failed on CreateInstanceAndUnwrap Decrypt file in VB6 encrypted in vb.net Runtime error when running caspol w/ -pub -hex Propagate Credentials from Internet Explorer Host Instead of Defau <identity impersonat=> problems. |
|||||||||||||||||||||||