
Hi Frnds,
I have a user (A) he has five group in ActiveDirectory (named AccounManager, BGroup, CGroup,..). Whether the same AD group is present in AX 2012? If so , how to check , assign and get roles for the same group in AX(which is already in AD).
I can able to use the "System.DirectoryServices.AccountManagement" class to get the AD group for the user.
Here is my code to get the AD group for the user:
domain = new System.DirectoryServices.AccountManagement.PrincipalContext(System.DirectoryServices.AccountManagement.ContextType::Domain);
networkAlias = userInfo.networkAlias;
//userPrinipal = System.DirectoryServices.AccountManagement.UserPrincipal::FindByIdentity(domain, networkAlias);
userPrinipal = System.DirectoryServices.AccountManagement.UserPrincipal::FindByIdentity(domain,networkAlias);
if(userPrinipal != null)
{
//groups = userPrinipal.GetAuthorizationGroups();
groups = userPrinipal.GetGroups();
enum = groups.GetEnumerator();
while (enum.MoveNext())
{
groupPrinipal = enum.get_Current();
groupName = groupPrinipal.get_Name();
groupN = groupName;
info(strFmt("Group 1 :%1 user id : %2 and user name %3",groupN,UserInfo.id,UserInfo.name));
}
Please check my code and correct me if anything wrong.
Here i have some question:
What is the difference between this two group ?
groups = userPrinipal.GetAuthorizationGroups();
groups = userPrinipal.GetGroups();
.
Thanks in advance.
*This post is locked for comments
I have the same question (0)Hi Jackie,
I have split this question as the question is different compared to the original. This would prevent changing the topic.
You can get some information about the methods on MSDN:
The getGroups seems like returning only direct linked AD groups of a certain user. The GetAuthorizationGroups seems to be a method to get also indirectly assigned groups. But this is an AD related topic which is not my area of knowledge.
I cannot comment on the code as you have not told the requirement to be fulfilled. Usually you setup the groups also as users in AX to have this feature enabled. I don't know your intention to read the AD groups per user.