2

We have a requirement in which we have to maintain all users under AD directory instead of Tridion and SDL tridion is integrated with Ad through LDAP, that means the user groups which we are going to create in tridion will not holds any users directly. User groups will hold Directory Service Group which is a group in AD and in that group we have assigned all the users in AD. So now my question is how to fetch all the users from directory service group which we assigned into the Tridion User group. I have code which can provide all the user and user groups name if those are assigned directly into the Tridion Group. Below is the code which I am using to fetch all the users from tridion

            Group approverGroup = new Group(new TcmUri(groupId), session);
            IEnumerable<Trustee> trustees = approverGroup.GetGroupMembers();
            foreach (Trustee trustee in trustees)
            {
                if (trustee == null)
                {
                    LoggerStream.WriteLine("trustee Not Found");
                    continue;
                }
                //local variable declaration.
                string userName  = trustee.Title.Split('\\')[1]; 

Now I need help regarding Directory service group that how to get all users using TOM.net.

2 Answers 2

2

There is a way through TOM.Net to get all the users from the Directory Service Group, as I found and able to retrieved all the users from Directory Service Group in event system code using TOM.NET.

Below is the code to get all users from specific Directory Service Group.

            string activeDirectoryGroup = string.Empty;
            List<ClaimMapping> activeUserGroups = (List<ClaimMapping>)approverGroup.ClaimMappings;
            foreach (ClaimMapping activeUG in activeUserGroups)
            {
                SearchResult result;
                DirectorySearcher search = new DirectorySearcher();

                activeDirectoryGroup = activeUG.Value.Split(',')[0].ToString().Split('=')[1].ToString();
                search.Filter = String.Format("(cn={0})", activeDirectoryGroup);
                search.PropertiesToLoad.Add("member");
                result = search.FindOne(); 

                ArrayList userNames = new ArrayList();
                if (result != null)
                {
                    for (int i = 0; i < result.Properties["member"].Count; i++)
                    {                            
                        string userDisplayName = (String)result.Properties["member"][i].ToString().Split(',')[0].ToString().Split('=')[1].ToString(); ;
                        SendmailToUser(userDisplayName, session, element, currentComponent, currentPage);
                    }
                }
            }                      
0

Unfortunately there's no way to do it in TOM.NET (AFAIK). Here's how to do it using CoreService. If you are using GroupSync you need to get the LDAP address by looking at ClaimMappings property of GroupData. For each of claim mapings you need to do:

var group = (GroupData) client.Read(groupId, readOptions);
var result = new List<DirectoryServiceUser>();
foreach ((DirectoryGroupMappingData) claimMapping in group.ClaimMappings)
{
    if (claimMapping.SearchType = DirectorySearchType.Subtree)
    {
        result.AddRange(client.GetListDirectoryServiceUsers(claimMapping.DirectoryServiceName,
            new DirectoryUsersFilter{ SubtreeDN = claimMapping.SearchDN }));
    }
    else
    {
        result.AddRange(client.GetListDirectoryServiceGroupMembers(claimMapping.DirectoryServiceName, claimMapping.SearchDN));
    }   
}
6
  • I need to get those users in event system code, and I think we can only use TOM.net dlls for eventing code.
    – Nash
    Aug 7, 2015 at 13:19
  • There's no way to get it through TOM.NET. Nothing is stopping you from initializing CoreService connection from your event system. Aug 7, 2015 at 13:47
  • 1
    Note that Core Service is a layer on top of TOM.NET, so everything you can do through Core Service should be possible through TOM.NET too. In this case, you'll have to reference Tridion.Security (to get access to the tridion.Security.DirectoryService class) Aug 7, 2015 at 14:13
  • Hmm, undocumented features... Lovely :) Aug 7, 2015 at 14:23
  • But how can we use core services in event system code, as I need to get directory service group through event system code on component save event
    – Nash
    Aug 11, 2015 at 2:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.