Exemplo n.º 1
0
        private void GetDelimitedIdentityAndContainers()
        {
            string[] ldaps     = LDAPPaths.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            string[] netbioses = NetBiosNames.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            string   fqn       = GetStringProperty(Constants.SOProperties.Identity.FQN, true);
            string   delimiter = GetStringParameter(Constants.SOProperties.Identity.Delimiter, true);

            ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable();

            DataTable dtResults = ServiceBroker.ServicePackage.ResultTable;

            FQName fqnName = new FQName(fqn);

            ICachedIdentity userIdentity = ServiceBroker.IdentityService.GetIdentityFromName(fqnName, IdentityType.User, null);

            ICollection <ICachedIdentity> groupIdentities = ServiceBroker.IdentityService.GetIdentityContainers(userIdentity, IdentitySearchOptions.Groups);
            ICollection <ICachedIdentity> roleIdentities  = ServiceBroker.IdentityService.GetIdentityContainers(userIdentity, IdentitySearchOptions.Roles);

            if (groupIdentities == null && roleIdentities == null)
            {
                return;
            }
            string delimitedFQNs = fqnName.FQN;

            foreach (ICachedIdentity groupIdentity in groupIdentities)
            {
                if (groupIdentity.Type == IdentityType.Group)
                {
                    delimitedFQNs += delimiter + groupIdentity.FullyQualifiedName.FQN;
                }
            }
            foreach (ICachedIdentity roleIdentity in roleIdentities)
            {
                if (roleIdentity.Type == IdentityType.Role)
                {
                    delimitedFQNs += delimiter + roleIdentity.FullyQualifiedName.FQN;
                }
            }

            DataRow dRow = dtResults.NewRow();

            dRow[Constants.SOProperties.Identity.DelimitedFQNs] = delimitedFQNs;
            dtResults.Rows.Add(dRow);
        }
Exemplo n.º 2
0
        private void GetGroups()
        {
            string[] ldaps         = LDAPPaths.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            string[] netbioses     = NetBiosNames.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            string   securityLabel = GetStringParameter(Constants.SOProperties.URM.Label, true);

            ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable();

            if (string.Compare(securityLabel, "K2", true) == 0)
            {
                List <Thread> threads = new List <Thread>();
                string        ldap, net;
                Parallel.For(0, ldaps.Length, i =>
                {
                    ldap = ldaps[i];
                    net  = netbioses[i];
                    RunUMGetGroups(ldap, net);
                });

                //This line of code is needed so that the received items are not filtered again by K2 internal filtering of SMO.
                ServiceBroker.Service.ServiceObjects[0].Methods[0].Filter = null;
            }
            else
            {
                // The below code is a copy/paste from reflected code with some modifications as we can't do anything else.
                string    name        = GetStringProperty(Constants.SOProperties.URM.Name);
                string    email       = GetStringProperty(Constants.SOProperties.URM.Email);
                string    description = GetStringProperty(Constants.SOProperties.URM.Description);
                DataTable dtResults   = ServiceBroker.ServicePackage.ResultTable;
                URMFilter urmFilter   = new URMFilter(ServiceBroker.Service.ServiceObjects[0].Methods[0].Filter);

                foreach (Dictionary <string, string> filterCollectionValues in urmFilter.GetFilterCollection().Values)
                {
                    foreach (KeyValuePair <string, string> keyValuePair in filterCollectionValues)
                    {
                        switch (keyValuePair.Key)
                        {
                        case Constants.SOProperties.URM.Name:
                            name = keyValuePair.Value.Replace("'", "");
                            continue;

                        case Constants.SOProperties.URM.Description:
                            description = keyValuePair.Value.Replace("'", "");
                            continue;

                        case Constants.SOProperties.URM.Email:
                            email = keyValuePair.Value.Replace("'", "");
                            continue;

                        default:
                            continue;
                        }
                    }
                    Dictionary <string, object> dictionary2 = new Dictionary <string, object>()
                    {
                        { "Name", name },
                        { "Description", description },
                        { "Email", email }
                    };
                    if (!string.IsNullOrEmpty(securityLabel))
                    {
                        dictionary2["Label"] = securityLabel as object;
                    }
                    ICollection <ICachedIdentity> identities = base.ServiceBroker.IdentityService.FindIdentities(dictionary2, IdentitySearchOptions.Groups);
                    if (identities == null)
                    {
                        return;
                    }

                    foreach (ICachedIdentity cachedIdentity in identities)
                    {
                        if (cachedIdentity.Type == IdentityType.Group)
                        {
                            DataRow dRow = dtResults.NewRow();
                            dRow[Constants.SOProperties.URM.FQN]       = cachedIdentity.FullyQualifiedName.FQN;
                            dRow[Constants.SOProperties.URM.GroupName] = cachedIdentity.FullyQualifiedName.FullName;
                            dRow[Constants.SOProperties.URM.Saml]      = cachedIdentity.FullyQualifiedName.FullName;

                            if (cachedIdentity.Properties.ContainsKey("Name") && cachedIdentity.Properties["Name"] != null)
                            {
                                dRow[Constants.SOProperties.URM.Name] = cachedIdentity.Properties["Name"].ToString();
                            }
                            if (cachedIdentity.Properties.ContainsKey("Description") && cachedIdentity.Properties["Description"] != null)
                            {
                                dRow[Constants.SOProperties.URM.Description] = cachedIdentity.Properties["Description"].ToString();
                            }
                            if (cachedIdentity.Properties.ContainsKey("Email") && !string.IsNullOrEmpty(cachedIdentity.Properties["Email"].ToString()))
                            {
                                dRow[Constants.SOProperties.URM.Email] = cachedIdentity.Properties["Email"].ToString();
                            }
                            dtResults.Rows.Add(dRow);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void GetUsers()
        {
            string[] ldaps         = LDAPPaths.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            string[] netbioses     = NetBiosNames.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            string   securityLabel = GetStringParameter(Constants.SOProperties.URM.Label, true);

            ServiceBroker.Service.ServiceObjects[0].Properties.InitResultTable();

            if (string.Compare(securityLabel, "K2", true) == 0)
            {
                List <Thread> threads = new List <Thread>();
                string        ldap, net;
                Parallel.For(0, ldaps.Length, i =>
                {
                    ldap = ldaps[i];
                    net  = netbioses[i];
                    RunUMGetUsers(ldap, net);
                });
                //This line of code is needed so that the received items are not filtered again by K2 internal filtering of SMO.
                ServiceBroker.Service.ServiceObjects[0].Methods[0].Filter = null;
            }
            else
            {
                // The below is basically copy/pasted code from the URM service. We don't really have a better way of calling that service instance code.

                string fqn         = GetStringProperty(Constants.SOProperties.URM.FQN);
                string name        = GetStringProperty(Constants.SOProperties.URM.Name);
                string email       = GetStringProperty(Constants.SOProperties.URM.Email);
                string description = GetStringProperty(Constants.SOProperties.URM.Description);
                string manager     = GetStringProperty(Constants.SOProperties.URM.Manager);
                string displayName = GetStringProperty(Constants.SOProperties.URM.DisplayName);
                string userName    = GetStringProperty(Constants.SOProperties.URM.UserName);
                string objectSid   = GetStringProperty(Constants.SOProperties.URM.ObjectSid);
                string saml        = GetStringProperty(Constants.SOProperties.URM.Saml);

                DataTable dtResults = ServiceBroker.ServicePackage.ResultTable;
                URMFilter urmFilter = new URMFilter(ServiceBroker.Service.ServiceObjects[0].Methods[0].Filter);

                foreach (Dictionary <string, string> dictionary in urmFilter.GetFilterCollection().Values)
                {
                    foreach (KeyValuePair <string, string> keyValuePair in dictionary)
                    {
                        switch (keyValuePair.Key)
                        {
                        case Constants.SOProperties.URM.FQN:
                            fqn = keyValuePair.Value.Replace("N'", "").Replace("'", "");
                            continue;

                        case Constants.SOProperties.URM.Name:
                            name = keyValuePair.Value.Replace("N'", "").Replace("'", "");
                            continue;

                        case Constants.SOProperties.URM.Email:
                            email = keyValuePair.Value.Replace("N'", "").Replace("'", "");
                            continue;

                        case Constants.SOProperties.URM.Description:
                            description = keyValuePair.Value.Replace("N'", "").Replace("'", "");
                            continue;

                        case Constants.SOProperties.URM.Manager:
                            manager = keyValuePair.Value.Replace("N'", "").Replace("'", "");
                            continue;

                        case Constants.SOProperties.URM.DisplayName:
                            displayName = keyValuePair.Value.Replace("N'", "").Replace("'", "");
                            continue;

                        case Constants.SOProperties.URM.UserName:
                            userName = keyValuePair.Value.Replace("N'", "").Replace("'", "");
                            continue;

                        case Constants.SOProperties.URM.ObjectSid:
                            objectSid = keyValuePair.Value.Replace("N'", "").Replace("'", "");
                            continue;

                        case Constants.SOProperties.URM.Saml:
                            saml = keyValuePair.Value.Replace("N'", "").Replace("'", "");
                            continue;

                        default:
                            continue;
                        }
                    }
                    Dictionary <string, object> properties = new Dictionary <string, object>()
                    {
                        { Constants.SOProperties.URM.Name, name == String.Empty ? (object)(string)null : (object)name },
                        {
                            Constants.SOProperties.URM.Description,
                            description == String.Empty ? (object)(string)null : (object)description
                        },
                        {
                            Constants.SOProperties.URM.Email, email == String.Empty ? (object)(string)null : (object)email
                        },
                        {
                            Constants.SOProperties.URM.Manager,
                            manager == String.Empty ? (object)(string)null : (object)manager
                        },
                        {
                            Constants.SOProperties.URM.DisplayName,
                            displayName == String.Empty ? (object)(string)null : (object)displayName
                        }
                    };
                    Helper.AddNonStandardProperties(properties, base.ServiceBroker.IdentityService.QueryUserProperties(securityLabel));

                    if (!string.IsNullOrEmpty(securityLabel))
                    {
                        properties[Constants.SOProperties.URM.Label] = (object)securityLabel;
                    }

                    if (ADMaxResultSize != -1)
                    {
                        properties["RowCount"]   = (object)(ADMaxResultSize);
                        properties["PageNumber"] = (object)1;
                    }
                    ICollection <ICachedIdentity> collection = base.ServiceBroker.IdentityService.FindIdentities((IDictionary <string, object>)properties, IdentitySearchOptions.Users);


                    bool flag   = properties.ContainsKey("RowCount");
                    int  result = 0;
                    if (flag)
                    {
                        int.TryParse((string)properties["RowCount"], out result);
                    }
                    if (collection != null)
                    {
                        foreach (ICachedIdentity cachedIdentity in collection)
                        {
                            if (cachedIdentity.Type == IdentityType.User)
                            {
                                DataRow dRow = dtResults.NewRow();
                                dRow[Constants.SOProperties.URM.FQN] = cachedIdentity.FullyQualifiedName.FQN;
                                if (cachedIdentity.Properties.ContainsKey("Name") && cachedIdentity.Properties["Name"] != null)
                                {
                                    dRow[Constants.SOProperties.URM.UserName] = cachedIdentity.Properties["Name"].ToString();
                                    dRow[Constants.SOProperties.URM.Name]     = cachedIdentity.Properties["Name"].ToString();
                                    dRow[Constants.SOProperties.URM.Saml]     = LdapHelper.GetSAMAccountName(cachedIdentity.Properties["Name"].ToString());
                                }
                                if (cachedIdentity.Properties.ContainsKey("Description") && cachedIdentity.Properties["Description"] != null)
                                {
                                    dRow[Constants.SOProperties.URM.Description] = cachedIdentity.Properties["Description"].ToString();
                                }
                                if (cachedIdentity.Properties.ContainsKey("Email") && !string.IsNullOrEmpty(cachedIdentity.Properties["Email"].ToString()))
                                {
                                    dRow[Constants.SOProperties.URM.Email] = cachedIdentity.Properties["Email"].ToString();
                                }
                                if (cachedIdentity.Properties.ContainsKey("Manager") && cachedIdentity.Properties["Manager"] != null)
                                {
                                    dRow[Constants.SOProperties.URM.Manager] = cachedIdentity.Properties["Manager"].ToString();
                                }
                                if (cachedIdentity.Properties.ContainsKey("ObjectSID") && cachedIdentity.Properties["ObjectSID"] != null)
                                {
                                    dRow[Constants.SOProperties.URM.ObjectSid] = cachedIdentity.Properties["ObjectSID"].ToString();
                                }
                                if (cachedIdentity.Properties.ContainsKey("DisplayName") && cachedIdentity.Properties["DisplayName"] != null)
                                {
                                    dRow[Constants.SOProperties.URM.DisplayName] = cachedIdentity.Properties["DisplayName"].ToString();
                                }
                                dtResults.Rows.Add(dRow);


                                if (flag && dtResults.Rows.Count == result)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }