Exemple #1
0
 public EOCInfoService(string username, string password)
 {
     _endpoint           = Settings.Default.EOCEndpointPath;
     _endpointConfigName = "EOCTcpBinding_InformationServicev2";
     _binding            = new NetTcpBinding("Windows");
     _credentials        = new WindowsCredential(username, password);
 }
 public OrionInfoServiceWindowsCompressed(string username, string password, bool v3 = false)
 {
     _endpoint           = v3 ? Settings.Default.OrionV3EndpointPathADCompressed : Settings.Default.OrionEndpointPathADCompressed;
     _endpointConfigName = "OrionWindowsTcpBindingCompressed";
     _binding            = new CustomBinding("CompressedWindows");
     _credentials        = new WindowsCredential(username, password);
 }
Exemple #3
0
 public OrionInfoServiceWindows(string username, string password, bool v3 = false)
 {
     _endpoint           = v3 ? Settings.Default.OrionV3EndpointPathAD : Settings.Default.OrionEndpointPathAD;
     _endpointConfigName = "OrionWindowsTcpBinding";
     _binding            = new NetTcpBinding("Windows");
     _credentials        = new WindowsCredential(username, password);
 }
Exemple #4
0
        public IActionResult Edit(string id, [FromForm] WindowsCredential cred)
        {
            var theTarget = _fakeCredentials.Find(c => c.Username == id);

            theTarget.Username = cred.Username;
            return(RedirectToAction(nameof(Index)));
        }
Exemple #5
0
        public TelegramBot()
        {
            mBotToken = WindowsCredential.GetTelegramCredential(mBotName).Token;

            mTokenGroupChat = WindowsCredential.GetTelegramCredential(mGroupBotName).Token;
            mGroupChatId    = WindowsCredential.GetTelegramCredential(mGroupBotName).ChatId;

            mTokenSuperGroupChat = WindowsCredential.GetTelegramCredential(mSuperGroupBotName).Token;
            mSuperGroupChatId    = WindowsCredential.GetTelegramCredential(mSuperGroupBotName).ChatId;
        }
        /// <summary>
        ///		Conecta a un servidor
        /// </summary>
        public void Connect()
        {
            WindowsCredential    objWindowsCredentials = new WindowsCredential(new NetworkCredential(User.Login, User.Pasword));
            TfsClientCredentials objCredentials        = new TfsClientCredentials(objWindowsCredentials);

            // Cierra la conexión
            Close();
            // Crea una conexión
            tfsTeamProject = new TfsTeamProjectCollection(Server.FullUrl, objCredentials);
            // Autentifica
            tfsTeamProject.Authenticate();
        }
Exemple #7
0
        internal static WindowsCredentialWrapper GetInstance()
        {
            var real = new WindowsCredential();

            RealInstanceFactory(ref real);
            var instance = (WindowsCredentialWrapper)WindowsCredentialWrapper.GetWrapper(real);

            InstanceFactory(ref instance);
            if (instance == null)
            {
                Assert.Inconclusive("Could not Create Test Instance");
            }
            return(instance);
        }
        /// <summary>
        /// Asynchronously initializes the sink.
        /// </summary>
        /// <param name="name">The configuration name of the sink.</param>
        /// <param name="cancellationToken">A token to monitor for cancellation requests. The default value is <see cref="System.Threading.CancellationToken.None" />.</param>
        /// <returns>
        /// A <see cref="Task" /> that represents the asynchronous initialize operation.
        /// </returns>
        public async Task InitializeAsync(
            string name,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            await Task.Delay(0);

            var element = Configuration.TfsConfigurationSection.Current.Sinks[name];

            searchString = element.SearchString;
            projectName  = element.Project;
            searchPeriod = TimeSpan.FromDays(element.SearchPeriodDays);

            // todo: support other auth methods, see the auth samples in https://www.visualstudio.com/en-us/integrate/get-started/client-libraries/samples
            // * OAuth
            // * ADD
            //var vssCredentials = new VssCredentials(); // Active directory auth - NTLM against a Team Foundation Server
            //var vssCredentials = new VssClientCredentials(); // Visual Studio sign-in prompt. Would need work to make this not prompt at every startup

            VssCredentials vssCredentials;

            switch (element.LoginMethod)
            {
            case 1:
                /* this is basic auth if on tfs2015 */
                // Ultimately you want a VssCredentials instance so...
                NetworkCredential netCred = new NetworkCredential(element.Username, element.Password);
                WindowsCredential winCred = new WindowsCredential(netCred);
                vssCredentials = new VssClientCredentials(winCred);

                // Bonus - if you want to remain in control when
                // credentials are wrong, set 'CredentialPromptType.DoNotPrompt'.
                // This will thrown exception 'TFS30063' (without hanging!).
                // Then you can handle accordingly.
                vssCredentials.PromptType = CredentialPromptType.DoNotPrompt;
                /*********************************************************************/
                break;

            default:
                vssCredentials = new VssBasicCredential("", element.AccessToken);
                break;
            }

            var connection = new VssConnection(new Uri(element.ProjectCollection), vssCredentials);

            _witClient = connection.GetClient <WorkItemTrackingHttpClient>();
        }
Exemple #9
0
        /// <summary>
        /// The get catalog nodes.
        /// </summary>
        /// <param name="uri">
        /// The uri.
        /// </param>
        /// <returns>
        /// The <see cref="List"/>.
        /// </returns>
        private List <CatalogNode> GetCatalogNodes(Uri uri, ICredentials cred, bool anotherUser)
        {
            List <CatalogNode> catalogNodes = null;

            try
            {
                connectUri = uri;
                TfsClientCredentials tfsClientCredentials;
                if (anotherUser)
                {
                    tfsClientCredentials = new TfsClientCredentials(false);
                    ICredentialsProvider provider = new UICredentialsProvider();
                    WindowsCredential    wcred    = new WindowsCredential(cred, provider);
                    tfsClientCredentials.Windows = wcred;
                    //Credential = tfsClientCredentials;
                }
                else
                {
                    tfsClientCredentials = new TfsClientCredentials(true);
                    ICredentialsProvider provider = new UICredentialsProvider();
                    WindowsCredential    wcred    = new WindowsCredential(cred, provider);
                    tfsClientCredentials.Windows = wcred;
                }

                using (TfsConfigurationServer serverConfig = new TfsConfigurationServer(uri, tfsClientCredentials))
                {
                    serverConfig.EnsureAuthenticated();
                    if (serverConfig.HasAuthenticated)
                    {
                        Credential   = serverConfig.Credentials;
                        catalogNodes = serverConfig.CatalogNode.QueryChildren(new[] { CatalogResourceTypes.ProjectCollection }, false, CatalogQueryOptions.None).OrderBy(f => f.Resource.DisplayName).ToList();
                    }
                }
            }
            catch (TeamFoundationServiceUnavailableException ex)
            {
                MessageBox.Show(ResourceHelper.GetResourceString("MSG_TFS_SERVER_IS_INACCESSIBLE") + "\n" + uri.OriginalString, ResourceHelper.GetResourceString("ERROR_TEXT"), MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ResourceHelper.GetResourceString("ERROR_TEXT"), MessageBoxButton.OK, MessageBoxImage.Error);
                return(catalogNodes);
            }

            return(catalogNodes);
        }
        public Task <VssCredentials> CreateCredentials()
        {
            VssCredentials credentials;

            switch (options.Mode)
            {
            case AuthMode.Pat:
                credentials = new VssBasicCredential(string.Empty, options.Pat);
                break;

            case AuthMode.Windows:
                credentials = new WindowsCredential();
                break;

            default:
                throw new NotImplementedException($"Invalid authentication mode `{options.Mode}`");
            }

            return(Task.FromResult(credentials));
        }
Exemple #11
0
        public bool ConnectToTFS(string tfsUrl)
        {
            string username = Utils.GetConfig(AppConstants.TFS_USERNAME);
            string password = Utils.GetConfig(AppConstants.TFS_PASSWORD);

            if (username.IsNullOrEmpty() || password.IsNullOrEmpty())
            {
                throw new Exception("Please set tfs credential in app.config.");
            }
            if (IsConnected)
            {
                return(true);
            }
            try
            {
                int tryTimes = 10;
                while (--tryTimes > 0)
                {
                    WindowsCredential    wCre    = new WindowsCredential(new NetworkCredential(username, password));
                    TfsClientCredentials tfsCred = new TfsClientCredentials(wCre)
                    {
                        AllowInteractive = false
                    };
                    TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(tfsUrl), tfsCred);
                    tpc.Authenticate();
                    _workItemStore        = tpc.GetService <WorkItemStore>();
                    _versionControlServer = tpc.GetService <VersionControlServer>();
                    IsConnected           = true;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            IsConnected = false;
            return(false);
        }
Exemple #12
0
        protected override void ProcessRecord()
        {
            var asset = new AssetDto
            {
                Name       = Name,
                ValueScope = AssetDtoValueScope.Global
            };

            switch (ParameterSetName)
            {
            case NewAssetRobotValue.TextValueSet:

                asset.ValueType   = AssetDtoValueType.Text;
                asset.StringValue = TextValue;
                break;

            case NewAssetRobotValue.IntValueSet:

                asset.ValueType = AssetDtoValueType.Integer;
                asset.IntValue  = IntValue;
                break;

            case NewAssetRobotValue.BoolValueSet:
                asset.ValueType = AssetDtoValueType.Bool;
                asset.BoolValue = BoolValue;
                break;

            case NewAssetRobotValue.DBConnectionStringSet:
                asset.ValueType   = AssetDtoValueType.DBConnectionString;
                asset.StringValue = DBConnectionString;
                break;

            case NewAssetRobotValue.HttpConnectionStringSet:

                asset.ValueType   = AssetDtoValueType.HttpConnectionString;
                asset.StringValue = HttpConnectionString;
                break;

            case NewAssetRobotValue.KeyValueListSet:
                asset.ValueType    = AssetDtoValueType.KeyValueList;
                asset.KeyValueList = KeyValueList.ToKeyList();
                break;

            case NewAssetRobotValue.WindowsCredentialSet:
                asset.ValueType          = AssetDtoValueType.WindowsCredential;
                asset.CredentialUsername = WindowsCredential.UserName;
                asset.CredentialPassword = WindowsCredential.ExtractPassword();

                break;

            case NewAssetRobotValue.CredentialSet:
                asset.ValueType          = AssetDtoValueType.Credential;
                asset.CredentialUsername = Credential.UserName;
                asset.CredentialPassword = Credential.ExtractPassword();

                break;

            case RobotValuesSet:
                asset.ValueScope = AssetDtoValueScope.PerRobot;
                if (RobotValues.Any())
                {
                    asset.ValueType   = (AssetDtoValueType)Enum.Parse(typeof(AssetDtoValueType), RobotValues.First().ValueType.ToString());
                    asset.RobotValues = RobotValues.Select(rv => rv.ToDto()).ToList();
                }
                break;
            }

            var dto = HandleHttpOperationException(() => Api.Assets.Post(asset));

            WriteObject(Asset.FromDto(dto));
        }
Exemple #13
0
        private void ProcessDto(AssetDto dto)
        {
            if (dto.ValueScope == AssetDtoValueScope.Global && ParameterSetName != AddAsset.RobotValuesSet)
            {
                switch (ParameterSetName)
                {
                case NewAssetRobotValue.TextValueSet:
                    dto.ValueType   = AssetDtoValueType.Text;
                    dto.StringValue = TextValue;
                    break;

                case NewAssetRobotValue.IntValueSet:
                    dto.ValueType = AssetDtoValueType.Integer;
                    dto.IntValue  = IntValue;
                    break;

                case NewAssetRobotValue.BoolValueSet:
                    dto.ValueType = AssetDtoValueType.Bool;
                    dto.BoolValue = BoolValue;
                    break;

                case NewAssetRobotValue.DBConnectionStringSet:
                    dto.ValueType   = AssetDtoValueType.DBConnectionString;
                    dto.StringValue = DBConnectionString;
                    break;

                case NewAssetRobotValue.HttpConnectionStringSet:
                    dto.ValueType   = AssetDtoValueType.HttpConnectionString;
                    dto.StringValue = HttpConnectionString;
                    break;

                case NewAssetRobotValue.KeyValueListSet:
                    dto.ValueType    = AssetDtoValueType.KeyValueList;
                    dto.KeyValueList = KeyValueList.ToKeyList();
                    break;

                case NewAssetRobotValue.WindowsCredentialSet:
                    dto.ValueType          = AssetDtoValueType.WindowsCredential;
                    dto.CredentialUsername = WindowsCredential.UserName;
                    dto.CredentialPassword = WindowsCredential.ExtractPassword();
                    break;

                case NewAssetRobotValue.CredentialSet:
                    dto.ValueType          = AssetDtoValueType.Credential;
                    dto.CredentialUsername = Credential.UserName;
                    dto.CredentialPassword = Credential.ExtractPassword();
                    break;
                }
            }
            else if (dto.ValueScope == AssetDtoValueScope.PerRobot && ParameterSetName == AddAsset.RobotValuesSet)
            {
                dto.RobotValues = dto.RobotValues.MergeAddRemove(
                    AddRobotValues?.Select(rv => rv.ToDto()),                                        // Robot values to add to the list
                    RemoveRobotIdValues?.Select(rid => new AssetRobotValueDto {
                    RobotId = rid
                }),                                                                                 // Robot IDs to remove, expressed as AssetRobotValue for sake of MergeAddRemove.. IEnumerable<T> ...
                    rv => rv.RobotId)                                                               // T->K Key selector expression
                                  .ToList();
            }
            else
            {
                throw new RuntimeException("Mismatched parameters and asset scope");
            }
            HandleHttpOperationException(() => Api.Assets.PutById(dto.Id.Value, dto));
        }
 private static TfsClientCredentials CreateCredentials(string username, string password)
 {
     NetworkCredential netCred = new NetworkCredential(username, password);
     WindowsCredential windowsCredential = new WindowsCredential(netCred);
     TfsClientCredentials tfsCred = new TfsClientCredentials(windowsCredential) { AllowInteractive = false };
     return tfsCred;
 }
Exemple #15
0
        /// <summary>
        /// The get catalog nodes.
        /// </summary>
        /// <param name="uri">
        /// The uri.
        /// </param>
        /// <returns>
        /// The <see cref="List"/>.
        /// </returns>
        private List<CatalogNode> GetCatalogNodes(Uri uri, ICredentials cred, bool anotherUser)
        {
            List<CatalogNode> catalogNodes = null;
            try
            {

                connectUri = uri;
                TfsClientCredentials tfsClientCredentials;
                if (anotherUser)
                {
                    
                    tfsClientCredentials = new TfsClientCredentials(false);
                    ICredentialsProvider provider = new UICredentialsProvider();
                    WindowsCredential wcred = new WindowsCredential(cred, provider);
                    tfsClientCredentials.Windows = wcred;
                    //Credential = tfsClientCredentials;
                }
                else
                {
                    tfsClientCredentials = new TfsClientCredentials(true);
                    ICredentialsProvider provider = new UICredentialsProvider();
                    WindowsCredential wcred = new WindowsCredential(cred, provider);
                    tfsClientCredentials.Windows = wcred;
                }

                using (TfsConfigurationServer serverConfig = new TfsConfigurationServer(uri, tfsClientCredentials))
                {
                    serverConfig.EnsureAuthenticated();
                    if (serverConfig.HasAuthenticated)
                    {
                        Credential = serverConfig.Credentials;
                        catalogNodes = serverConfig.CatalogNode.QueryChildren(new[] { CatalogResourceTypes.ProjectCollection }, false, CatalogQueryOptions.None).OrderBy(f => f.Resource.DisplayName).ToList();
                    }
                }
            }
            catch (TeamFoundationServiceUnavailableException ex)
            {
                MessageBox.Show(ResourceHelper.GetResourceString("MSG_TFS_SERVER_IS_INACCESSIBLE") + "\n" + uri.OriginalString, ResourceHelper.GetResourceString("ERROR_TEXT"), MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ResourceHelper.GetResourceString("ERROR_TEXT"), MessageBoxButton.OK, MessageBoxImage.Error);
                return catalogNodes;
            }

            return catalogNodes;
        }
Exemple #16
0
 static partial void RealInstanceFactory(ref WindowsCredential real, [CallerMemberName] string callerName = "");
Exemple #17
0
        public IActionResult Create()
        {
            var model = new WindowsCredential();

            return(View(model));
        }
Exemple #18
0
 public IActionResult Create([FromForm] WindowsCredential cred)
 {
     _fakeCredentials.Add(cred);
     return(RedirectToAction(nameof(Index)));
 }
Exemple #19
0
        private void uploadFile(string userName, string password)
        {
            NetworkCredential netCred = new NetworkCredential(userName, password);
            WindowsCredential winCred = new WindowsCredential(netCred);
            VssCredentials    creds   = new VssClientCredentials(winCred);

            creds.Storage = new VssClientCredentialStorage();


            // Connect to VSTS
            VssConnection connection = new VssConnection(new Uri(c_collectionUri), creds);

            // Get a GitHttpClient to talk to the Git endpoints
            GitHttpClient gitClient = connection.GetClient <GitHttpClient>();

            // Get data about a specific repository
            var repo = gitClient.GetRepositoryAsync(c_projectName, c_repoName).GetAwaiter().GetResult();


            GitRef       branch    = gitClient.GetRefsAsync(repo.Id, filter: "heads/OfficeMarketing").GetAwaiter().GetResult().First();
            GitRefUpdate refUpdate = new GitRefUpdate()
            {
                Name        = $"refs/heads/OfficeMarketing",
                OldObjectId = branch.ObjectId,
            };
            GitCommitRef newCommit = new GitCommitRef()
            {
                Comment = "add Json and xml file",
                Changes = new GitChange[]
                {
                    new GitChange()
                    {
                        ChangeType = VersionControlChangeType.Add,
                        Item       = new GitItem()
                        {
                            Path = $"IRIS/Chatbot/Source/" + ChampaignNamelabel1.Text + "/" + ChampaignNamelabel1.Text + ".en-US.json"
                        },
                        NewContent = new ItemContent()
                        {
                            Content     = writeToJson(),
                            ContentType = ItemContentType.RawText,
                        }
                    },
                    new GitChange()
                    {
                        ChangeType = VersionControlChangeType.Add,
                        Item       = new GitItem()
                        {
                            Path = $"IRIS/Chatbot/Source/" + ChampaignNamelabel1.Text + "/ExceptionMarketReference.xml"
                        },
                        NewContent = new ItemContent()
                        {
                            Content     = writeToXml(),
                            ContentType = ItemContentType.RawText,
                        }
                    }
                },
            };
            // create the push with the new branch and commit
            GitPush push = gitClient.CreatePushAsync(new GitPush()

            {
                RefUpdates = new GitRefUpdate[] { refUpdate },

                Commits = new GitCommitRef[] { newCommit },
            }, repo.Id).GetAwaiter().GetResult();
        }