Example #1
0
        public string Authenticate(UUID principalID, string authType, string password, int lifetime)
        {
            NameValueCollection requestArgs = new NameValueCollection
            {
                { "RequestMethod", "GetIdentities" },
                { "UserID", principalID.ToString() }
            };

            OSDMap response = WebUtils.PostToService(m_serverUrl, requestArgs);

            if (response["Success"].AsBoolean() && response["Identities"] is OSDArray)
            {
                bool md5hashFound = false;

                OSDArray identities = (OSDArray)response["Identities"];
#if (!ISWIN)
                foreach (OSD osd in identities)
                {
                    OSDMap identity = osd as OSDMap;
                    if (identity != null)
                    {
                        if (identity["Type"].AsString() == "md5hash")
                        {
                            string authorizeResult;
                            if (CheckPassword(principalID, password, identity["Credential"].AsString(), out authorizeResult))
                            {
                                return(authorizeResult);
                            }

                            md5hashFound = true;
                            break;
                        }
                    }
                }
#else
                foreach (OSDMap identity in identities.OfType <OSDMap>().Where(identity => identity["Type"].AsString() == "md5hash"))
                {
                    string authorizeResult;
                    if (CheckPassword(principalID, password, identity["Credential"].AsString(),
                                      out authorizeResult))
                    {
                        return(authorizeResult);
                    }

                    md5hashFound = true;
                    break;
                }
#endif

                if (!md5hashFound)
                {
                    MainConsole.Instance.Warn("[SIMIAN AUTH CONNECTOR]: Authentication failed for " + principalID +
                                              ", no md5hash identity found");
                }
            }
            else
            {
                MainConsole.Instance.Warn("[SIMIAN AUTH CONNECTOR]: Failed to retrieve identities for " + principalID + ": " +
                                          response["Message"].AsString());
            }

            return(String.Empty);
        }