示例#1
0
        public Subscription(InfoServiceProxy swis, string endpointAddress, string query, string binding = "NetTcp", string dataFormat = "Xml", CredentialType credentialType = CredentialType.Certificate, string username = null, string password = null)
        {
            this.swis = swis;

            PropertyBag propertyBag = new PropertyBag
            {
                { "Query", query },
                { "EndpointAddress", endpointAddress },
                { "Description", "SWQL Studio" },
                { "DataFormat", dataFormat },
                { "CredentialType", credentialType.ToString() }
            };

            if (!string.IsNullOrEmpty(binding))
            {
                propertyBag["Binding"] = binding;
            }

            if (credentialType == CredentialType.Username)
            {
                propertyBag.Add("Username", username);
                propertyBag.Add("Password", password);
            }

            SubscriptionUri = swis.Create(systemSubscription, propertyBag);
        }
 public static String login(String name, String pwd)
 {
     try {
         CredentialType par = new CredentialType(name, pwd);
         return(sendPostCommand("/login", par.ToString()));
     } catch (Exception ex) {
         logError(ex);
     }
     return(null);
 }
示例#3
0
 private SessionInfo ToSessionInfo(int accountId, string userId, string key, IEnumerable <string> roles, CredentialType credentialType, bool isDeleted)
 {
     return(new SessionInfo
     {
         AccountId = accountId,
         UserId = userId,
         Key = key,
         Roles = roles.ToHashSet(),
         AuthenticationMethod = credentialType.ToString(),
         IsDeleted = isDeleted
     });
 }
示例#4
0
文件: Identity.cs 项目: lulzzz/simias
        /// <summary>
        /// Stores the passphrase for the specified domain.
        /// </summary>
        /// <param name="domainID">The domain to store the passphrase for.</param>
        /// <param name="passPhrase">The domain passphrase.</param>
        /// <param name="type">Type of credentials.</param>
        /// <param name="rememberPassPhrase"></param>
        /// <returns>The modified identity object.</returns>
        internal Identity StorePassPhrase(string domainID, string passPhrase, CredentialType type, bool rememberPassPhrase)
        {
            Property p = GetPropertyByDomain(domainID);

            if (p == null)
            {
                throw new CollectionStoreException("There is no mapping for this domain.");
            }

            // Set the password on the mapping.
            XmlDocument mapDoc = p.Value as XmlDocument;

            if (type == CredentialType.None)
            {
                mapDoc.DocumentElement.RemoveAttribute(PassPhraseTag);
                mapDoc.DocumentElement.RemoveAttribute(RememberPassPhraseTag);
            }
            else
            {
                if (type == CredentialType.Basic)
                {
                    if (passPhrase != null && passPhrase != "")
                    {
                        mapDoc.DocumentElement.SetAttribute(PassPhraseTag, EncryptCredential(passPhrase));
                    }
                }
                else
                {
                    mapDoc.DocumentElement.SetAttribute(PassPhraseTag, passPhrase);
                }
                if (rememberPassPhrase)
                {
                    mapDoc.DocumentElement.SetAttribute(RememberPassPhraseTag, "true");
                }
                else
                {
                    mapDoc.DocumentElement.SetAttribute(RememberPassPhraseTag, "false");
                }
            }

            mapDoc.DocumentElement.SetAttribute(PassPhraseTypeTag, type.ToString());
            p.SetPropertyValue(mapDoc);
            return(this);
        }
示例#5
0
文件: Identity.cs 项目: lulzzz/simias
        /// <summary>
        /// Adds a domain identity property to the Identity object.
        /// </summary>
        /// <param name="userID">Identity that this user is known as in the specified domain.</param>
        /// <param name="domainID">Well known identity for the specified domain.</param>
        /// <param name="credentials">Credentials for this domain. This may be null.</param>
        /// <param name="type">The type of credentials stored.</param>
        /// <returns>The modified identity object.</returns>
        internal Identity AddDomainIdentity(string userID, string domainID, string credentials, CredentialType type)
        {
            XmlDocument mapDoc = null;

            // Check to see if the domain already exists.
            Property p = GetPropertyByDomain(domainID);

            if (p != null)
            {
                mapDoc = p.Value as XmlDocument;
            }
            else
            {
                mapDoc = new XmlDocument();
                XmlElement root = mapDoc.CreateElement(MappingTag);
                mapDoc.AppendChild(root);
                mapDoc.DocumentElement.SetAttribute(DomainTag, domainID);

                p = new Property(PropertyTags.Domain, mapDoc);
                properties.AddNodeProperty(p);
            }

            mapDoc.DocumentElement.SetAttribute(UserTag, userID);
            mapDoc.DocumentElement.SetAttribute(TypeTag, type.ToString());

            if ((credentials != null) && (type != CredentialType.None))
            {
                if (type == CredentialType.Basic)
                {
                    mapDoc.DocumentElement.SetAttribute(CredentialTag, EncryptCredential(credentials));
                }
                else
                {
                    mapDoc.DocumentElement.SetAttribute(CredentialTag, credentials);
                }
            }

            p.SetPropertyValue(mapDoc);
            return(this);
        }
示例#6
0
文件: Identity.cs 项目: lulzzz/simias
        /// <summary>
        /// Sets the credentials for the specified domain.
        /// </summary>
        /// <param name="domainID">The domain to set the password for.</param>
        /// <param name="credentials">The domain credentials.</param>
        /// <param name="type">Type of credentials.</param>
        /// <returns>The modified identity object.</returns>
        internal Identity SetDomainCredentials(string domainID, string credentials, CredentialType type)
        {
            Property p = GetPropertyByDomain(domainID);

            if (p == null)
            {
                throw new CollectionStoreException("There is no mapping for this domain.");
            }

            // Set the password on the mapping.
            XmlDocument mapDoc = p.Value as XmlDocument;

            if (type == CredentialType.None)
            {
                if (domainID == StoreReference.LocalDomain)
                {
                    throw new CollectionStoreException("Cannot remove the local domain credentials.");
                }

                mapDoc.DocumentElement.RemoveAttribute(CredentialTag);
            }
            else
            {
                if (type == CredentialType.Basic)
                {
                    mapDoc.DocumentElement.SetAttribute(CredentialTag, EncryptCredential(credentials));
                }
                else
                {
                    mapDoc.DocumentElement.SetAttribute(CredentialTag, credentials);
                }
            }

            mapDoc.DocumentElement.SetAttribute(TypeTag, type.ToString());
            p.SetPropertyValue(mapDoc);
            return(this);
        }
示例#7
0
        public Subscription(InfoServiceProxy swis, string endpointAddress, string query, string binding = "NetTcp", string dataFormat = "Xml", CredentialType credentialType = CredentialType.Certificate, string username = null, string password = null)
        {
            this.swis = swis;

            PropertyBag propertyBag = new PropertyBag
                {
                    {"Query", query}, 
                    {"EndpointAddress", endpointAddress}, 
                    {"Description", "SWQL Studio"}, 
                    {"DataFormat", dataFormat}, 
                    {"CredentialType", credentialType.ToString()}
                };

            if (!string.IsNullOrEmpty(binding))
                propertyBag["Binding"] = binding;

            if (credentialType == CredentialType.Username)
            {
                propertyBag.Add("Username", username);
                propertyBag.Add("Password", password);
            }

            SubscriptionUri = swis.Create(systemSubscription, propertyBag);
        }
示例#8
0
 /// <summary>
 /// Retrieve credential information such as connection string, user, etc by key. 
 /// </summary>
 /// <param name="type">The lookup key.</param>
 /// <returns>The credential as a string.</returns>
 /// <exception cref="InputException">If the key is not found or the value is empty.</exception>
 public String GetCredential(CredentialType type)
 {
     OutputCredential ret = null;
     if (this.credentials.TryGetValue(type, out ret)) {
     if (ret.Value.Length > 0) {
         return ret.Value;
     }
     throw new InputException("Zero length " + type.ToString() + " credential.");
     }
     throw new InputException("No " + type.ToString() + " credential found.");
 }