示例#1
0
        public static ActiveDirectoryConfig GetActiveDirectoryConfig()
        {
            var configRoot = (new ConfigurationBuilder())
                             .SetBasePath(Directory.GetCurrentDirectory())
                             .AddJsonFile("appsettings.json")
                             .Build();

            // read the config settings from the appsettings.json file
            string availableLoginADDomains = configRoot.GetValue <string>("ActiveDirectory.LoginDomains")?.Trim();
            string userSearchDomain        = configRoot.GetValue <string>("ActiveDirectory.UserSearchDomain")?.Trim();
            string adApplicationRolePrefix = configRoot.GetValue <string>("ActiveDirectory.ApplicationRolePrefix")?.Trim();

            if (string.IsNullOrWhiteSpace(availableLoginADDomains) ||
                string.IsNullOrWhiteSpace(userSearchDomain) ||
                string.IsNullOrWhiteSpace(adApplicationRolePrefix))
            {
                throw new Exception("Could not read all the Active Directory config parameters from the config file.");
            }

            // create the ActiveDirectoryConfig object, with its values read from the config file
            var config = new ActiveDirectoryConfig();

            config.LoginDomains          = availableLoginADDomains.Split(',').Select(s => s.Trim().ToUpper()).ToArray();
            config.UserSearchDomain      = userSearchDomain;
            config.ApplicationRolePrefix = adApplicationRolePrefix;

            return(config);
        }
示例#2
0
        private void CanCreateNonPopulateOnlyAndDeleteRemoteAppService()
        {
            using (var undoContext = UndoContext.Current)
            {
                undoContext.Start();

                var client = GetRemoteAppManagementClient();

                string           name = TestUtilities.GenerateName("ghut");
                string           activeDirectoryName = TestUtilities.GenerateName("ghut");
                string           billingPlanName     = "Standard";
                string           templateName        = TestUtilities.GenerateName("ghut"); // BUGBUG this must be a real template
                HttpStatusCode[] statusSuccess       = { HttpStatusCode.OK, HttpStatusCode.Accepted };

                ActiveDirectoryConfig adDetails = new ActiveDirectoryConfig()
                {
                    DomainName = activeDirectoryName,
                    UserName   = "******",
                    Password   = "******"
                };

                CollectionCreationDetails collectionDetails = new CollectionCreationDetails()
                {
                    Name               = name,
                    AdInfo             = adDetails,
                    PlanName           = billingPlanName,
                    TemplateImageName  = templateName,
                    Description        = "OneSDK test created.",
                    Mode               = CollectionMode.Apps,
                    ReadyForPublishing = true,
                    VNetName           = "SomeVnet"
                };

                CollectionResult queriedCollection = null;

                OperationResultWithTrackingId result = client.Collections.Create(false, collectionDetails);
                Assert.NotNull(result);
                Assert.Contains(result.StatusCode, statusSuccess);

                if (result.StatusCode == HttpStatusCode.Accepted)
                {
                    //                    RemoteAppManagementClient.WaitForLongRunningOperation(result.TrackingId, timeoutMs, client);
                    Assert.True(result.StatusCode == HttpStatusCode.OK, "Failed to create collection.");
                }

                queriedCollection = client.Collections.Get(collectionDetails.Name);
                Assert.Equal(queriedCollection.Collection.AdInfo.DomainName, collectionDetails.AdInfo.DomainName);
                Assert.Equal(queriedCollection.Collection.PlanName, collectionDetails.PlanName);
                Assert.Equal(queriedCollection.Collection.TemplateImageName, collectionDetails.TemplateImageName);
                Assert.Equal(queriedCollection.Collection.Mode, collectionDetails.Mode);
                Assert.Equal(queriedCollection.Collection.VNetName, collectionDetails.VNetName);
                Assert.Equal(queriedCollection.Collection.Description, collectionDetails.Description);
                Assert.Equal(queriedCollection.Collection.ReadyForPublishing, collectionDetails.ReadyForPublishing);

                OperationResultWithTrackingId response = client.Collections.Delete(queriedCollection.Collection.Name);
                Assert.True(result.StatusCode == HttpStatusCode.OK, "Delete collection did not return OK.");
            }
        }
示例#3
0
        private Collection CreateNewServiceWithPopulateOnlyTrue(RemoteAppManagementClient client)
        {
            string name = "hsut2861";
            string activeDirectoryName = "ghutad";
            string billingPlanName     = "Standard";
            string templateName        = "bluerefresh.2014.08.21.vhd"; //GetReadyTemplateImageName(client);

            ActiveDirectoryConfig adDetails = new ActiveDirectoryConfig()
            {
                DomainName = activeDirectoryName,
                UserName   = "******",
                Password   = "******"
            };

            CollectionCreationDetails collectionDetails = new CollectionCreationDetails()
            {
                Name               = name,
                AdInfo             = adDetails,
                PlanName           = billingPlanName,
                TemplateImageName  = templateName,
                Description        = "OneSDK test created.",
                Mode               = CollectionMode.Apps,
                ReadyForPublishing = true,
                VNetName           = "SomeVnet"
            };

            OperationResultWithTrackingId result = null;

            Assert.DoesNotThrow(() =>
            {
                result = client.Collections.Create(true, collectionDetails);
            });

            Assert.NotNull(result);

            // if OK is returned then the tracking id is the name of the newly created collection
            Assert.Equal(HttpStatusCode.OK, result.StatusCode);

            Assert.NotNull(result.TrackingId);

            // now check if the object is actually created at the backend
            CollectionResult queriedService = client.Collections.Get(collectionDetails.Name);

            Assert.Equal(HttpStatusCode.OK, queriedService.StatusCode);
            Assert.Equal(queriedService.Collection.Name, name);
            Assert.Equal(queriedService.Collection.PlanName, collectionDetails.PlanName);
            Assert.Equal(queriedService.Collection.TemplateImageName, collectionDetails.TemplateImageName);
            Assert.Equal(queriedService.Collection.Status, "Creating");

            return(queriedService.Collection);
        }
        private static LdapConnection CreateConnection(ActiveDirectoryConfig config)
        {
            var identifier = new LdapDirectoryIdentifier(config.Server, config.Port);
            var connection = new LdapConnection(identifier);

            connection.SessionOptions.SecureSocketLayer       = true;
            connection.SessionOptions.VerifyServerCertificate = ServerCallback;
            connection.Credential = new NetworkCredential(config.Username, config.Password);
            connection.AuthType   = AuthType.Negotiate;

            connection.Bind();

            return(connection);
        }
        public static PrincipalContext CreateContext(ActiveDirectoryConfig config)
        {
            var context = new PrincipalContext(
                ContextType.Domain,
                config.Server,
                config.DistinguishedName,
                ContextOptions.Negotiate,
                config.Username,
                config.Password);

            if (!context.ValidateCredentials(config.Username, config.Password, ContextOptions.Negotiate))
            {
                throw new InvalidOperationException("Failed to validate username / password credentials.");
            }

            return(context);
        }
        public async void GetConfigurationTest()
        {
            // arrage
            var storage           = new MemoryStorage();
            var userState         = new UserState(storage);
            var conversationState = new ConversationState(storage);
            var adapter           = new TestAdapter().Use(new AutoSaveStateMiddleware(conversationState));
            var dialogState       = conversationState.CreateProperty <DialogState>("dialogState");
            var dialogs           = new DialogSet(dialogState);
            var steps             = new WaterfallStep[]
            {
                async(step, cancellationToken) =>
                {
                    await step.Context.SendActivityAsync("response");

                    // act
                    IActiveDirectoryService activeDirectoryService = new ActiveDirectoryService(EnvironmentName, ContentRootPath);
                    ActiveDirectoryConfig   config = activeDirectoryService.GetConfiguration();

                    // assert
                    Assert.Equal(configuration.ValidAudience, config.ValidAudience);
                    Assert.Equal(configuration.ValidIssuer, config.ValidIssuer);

                    return(Dialog.EndOfTurn);
                }
            };

            dialogs.Add(new WaterfallDialog(
                            "test",
                            steps));

            await new TestFlow(adapter, async(turnContext, cancellationToken) =>
            {
                var dc = await dialogs.CreateContextAsync(turnContext, cancellationToken);
                await dc.ContinueDialogAsync(cancellationToken);
                if (!turnContext.Responded)
                {
                    await dc.BeginDialogAsync("test", null, cancellationToken);
                }
            })
            .Send("ask")
            .AssertReply("response")
            .StartTestAsync();
        }
        public ActiveDirectoryService(string environmentName, string contentRootPath)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(contentRootPath)
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                          .AddJsonFile($"appsettings.{environmentName}.json", optional: true)
                          .AddEnvironmentVariables();

            var configuration = builder.Build();

            config = new ActiveDirectoryConfig();
            configuration.GetSection("ActiveDirectoryConfig").Bind(config);

            if (string.IsNullOrEmpty(config.ValidAudience))
            {
                throw new ArgumentException("Missing value in ActiveDirectoryConfig -> ValidAudience");
            }

            if (string.IsNullOrEmpty(config.ValidIssuer))
            {
                throw new ArgumentException("Missing value in ActiveDirectoryConfig -> ValidIssuer");
            }
        }
示例#8
0
        public IList <DirectoryEntry> GetVmAdStaleEntries(IList <RemoteAppVm> vmList, ActiveDirectoryConfig adConfig, PSCredential credential)
        {
            Dictionary <string, string> vmPrefixes     = new Dictionary <string, string>();
            List <DirectoryEntry>       staleVmEntries = null;

            foreach (RemoteAppVm vm in vmList)
            {
                string vmNamePrefix = vm.VirtualMachineName.Substring(0, 8);

                // for each VM group with the same 8-character prefix, find the "minimum" VM name.
                // i.g, for VMs "abcdefgh0004", "abcdefgh0002", "abcdefgh0005", "abcdefgh0003" the minimum will be "abcdefgh0002"
                // this will be used later to determine which AD entries are stale
                // because each staleVMName < MIN(existingVMName) using regular case-insensitive alphanumerical comparison
                if (vmPrefixes.ContainsKey(vmNamePrefix))
                {
                    if (String.Compare(vm.VirtualMachineName, vmPrefixes[vmNamePrefix], StringComparison.OrdinalIgnoreCase) < 0)
                    {
                        vmPrefixes[vmNamePrefix] = vm.VirtualMachineName;
                    }
                }
                else
                {
                    vmPrefixes.Add(vmNamePrefix, vm.VirtualMachineName);
                }
            }

            staleVmEntries = new List <DirectoryEntry>();

            foreach (string vmNamePrefix in vmPrefixes.Keys)
            {
                IList <DirectoryEntry> adEntries = ActiveDirectoryHelper.GetVmAdEntries(
                    adConfig.DomainName,
                    adConfig.OrganizationalUnit,
                    vmNamePrefix,
                    credential);

                string maxName = vmPrefixes[vmNamePrefix];

                foreach (DirectoryEntry adEntry in adEntries)
                {
                    string name = ActiveDirectoryHelper.GetCN(adEntry);

                    if ((name.Length == AdHelper.VMNameLength) && (String.Compare(name, maxName, StringComparison.OrdinalIgnoreCase) < 0))
                    {
                        staleVmEntries.Add(adEntry);
                    }
                }
            }

            return(staleVmEntries);
        }
 private void ValidateAD(RemoteAppManagementClient client, ActiveDirectoryConfig adConfig)
 {
     AssertNotNullOrEmpty(adConfig.DomainName);
     AssertNotNullOrEmpty(adConfig.UserName);
 }
示例#10
0
 public CreateTestUsersProcess(ActiveDirectoryConfig config)
 {
     _config     = config;
     _connection = CreateConnection(_config);
     _context    = CreateContext(_config);
 }