private static string TeamProjectUri(this TeamFoundationIdentity identity, string projectUri)
        {
            string teamProject = null;

            if (identity.Descriptor.IdentityType == ExtensionMethods.IDENTITY_TYPE_TFS)
            {
                teamProject = identity.GetProperty("Domain").ToString();
            }
            return(teamProject);
        }
Ejemplo n.º 2
0
 public Task <Image> GetImageAsync(TeamFoundationIdentity identity)
 {
     return(Task.Run(() =>
     {
         return Check.TryCatch <Image, Exception>(() =>
         {
             TeamFoundationIdentity readIdentity = tfsContext.IdentityManagementService2.ReadIdentity(IdentitySearchFactor.AccountName, identity.UniqueName, MembershipQuery.Direct, ReadIdentityOptions.ExtendedProperties, fetchPropertiesForImage, IdentityPropertyScope.Both);
             byte[] image = readIdentity.GetProperty("Microsoft.TeamFoundation.Identity.Image.Data") as byte[];
             if (image != null && image.Length > 0)
             {
                 MemoryStream ms = new MemoryStream(image);
                 return Image.FromStream(ms);
             }
             return null;
         });
     }));
 }
Ejemplo n.º 3
0
        private async void FillModelData()
        {
            if (identity != null)
            {
                DisplayName = identity.DisplayName;
                Email       = Check.TryCatch <string, Exception>(() => identity.GetProperty("Mail").ToString());
                UniqueName  = identity.UniqueName;
                AllUsers    =
                    new ObservableCollection <TeamFoundationIdentity>(
                        TfsContext.IdentityManager.GetAllIdentities().Where(i => !i.DisplayName.Contains(@"]\")));

                var _image = await TfsContext.IdentityManager.GetImageAsync(identity);

                if (_image != null)
                {
                    Image = new Bitmap(_image).ToImageSource();
                }
            }
        }
Ejemplo n.º 4
0
 public byte[] GetImage(string username)
 {
     if (string.IsNullOrWhiteSpace(username))
     {
         return(null);
     }
     try
     {
         _projectCollection.EnsureAuthenticated();
         var identityService      = _projectCollection.GetService <IIdentityManagementService2>();
         TeamFoundationIdentity i = identityService.ReadIdentity(IdentitySearchFactor.AccountName, username,
                                                                 MembershipQuery.Direct, ReadIdentityOptions.ExtendedProperties);
         var img = i.GetProperty("Microsoft.TeamFoundation.Identity.Image.Data");
         return(img as byte[]);
     }
     catch
     {
         return(null);
     }
 }
Ejemplo n.º 5
0
        public string GetEmail(string accountUniqueName)
        {
            var tfs = this.dte.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt") as TeamFoundationServerExt;

            if (tfs == null || tfs.ActiveProjectContext == null)
            {
                return(null);
            }

            string activeUri = tfs.ActiveProjectContext.DomainUri;

            if (string.IsNullOrEmpty(activeUri))
            {
                return(null);
            }

            TfsTeamProjectCollection collection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(activeUri));

            if (collection == null)
            {
                return(null);
            }

            IIdentityManagementService ims = collection.GetService(typeof(IIdentityManagementService)) as IIdentityManagementService;

            if (ims == null)
            {
                return(null);
            }

            TeamFoundationIdentity identity = ims.ReadIdentity(IdentitySearchFactor.AccountName, accountUniqueName, MembershipQuery.Direct, ReadIdentityOptions.None);

            if (identity == null)
            {
                return(null);
            }

            string email = identity.GetProperty("Mail") as string;

            return(email);
        }
Ejemplo n.º 6
0
        public static object Run(ExportADGroupsOptions opts, string logPath)
        {
            Telemetry.Current.TrackEvent("Run-ExportADGroupsCommand");
            string exportPath = CreateExportPath(logPath, "ExportADGroups");

            Trace.Listeners.Add(new TextWriterTraceListener(Path.Combine(exportPath, "ExportADGroups.log"), "ExportADGroupsCommand"));
            Stopwatch stopwatch = Stopwatch.StartNew();
            //////////////////////////////////////////////////

            StreamWriter sw = File.CreateText(Path.Combine(exportPath, "AzureADGroups.csv"));

            sw.AutoFlush = true;
            using (var csv = new CsvWriter(sw))
            {
                csv.WriteHeader <AzureAdGroupItem>();

                TfsTeamProjectCollection sourceCollection = new TfsTeamProjectCollection(opts.CollectionURL);
                sourceCollection.EnsureAuthenticated();
                IIdentityManagementService2 sourceIMS2         = (IIdentityManagementService2)sourceCollection.GetService(typeof(IIdentityManagementService2));
                List <CatalogNode>          sourceTeamProjects = sourceCollection.CatalogNode.QueryChildren(new[] { CatalogResourceTypes.TeamProject }, false, CatalogQueryOptions.None).ToList();
                if (opts.TeamProject != null)
                {
                    sourceTeamProjects = sourceTeamProjects.Where(x => x.Resource.DisplayName == opts.TeamProject).ToList();
                }
                int current = sourceTeamProjects.Count();
                foreach (CatalogNode sourceTeamProject in sourceTeamProjects)
                {
                    Trace.WriteLine(string.Format("---------------{0}\\{1}", current, sourceTeamProjects.Count()));
                    Trace.WriteLine(string.Format("{0}, {1}", sourceTeamProject.Resource.DisplayName, sourceTeamProject.Resource.Identifier));
                    string projectUri = sourceTeamProject.Resource.Properties["ProjectUri"];
                    TeamFoundationIdentity[] appGroups = sourceIMS2.ListApplicationGroups(projectUri, ReadIdentityOptions.None);
                    foreach (TeamFoundationIdentity appGroup in appGroups.Where(x => !x.DisplayName.EndsWith("\\Project Valid Users")))
                    {
                        Trace.WriteLine(string.Format("    {0}", appGroup.DisplayName));
                        TeamFoundationIdentity sourceAppGroup = sourceIMS2.ReadIdentity(appGroup.Descriptor, MembershipQuery.Expanded, ReadIdentityOptions.None);
                        foreach (IdentityDescriptor child in sourceAppGroup.Members.Where(x => x.IdentityType == "Microsoft.TeamFoundation.Identity"))
                        {
                            TeamFoundationIdentity sourceChildIdentity = sourceIMS2.ReadIdentity(IdentitySearchFactor.Identifier, child.Identifier, MembershipQuery.None, ReadIdentityOptions.ExtendedProperties);

                            if ((string)sourceChildIdentity.GetProperty("SpecialType") == "AzureActiveDirectoryApplicationGroup")
                            {
                                Trace.WriteLine(string.Format("     Suspected AD Group {0}", sourceChildIdentity.DisplayName));
                                csv.WriteRecord <AzureAdGroupItem>(new AzureAdGroupItem
                                {
                                    TeamProject      = sourceTeamProject.Resource.DisplayName,
                                    ApplciationGroup = sourceTeamProject.Resource.DisplayName,
                                    Account          = (string)sourceChildIdentity.GetProperty("Account"),
                                    Mail             = (string)sourceChildIdentity.GetProperty("Mail"),
                                    DirectoryAlias   = (string)sourceChildIdentity.GetProperty("DirectoryAlias")
                                });
                            }
                        }
                    }
                    current--;
                    sw.Flush();
                }
            }
            sw.Close();
            //    current--;
            //}



            //////////////////////////////////////////////////
            stopwatch.Stop();
            Trace.WriteLine(string.Format(@"DONE in {0:%h} hours {0:%m} minutes {0:s\:fff} seconds", stopwatch.Elapsed));
            Trace.Listeners.Remove("ExportADGroupsCommand");
            return(0);
        }
Ejemplo n.º 7
0
        public override int RunInternal(ExportAzureADOptions opts)
        {
            opts.OutPath = opts.OutPath ?? this.LogPathRoot;

            StreamWriter sw = File.CreateText(Path.Combine(opts.OutPath, "IdentityList.csv"));

            sw.AutoFlush = true;
            using (var csv = new CsvWriter(sw))
            {
                csv.WriteHeader <AzureAdGroupItem>();

                TfsTeamProjectCollection sourceCollection = new TfsTeamProjectCollection(opts.CollectionURL);
                sourceCollection.EnsureAuthenticated();
                IIdentityManagementService2 sourceIMS2         = (IIdentityManagementService2)sourceCollection.GetService(typeof(IIdentityManagementService2));
                List <CatalogNode>          sourceTeamProjects = sourceCollection.CatalogNode.QueryChildren(new[] { CatalogResourceTypes.TeamProject }, false, CatalogQueryOptions.None).ToList();
                if (opts.TeamProject != null)
                {
                    sourceTeamProjects = sourceTeamProjects.Where(x => x.Resource.DisplayName == opts.TeamProject).ToList();
                }
                int current = sourceTeamProjects.Count();
                foreach (CatalogNode sourceTeamProject in sourceTeamProjects)
                {
                    Trace.WriteLine(string.Format("---------------{0}\\{1}", current, sourceTeamProjects.Count()));
                    Trace.WriteLine(string.Format("{0}, {1}", sourceTeamProject.Resource.DisplayName, sourceTeamProject.Resource.Identifier));
                    string projectUri = sourceTeamProject.Resource.Properties["ProjectUri"];
                    TeamFoundationIdentity[] appGroups = sourceIMS2.ListApplicationGroups(projectUri, ReadIdentityOptions.None);
                    foreach (TeamFoundationIdentity appGroup in appGroups.Where(x => !x.DisplayName.EndsWith("\\Project Valid Users")))
                    {
                        Trace.WriteLine(string.Format("    {0}", appGroup.DisplayName));
                        TeamFoundationIdentity sourceAppGroup = sourceIMS2.ReadIdentity(appGroup.Descriptor, MembershipQuery.Expanded, ReadIdentityOptions.None);
                        foreach (IdentityDescriptor child in sourceAppGroup.Members.Where(x => x.IdentityType == "Microsoft.TeamFoundation.Identity" || x.IdentityType == "Microsoft.IdentityModel.Claims.ClaimsIdentity"))
                        {
                            TeamFoundationIdentity sourceChildIdentity = sourceIMS2.ReadIdentity(IdentitySearchFactor.Identifier, child.Identifier, MembershipQuery.None, ReadIdentityOptions.ExtendedProperties);
                            var    SpecialType = (string)sourceChildIdentity.GetProperty("SpecialType");
                            var    Account     = (string)sourceChildIdentity.GetProperty("Account");
                            object DirectoryAlias;
                            object Mail;
                            sourceChildIdentity.TryGetProperty("DirectoryAlias", out DirectoryAlias);
                            sourceChildIdentity.TryGetProperty("Mail", out Mail);
                            switch (SpecialType)
                            {
                            case "AzureActiveDirectoryApplicationGroup":
                                Trace.WriteLine(string.Format("     Found AD Group {0}", sourceChildIdentity.DisplayName));
                                csv.WriteRecord <AzureAdGroupItem>(new AzureAdGroupItem
                                {
                                    TeamProject      = sourceTeamProject.Resource.DisplayName,
                                    ApplciationGroup = appGroup.DisplayName,
                                    Account          = Account,
                                    Mail             = (string)Mail,
                                    DirectoryAlias   = (string)DirectoryAlias
                                });
                                break;

                            case "Generic":
                                if (sourceChildIdentity.IsContainer)
                                {
                                    Trace.WriteLine(string.Format("Skipping {0} | {1} - TF GROUP", SpecialType, Account));
                                }
                                else
                                {
                                    Trace.WriteLine(string.Format("     Found AD User {0}", sourceChildIdentity.DisplayName));
                                    csv.WriteRecord <AzureAdGroupItem>(new AzureAdGroupItem
                                    {
                                        TeamProject      = sourceTeamProject.Resource.DisplayName,
                                        ApplciationGroup = appGroup.DisplayName,
                                        Account          = Account,
                                        Mail             = (string)Mail,
                                        DirectoryAlias   = (string)DirectoryAlias
                                    });
                                }
                                break;

                            default:
                                Trace.WriteLine(string.Format("Skipping {0} | {1} - UNKNOWN", SpecialType, Account));
                                break;
                            }
                        }
                    }
                    current--;
                    sw.Flush();
                }
            }
            sw.Close();
            return(0);
        }