Exemplo n.º 1
0
        public IEnumerable <PSADServicePrincipal> FilterServicePrincipals(Rest.Azure.OData.ODataQuery <MicrosoftGraphServicePrincipal> odataQuery, int first = int.MaxValue, int skip = 0)
        {
            var response = GraphClient.ServicePrincipals.ListServicePrincipal(
                consistencyLevel: "eventual",
                filter: OdataHelper.GetFilterString(odataQuery)
                );

            return(response.Value.Select(s => s.ToPSADServicePrincipal()));
        }
Exemplo n.º 2
0
        public IEnumerable <PSADGroup> FilterGroups(ADObjectFilterOptions options, int first = int.MaxValue, int skip = 0)
        {
            if (!string.IsNullOrEmpty(options.Id))
            {
                try
                {
                    // use GetObjectsByObjectId to handle Redirects in the CSP scenario
                    PSADGroup group = GetObjectByObjectId(options.Id) as PSADGroup;
                    if (group != null)
                    {
                        return(new List <PSADGroup> {
                            group
                        });
                    }
                }
                catch { /* The group does not exist, ignore the exception */ }

                return(new List <PSADGroup>());
            }
            else if (options.Mail != null)
            {
                Rest.Azure.OData.ODataQuery <MicrosoftGraphGroup> odataQuery = new Rest.Azure.OData.ODataQuery <MicrosoftGraphGroup>(g => g.Mail == options.Mail);
                return(GraphClient.Groups.ListGroup(filter: OdataHelper.GetFilterString(odataQuery)).Value.Select(g => g.ToPSADGroup()));
            }
            else
            {
                Rest.Azure.OData.ODataQuery <MicrosoftGraphGroup> odataQuery = null;
                if (!string.IsNullOrEmpty(options.SearchString) && options.SearchString.EndsWith("*"))
                {
                    options.SearchString = options.SearchString.TrimEnd('*');
                    odataQuery           = new Rest.Azure.OData.ODataQuery <MicrosoftGraphGroup>(g => g.DisplayName.StartsWith(options.SearchString));
                }
                else
                {
                    odataQuery = new Rest.Azure.OData.ODataQuery <MicrosoftGraphGroup>(g => g.DisplayName == options.SearchString);
                }

                return(GraphClient.Groups.ListGroup(filter: OdataHelper.GetFilterString(odataQuery)).Value.Select(g => g.ToPSADGroup()));
            }
        }
Exemplo n.º 3
0
        public IEnumerable <PSADServicePrincipal> FilterServicePrincipals(ADObjectFilterOptions options, int first = int.MaxValue, int skip = 0)
        {
            List <PSADServicePrincipal>    servicePrincipals = new List <PSADServicePrincipal>();
            MicrosoftGraphServicePrincipal servicePrincipal  = null;

            if (!string.IsNullOrEmpty(options.Id))
            {
                try
                {
                    servicePrincipal = GraphClient.ServicePrincipals.GetServicePrincipal(options.Id);
                }
                catch { /* The user does not exist, ignore the exception. */ }

                if (servicePrincipal != null)
                {
                    servicePrincipals.Add(servicePrincipal.ToPSADServicePrincipal());
                }
            }
            else if (!string.IsNullOrEmpty(options.SPN))
            {
                try
                {
                    var odataQuery = new Rest.Azure.OData.ODataQuery <MicrosoftGraphServicePrincipal>(s => s.ServicePrincipalNames.Contains(options.SPN));
                    // todo: doesn't support paging
                    servicePrincipal = GraphClient.ServicePrincipals.ListServicePrincipal(filter: OdataHelper.GetFilterString(odataQuery)).Value.FirstOrDefault();
                }
                catch { /* The user does not exist, ignore the exception. */ }

                if (servicePrincipal != null)
                {
                    servicePrincipals.Add(servicePrincipal.ToPSADServicePrincipal());
                }
            }
            else
            {
                Rest.Azure.OData.ODataQuery <MicrosoftGraphServicePrincipal> odataQuery = null;
                if (!string.IsNullOrEmpty(options.SearchString) && options.SearchString.EndsWith("*"))
                {
                    options.SearchString = options.SearchString.TrimEnd('*');
                    odataQuery           = new Rest.Azure.OData.ODataQuery <MicrosoftGraphServicePrincipal>(s => s.DisplayName != null && s.DisplayName.StartsWith(options.SearchString));
                }
                else
                {
                    odataQuery = new Rest.Azure.OData.ODataQuery <MicrosoftGraphServicePrincipal>(s => s.DisplayName == options.SearchString);
                }

                return(FilterServicePrincipals(odataQuery, first, skip));
            }

            return(servicePrincipals);
        }
Exemplo n.º 4
0
        public IEnumerable <PSADUser> FilterUsers(ADObjectFilterOptions options, int first = int.MaxValue, int skip = 0)
        {
            if (!string.IsNullOrEmpty(options.Id))
            {
                MicrosoftGraphUser user = null;
                try
                {
                    user = GraphClient.Users.GetUser(Normalize(options.Id));
                }
                catch { /* The user does not exist, ignore the exception. */ }

                if (user != null)
                {
                    return(new List <PSADUser> {
                        user.ToPSADUser()
                    });
                }
            }
            else if (!string.IsNullOrEmpty(options.UPN) || !string.IsNullOrEmpty(options.Mail))
            {
                IList <MicrosoftGraphUser> result = null;
                try
                {
                    string upnOrMail  = Normalize(options.UPN) ?? Normalize(options.Mail);
                    var    odataQuery = new Rest.Azure.OData.ODataQuery <MicrosoftGraphUser>();
                    if (!string.IsNullOrEmpty(options.UPN))
                    {
                        odataQuery.SetFilter(u => u.UserPrincipalName == upnOrMail);
                    }
                    else
                    {
                        odataQuery.SetFilter(u => u.Mail == upnOrMail);
                    }
                    result = GraphClient.Users.ListUser(
                        "eventual",
                        filter: OdataHelper.GetFilterString(odataQuery)
                        ).Value;
                }
                catch { /* The user does not exist, ignore the exception. */ }

                if (result != null)
                {
                    return(result.Select(u => u.ToPSADUser()));
                }
            }
            else
            {
                Rest.Azure.OData.ODataQuery <MicrosoftGraphUser> odataQuery = null;
                if (!string.IsNullOrEmpty(options.SearchString) && options.SearchString.EndsWith("*"))
                {
                    options.SearchString = options.SearchString.TrimEnd('*');
                    odataQuery           = new Rest.Azure.OData.ODataQuery <MicrosoftGraphUser>(u => u.DisplayName != null && u.DisplayName.StartsWith(options.SearchString));
                }
                else
                {
                    odataQuery = new Rest.Azure.OData.ODataQuery <MicrosoftGraphUser>(u => u.DisplayName == options.SearchString);
                }

                return(GraphClient.Users.ListUser(
                           consistencyLevel: "eventual",
                           filter: OdataHelper.GetFilterString(odataQuery)
                           ).Value.Select(u => u.ToPSADUser()));
            }

            return(new List <PSADUser>());
        }