コード例 #1
0
        /// <summary>
        /// Export specified SSO application with specified key to specified file
        /// This code is borrowed from the MMC Snap-in for SSO
        /// </summary>
        private static void ExportSSOApp()
        {
            SSO sSO = new SSO(_databaseServer, _databaseName, _company);

            string[]      keys          = sSO.GetKeys(_appName);
            string[]      values        = sSO.GetValues(_appName);
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?><SSOApplicationExport><applicationData>");
            for (int i = 0; i < keys.Length; i++)
            {
                if (keys[i] != null && !(keys[i] == ""))
                {
                    stringBuilder.Append(string.Concat(new string[]
                    {
                        "<add key=\"",
                        keys[i],
                        "\" value=\"",
                        values[i],
                        "\" />"
                    }));
                }
            }
            stringBuilder.Append("</applicationData></SSOApplicationExport>");
            StreamWriter streamWriter = new StreamWriter(_encryptedFile, false);

            try
            {
                streamWriter.Write(sSO.Encrypt(stringBuilder.ToString(), _encryptedFileKey));
                streamWriter.Flush();
            }
            catch (Exception ex)
            {
                ConsoleColor currentColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error in export process: " + ex);
                Console.ForegroundColor = currentColor;
                return;
            }
            finally
            {
                streamWriter.Close();
                streamWriter.Dispose();
            }
        }
コード例 #2
0
        /// <summary>
        /// Display the keys + values for the specified SSO application
        /// </summary>
        private static void DetailSSOApp()
        {
            Console.WriteLine("Details of SSO application {0}", _appName);
            ConsoleColor currentColor = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Green;

            SSO sSO = new SSO(_databaseServer, _databaseName, _company);

            string[] keys   = sSO.GetKeys(_appName);
            string[] values = sSO.GetValues(_appName);
            for (int i = 0; i < keys.Length; i++)
            {
                Console.WriteLine("{0}\t - {1}", keys[i], values[i]);
            }
            Console.ForegroundColor = currentColor;
            Console.WriteLine("** End of details of SSO Application");
        }
コード例 #3
0
        /// <summary>
        /// Import an SSO application with specified name, key and file
        /// This code is borrowed from the MMC Snap-in for SSO
        /// </summary>
        private static void ImportSSOApp()
        {
            ConsoleColor currentColor = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Red;

            bool        flag        = true;
            XmlDocument xmlDocument = new XmlDocument();
            string      text        = string.Empty;
            string      toDecrypt   = string.Empty;

            try
            {
                SSO          sSO          = new SSO(_databaseServer, _databaseName, _company);
                StreamReader streamReader = new StreamReader(_encryptedFile);
                toDecrypt = streamReader.ReadToEnd();
                streamReader.Dispose();
                text = _appName;
                string[] applications = sSO.GetApplications();
                for (int i = 0; i < applications.Length; i++)
                {
                    if (applications[i].ToUpper() == text.ToUpper())
                    {
                        flag = false;
                    }
                }
                byte[] bytes;
                try
                {
                    bytes = Encoding.ASCII.GetBytes(sSO.Decrypt(toDecrypt, _encryptedFileKey));
                }
                catch (Exception exception)
                {
                    Console.WriteLine("Error while decrypting the file to import, probably cause is the file hasn't been encrypted with the supplied key (error: " + exception.Message + ")");
                    Console.ForegroundColor = currentColor;
                    return;
                }
                MemoryStream memoryStream = new MemoryStream(bytes);
                try
                {
                    xmlDocument.Load(memoryStream);
                }
                catch (Exception exception)
                {
                    Console.WriteLine("Error in import process: " + exception);
                    Console.ForegroundColor = currentColor;
                    return;
                }
                finally
                {
                    memoryStream.Dispose();
                }
                XmlElement    documentElement = xmlDocument.DocumentElement;
                XmlNodeList   xmlNodeList     = documentElement.SelectNodes("applicationData/add");
                List <string> list            = new List <string>();
                List <string> list2           = new List <string>();
                if (!flag)
                {
                    list.AddRange(sSO.GetKeys(text));
                    list2.AddRange(sSO.GetValues(text));
                }
                foreach (XmlNode xmlNode in xmlNodeList)
                {
                    string value  = xmlNode.SelectSingleNode("@key").Value;
                    string value2 = xmlNode.SelectSingleNode("@value").Value;
                    if (!string.IsNullOrEmpty(value) && !string.IsNullOrEmpty(value2))
                    {
                        if (!list.Contains(value))
                        {
                            list.Add(value);
                            list2.Add(value2);
                        }
                    }
                }
                sSO.CreateApplicationFieldsValues(text, list.ToArray(), list2.ToArray());
            }
            catch (Exception exception)
            {
                Console.WriteLine("Error in import process: " + exception.Message);
                Console.ForegroundColor = currentColor;
            }
        }