コード例 #1
0
        /// <summary>
        /// Depending on the specific setup of the TFS server, it may or may not accept credentials of specific type. To accommodate for that
        /// without making the configuration more complicated (by making the user explicitly set which type of credentials to use), we just
        /// provide a list of all the relevant credential types we support in order of priority, and when connecting to TFS, we can try them
        /// in order and just go with the first one that succeeds.
        ///
        /// If ServiceIdentityUsername and ServiceIdentityPasswordFile are set correctly, then we'll try to use those credentials first. Even
        /// then, though, they can be wrapped in different ways (e.g. SimpleWebTokenCredneitals, WindowsCredentials), and different servers
        /// may prefer one over the other.
        ///
        /// As a last resort, we always try the default credentials as well
        /// </summary>
        private IEnumerable <TfsClientCredentials> GetTfsCredentials()
        {
            var credentials = new List <TfsClientCredentials>();

            if (!string.IsNullOrWhiteSpace(_config.TfsServerConfig.ServiceIdentityUsername) &&
                !string.IsNullOrWhiteSpace(_config.TfsServerConfig.ServiceIdentityPasswordFile) &&
                File.Exists(_config.TfsServerConfig.ServiceIdentityPasswordFile))
            {
                try
                {
                    var password = DPAPIHelper.ReadDataFromFile(_config.TfsServerConfig.ServiceIdentityPasswordFile);

                    credentials.Add(
                        new TfsClientCredentials(
                            new SimpleWebTokenCredential(_config.TfsServerConfig.ServiceIdentityUsername, password)));
                    credentials.Add(
                        new TfsClientCredentials(
                            new WindowsCredential(
                                new NetworkCredential(_config.TfsServerConfig.ServiceIdentityUsername, password))));
                }
                catch (Exception e)
                {
                    throw new BadConfigException("ServiceIdentityUsername or ServiceIdentityPasswordFile", e.Message);
                }
            }

            credentials.Add(new TfsClientCredentials(true));

            return(credentials);
        }
コード例 #2
0
        public IMailboxManager CreateMailboxManager(Config.EmailSettings emailSettings)
        {
            var credentials = new EWSConnectionManger.Credentials
            {
                EmailAddress = emailSettings.EWSMailboxAddress,
                UserName     = emailSettings.EWSUsername,
                Password     = DPAPIHelper.ReadDataFromFile(emailSettings.EWSPasswordFile)
            };

            var exchangeService = _connectionManger.GetConnection(credentials);
            var postProcessor   = GetPostProcesor(emailSettings, exchangeService.Service);

            switch (emailSettings.ServiceType)
            {
            case Config.EmailSettings.MailboxServiceType.EWSByFolder:
                return(new FolderMailboxManager(
                           exchangeService.Service,
                           emailSettings.IncomingFolder,
                           postProcessor));

            case Config.EmailSettings.MailboxServiceType.EWSByRecipients:

                return(new RecipientsMailboxManager(
                           exchangeService.Router,
                           ParseDelimitedList(emailSettings.Recipients, ';'),
                           postProcessor));

            default:
                throw new BadConfigException(
                          "EmailSettings.ServiceType",
                          string.Format("Invalid mailbox service type defined in config ({0})", emailSettings.ServiceType));
            }
        }
コード例 #3
0
ファイル: DPAPIUnitTests.cs プロジェクト: Cadacious/Mail2Bug
        public void TestSimpleEncryptionSucceedsMachineScope()
        {
            var sourceString = "Hello world!@#";

            var encryptedData   = DPAPIHelper.Encrypt(sourceString, null, DataProtectionScope.LocalMachine);
            var decryptedString = DPAPIHelper.Decrypt(encryptedData, null, DataProtectionScope.LocalMachine);

            Assert.AreEqual <string>(sourceString, decryptedString);
        }
コード例 #4
0
        private string GetPatFromConfig()
        {
            if (string.IsNullOrWhiteSpace(_config.TfsServerConfig.ServiceIdentityPatFile))
            {
                return(null);
            }

            if (!File.Exists(_config.TfsServerConfig.ServiceIdentityPatFile))
            {
                throw new BadConfigException("ServiceIdentityPatFile", "Personal Access Token file doesn't exist");
            }

            return(DPAPIHelper.ReadDataFromFile(_config.TfsServerConfig.ServiceIdentityPatFile));
        }
コード例 #5
0
ファイル: TFSWorkItemManager.cs プロジェクト: liaxu/mail2bug
        private Tuple <string, string> GetUsernameAndPasswordFromConfig()
        {
            if (string.IsNullOrWhiteSpace(_config.TfsServerConfig.ServiceIdentityUsername) ||
                string.IsNullOrWhiteSpace(_config.TfsServerConfig.ServiceIdentityPasswordFile))
            {
                return(null);
            }

            if (!File.Exists(_config.TfsServerConfig.ServiceIdentityPasswordFile))
            {
                throw new BadConfigException("ServiceIdentityPasswordFile", "Password file doesn't exist");
            }

            return(new Tuple <string, string>(_config.TfsServerConfig.ServiceIdentityUsername,
                                              DPAPIHelper.ReadDataFromFile(_config.TfsServerConfig.ServiceIdentityPasswordFile)));
        }
コード例 #6
0
        private Tuple <string, string> GetAltAuthUsernameAndPasswordFromConfig()
        {
            if (string.IsNullOrWhiteSpace(_config.TfsServerConfig.AltAuthUsername) ||
                string.IsNullOrWhiteSpace(_config.TfsServerConfig.AltAuthPasswordFile))
            {
                return(null);
            }

            if (!File.Exists(_config.TfsServerConfig.AltAuthPasswordFile))
            {
                throw new BadConfigException("AltAuthPasswordFile", "Alt password file doesn't exist");
            }

            return(new Tuple <string, string>(
                       _config.TfsServerConfig.AltAuthUsername,
                       DPAPIHelper.ReadDataFromFile(_config.TfsServerConfig.AltAuthPasswordFile, _config.TfsServerConfig.EncryptionScope)));
        }
コード例 #7
0
            public override void Execute()
            {
                string readDataFromFile = DPAPIHelper.ReadDataFromFile(Filename);

                Console.WriteLine("Data:'{0}'", readDataFromFile);
            }
コード例 #8
0
 public override void Execute()
 {
     DPAPIHelper.WriteDataToFile(Data, Out);
 }