/// <summary>
 /// Demonstrates how to authenticate using web services.
 /// Assumes that the account is a local account not using Secret Server Online.
 /// </summary>
 public void SampleAuthenticateInstalledNoDomain()
 {
     //Use a basic HTTP binding for SOAP.
     var binding = new BasicHttpBinding();
     //Create an endpoint for the URI.
     var endpoint = new EndpointAddress(_webserviceURL);
     var soapClient = new SSWebServiceSoapClient(binding, endpoint);
     var result = soapClient.Authenticate("theUserName", "thePassword", string.Empty, string.Empty);
     if (result.Errors.Length > 0)
     {
         //Authentication failed. The Errors array contains the reason(s).
     }
     //Successful
     else
     {
         var token = result.Token;
         //token is the authenticate token.
     }
 }
        /// <summary>
        /// Demonstrates how to authenticate using web services.
        /// Assumes that the account is a domain account on domain "example".
        /// </summary>
        public void SampleAuthenticateInstalledWithDomain()
        {
            //Use a basic HTTP binding for SOAP.
            var binding = new BasicHttpBinding();
            //Create an endpoint for the URI.
            var endpoint   = new EndpointAddress(_webserviceURL);
            var soapClient = new SSWebServiceSoapClient(binding, endpoint);
            var result     = soapClient.Authenticate("theUserName", "thePassword", string.Empty, "example");

            if (result.Errors.Length > 0)
            {
                //Authentication failed. The Errors array contains the reason(s).
            }
            //Successful
            else
            {
                var token = result.Token;
                //token is the authenticate token.
            }
        }
        /// <summary>
        /// Example on how to validate a token
        /// </summary>
        public void ValidateTokenIsStillValid()
        {
            //Use a basic HTTP binding for SOAP.
            var binding = new BasicHttpBinding();
            //Create an endpoint for the URI.
            var endpoint           = new EndpointAddress(_webserviceURL);
            var soapClient         = new SSWebServiceSoapClient(binding, endpoint);
            var authenticateResult = soapClient.Authenticate("theUserName", "thePassword", string.Empty, string.Empty);
            //Assume authentication was successful.
            var token = authenticateResult.Token;
            var isValidTokenResult = soapClient.GetTokenIsValid(token);

            if (isValidTokenResult.Errors.Length == 0)
            {
                //Token is still valid
            }
            else
            {
                //Token is invalid. The Errors property on isValidTokenResult contains the reason.
            }
        }
        /// <summary>
        /// Displays a Secret by Secret ID
        /// </summary>
        public void DisplaySecret()
        {
            //Use a basic HTTP binding for SOAP.
            var binding = new BasicHttpBinding();
            //Create an endpoint for the URI.
            var endpoint   = new EndpointAddress(_webserviceURL);
            var soapClient = new SSWebServiceSoapClient(binding, endpoint);
            var result     = soapClient.Authenticate("theUserName", "thePassword", string.Empty, string.Empty);

            if (result.Errors.Length > 0)
            {
                //Authentication failed. The Errors array contains the reason(s).
            }
            //Successful
            else
            {
                var token = result.Token;
                //The ID of the Secret. Obtain the ID through other web service methods.
                var secretId        = 1;
                var getSecretResult = soapClient.GetSecretLegacy(token, secretId);
                if (getSecretResult.Errors.Length > 0)
                {
                    //Failed to get the secret. The Errors array contains the reason(s).
                }
                else
                {
                    //The display name of the Secret
                    var secretName = getSecretResult.Secret.Name;
                    //The items of the secret
                    var items = getSecretResult.Secret.Items;
                    foreach (var item in items)
                    {
                        //The display name of the field.
                        var fieldName = item.FieldDisplayName;
                        //The value of the field.
                        var fieldValue = item.Value;
                    }
                }
            }
        }
 /// <summary>
 /// Displays a Secret by Secret ID
 /// </summary>
 public void DisplaySecret()
 {
     //Use a basic HTTP binding for SOAP.
     var binding = new BasicHttpBinding();
     //Create an endpoint for the URI.
     var endpoint = new EndpointAddress(_webserviceURL);
     var soapClient = new SSWebServiceSoapClient(binding, endpoint);
     var result = soapClient.Authenticate("theUserName", "thePassword", string.Empty, string.Empty);
     if (result.Errors.Length > 0)
     {
         //Authentication failed. The Errors array contains the reason(s).
     }
     //Successful
     else
     {
         var token = result.Token;
         //The ID of the Secret. Obtain the ID through other web service methods.
         var secretId = 1;
         var getSecretResult = soapClient.GetSecretLegacy(token, secretId);
         if (getSecretResult.Errors.Length > 0)
         {
             //Failed to get the secret. The Errors array contains the reason(s).
         }
         else
         {
             //The display name of the Secret
             var secretName = getSecretResult.Secret.Name;
             //The items of the secret
             var items = getSecretResult.Secret.Items;
             foreach (var item in items)
             {
                 //The display name of the field.
                 var fieldName = item.FieldDisplayName;
                 //The value of the field.
                 var fieldValue = item.Value;
             }
         }
     }
 }
        public void SearchSecrets()
        {
            //Use a basic HTTP binding for SOAP.
            var binding = new BasicHttpBinding();
            //Create an endpoint for the URI.
            var endpoint   = new EndpointAddress(_webserviceURL);
            var soapClient = new SSWebServiceSoapClient(binding, endpoint);
            var result     = soapClient.Authenticate("theUserName", "thePassword", string.Empty, string.Empty);

            if (result.Errors.Length > 0)
            {
                //Authentication failed. The Errors array contains the reason(s).
            }
            //Successful
            else
            {
                var token = result.Token;
                //Search for all secrets that contain "Hello" in them.
                var searchResult = soapClient.SearchSecretsLegacy(token, "Hello");
                if (searchResult.Errors.Length > 0)
                {
                    //Failed to get the secret. The Errors array contains the reason(s).
                }
                else
                {
                    foreach (var summary in searchResult.SecretSummaries)
                    {
                        //The Secret's name
                        var secretName = summary.SecretName;
                        //The name of the Template
                        var templateName = summary.SecretTypeName;
                        //The ID of the Secret. Can be used in GetSecret to obtain more information
                        var secretId = summary.SecretId;
                    }
                }
            }
        }
Пример #7
0
        private static void Main()
        {
            var service = new SSWebServiceSoapClient();
            Console.WriteLine("username:"******"password:"******"";
            ConsoleKeyInfo key;

            do
            {
                key = Console.ReadKey(true);
                // Backspace Should Not Work
                if (key.Key != ConsoleKey.Backspace && key.Key != ConsoleKey.Enter)
                {
                    password += key.KeyChar;
                    Console.Write("*");
                }
                else
                {
                    if (key.Key == ConsoleKey.Backspace && password.Length > 0)
                    {
                        password = password.Substring(0, (password.Length - 1));
                        Console.Write("\b \b");
                    }
                }
            }
            // Stops Receving Keys Once Enter is Pressed
            while (key.Key != ConsoleKey.Enter);
            Console.WriteLine();
            Console.WriteLine("org:");
            var org = Console.ReadLine();
            Console.WriteLine();
            Console.WriteLine("dry run (y/n):");
            var dryRun = Console.ReadLine();
            Console.Clear();
            Console.WriteLine("authenticating...");
            var result = service.Authenticate(username, password, org, "");
            var authToken = result.Token;
            Console.Clear();
            Console.WriteLine("getting secrets...");
            var summaries = service.SearchSecrets(authToken, "").SecretSummaries;
            Console.Clear();
            Console.WriteLine("getting templates...");
            var me = service.GetSecretTemplates(authToken).SecretTemplates;
            var templates = new List<TemplateCount>();
            Console.Clear();
            Console.Write("checking templates");
            var templateStringBuilder = new StringBuilder();
            var secretStringBuilder = new StringBuilder();
            secretStringBuilder.AppendLine("{\"d\":[");
            var log = new StringBuilder();

            Console.Clear();
            var browser = new IE("https://lionlock.com/App/Account/Login");
            Console.WriteLine("Login then press enter.");
            Console.ReadLine();
            Console.Clear();
            var favorites = service.GetFavorites(authToken);
            var converter = new SecretConverter(browser, dryRun.ToLower() == "y", favorites.SecretSummaries, log);

            foreach (var secretSummary in summaries)
            {
                var percent = (int) ((Array.IndexOf(summaries, secretSummary)/(double) summaries.Length)*100);
                RenderConsoleProgress(percent, '+', ConsoleColor.Green, "Loading Secrets, " + percent + "% Completed (" + secretSummary.SecretName + ")");
                var secret = service.GetSecret(authToken, secretSummary.SecretId);
                var template = me.First(t => t.Id == secretSummary.SecretTypeId);

                converter.Convert(template.Name, secret.Secret);

                if (secret.Secret.Items.Any(item => item.IsFile))
                {
                    log.AppendLine(secret.Secret.Name + " has a file (" + template.Name + ").");
                }
                if (templates.All(t => t.Name != template.Name))
                {
                    secretStringBuilder.AppendLine(secret.ToJson());
                    templates.Add(new TemplateCount {Name = template.Name, Count = 1});
                    templateStringBuilder.AppendLine(template.ToJson());
                }
                else
                {
                    templates.First(t => t.Name == template.Name).Count++;
                }
                secretStringBuilder.AppendLine(",");
            }

            RenderConsoleProgress(100, '+', ConsoleColor.Green, "Loading Secrets, 100% Completed");
            Console.Clear();
            secretStringBuilder.AppendLine("]}");
            var text = "";
            foreach (var template in templates)
            {
                text = text + string.Format("{0} ({1})", template.Name, template.Count);
                Console.Out.WriteLine("{0} ({1})", template.Name, template.Count);

                text = text + "\n";
            }
            Console.ReadLine();
            //File.WriteAllText("D:\\SecretStats.txt", text);
            File.WriteAllText("D:\\Log.txt", log.ToString());
            //File.WriteAllText("D:\\TemplateExport.txt", templateStringBuilder.ToString());
            //File.WriteAllText("D:\\SecretExport.json", secretStringBuilder.ToString());
        }
 /// <summary>
 /// Example on how to validate a token
 /// </summary>
 public void ValidateTokenIsStillValid()
 {
     //Use a basic HTTP binding for SOAP.
     var binding = new BasicHttpBinding();
     //Create an endpoint for the URI.
     var endpoint = new EndpointAddress(_webserviceURL);
     var soapClient = new SSWebServiceSoapClient(binding, endpoint);
     var authenticateResult = soapClient.Authenticate("theUserName", "thePassword", string.Empty, string.Empty);
     //Assume authentication was successful.
     var token = authenticateResult.Token;
     var isValidTokenResult = soapClient.GetTokenIsValid(token);
     if (isValidTokenResult.Errors.Length == 0)
     {
         //Token is still valid
     }
     else
     {
         //Token is invalid. The Errors property on isValidTokenResult contains the reason.
     }
 }
 public void SearchSecrets()
 {
     //Use a basic HTTP binding for SOAP.
     var binding = new BasicHttpBinding();
     //Create an endpoint for the URI.
     var endpoint = new EndpointAddress(_webserviceURL);
     var soapClient = new SSWebServiceSoapClient(binding, endpoint);
     var result = soapClient.Authenticate("theUserName", "thePassword", string.Empty, string.Empty);
     if (result.Errors.Length > 0)
     {
         //Authentication failed. The Errors array contains the reason(s).
     }
     //Successful
     else
     {
         var token = result.Token;
         //Search for all secrets that contain "Hello" in them.
         var searchResult = soapClient.SearchSecretsLegacy(token, "Hello");
         if (searchResult.Errors.Length > 0)
         {
             //Failed to get the secret. The Errors array contains the reason(s).
         }
         else
         {
             foreach (var summary in searchResult.SecretSummaries)
             {
                 //The Secret's name
                 var secretName = summary.SecretName;
                 //The name of the Template
                 var templateName = summary.SecretTypeName;
                 //The ID of the Secret. Can be used in GetSecret to obtain more information
                 var secretId = summary.SecretId;
             }
         }
     }
 }