Ejemplo n.º 1
0
        private void TestGetAttributes()
        {
            GetAttributesRequest request = new GetAttributesRequest()
            {
                DomainName     = domainName,
                ItemName       = FOO_ITEM.Name,
                AttributeNames = new List <string>()
                {
                    FOO_ITEM.Attributes[0].Name, FOO_ITEM.Attributes[1].Name
                },
                ConsistentRead = true
            };

            GetAttributesResult getAttributesResult                      = Client.GetAttributes(request);
            List <Amazon.SimpleDB.Model.Attribute> attributes            = getAttributesResult.Attributes;
            Dictionary <string, string>            attributeValuesByName = ConvertAttributesToMap(attributes);

            Assert.AreEqual <int>(2, attributeValuesByName.Count);

            List <ReplaceableAttribute> attrs = new List <ReplaceableAttribute>();

            attrs.Add(FOO_ITEM.Attributes[0]);
            attrs.Add(FOO_ITEM.Attributes[1]);

            foreach (ReplaceableAttribute expectedAttribute in attrs)
            {
                string expectedAttributeName = expectedAttribute.Name;
                Assert.IsTrue(attributeValuesByName.ContainsKey(expectedAttributeName));
                Assert.AreEqual <string>(expectedAttribute.Value, attributeValuesByName[expectedAttributeName]);
            }
        }
Ejemplo n.º 2
0
        private void btnGetAttributes_Click(object sender, RoutedEventArgs e)
        {
            #region User Input Validation

            this.Attributes.Clear();
            //Validate user input.
            if (string.IsNullOrEmpty(this.DomainName) || string.IsNullOrEmpty(this.ItemName))
            {
                FetchingOrDeletingAttributeMessage = "Domain-Name or Item-Name cannot be empty.";
                return;
            }
            this.FetchingOrDeletingAttributeMessage = "Please wait...";

            #endregion User Input Validation

            GetAttributesRequest request = new GetAttributesRequest {
                DomainName = this.DomainName, ItemName = this.ItemName
            };

            //Associate the attributes.
            GetListAttributeFromString(this.AttributesForQuery).ForEach(v => request.AttributeName.Add(v.Attribute));

            SimpleDBResponseEventHandler <object, ResponseEventArgs> handler = null;

            handler = delegate(object senderAmazon, ResponseEventArgs args)
            {
                //Unhook from event.
                SimpleDB.Client.OnSimpleDBResponse -= handler;
                GetAttributesResponse response = args.Response as GetAttributesResponse;

                if (null != response)
                {
                    GetAttributesResult attributeResult = response.GetAttributesResult;
                    if (null != attributeResult)
                    {
                        this.Dispatcher.BeginInvoke(() =>
                        {
                            this.Attributes.Clear();
                            if (attributeResult.Attribute.Count > 0)
                            {
                                FetchingOrDeletingAttributeMessage = "Result count: " + attributeResult.Attribute.Count;
                                foreach (var item in attributeResult.Attribute)
                                {
                                    this.Attributes.Add(item);
                                }
                            }
                            else
                            {
                                FetchingOrDeletingAttributeMessage = "No results";
                            }
                        });
                    }
                }
            };

            SimpleDB.Client.OnSimpleDBResponse += handler;
            SimpleDB.Client.GetAttributes(request);
        }
Ejemplo n.º 3
0
        //
        // MembershipProvider.GetUser(string, bool)
        //

        public override MembershipUser GetUser(string username, bool userIsOnline)
        {
            try
            {
                GetAttributesRequest  request  = new GetAttributesRequest().WithDomainName(domain).WithItemName(username);
                GetAttributesResponse response = client.GetAttributes(request);
                GetAttributesResult   result   = response.GetAttributesResult;
                // if we have no attributes we have no user
                if (result.Attribute.Count == 0)
                {
                    return(null);
                }
                string           email            = "";
                string           passwordQuestion = "";
                bool             isApproved       = false;
                List <Attribute> attributes       = result.Attribute;
                foreach (Attribute att in attributes)
                {
                    switch (att.Name)
                    {
                    case "Email": email = att.Value; break;

                    case "PasswordQuestion": passwordQuestion = att.Value; break;

                    case "IsApproved": isApproved = bool.Parse(att.Value); break;

                    default: break;
                    }
                }

                MembershipUser user = new MembershipUser(this.Name, username,
                                                         "", email, passwordQuestion, "", isApproved, false,
                                                         DateTime.Today, DateTime.Today, DateTime.Today, DateTime.Today, DateTime.Today);
                return(user);
            }
            catch (Exception e)
            {
                if (WriteExceptionsToEventLog)
                {
                    WriteToEventLog(e, "GetUser(String, Boolean)");

                    throw new ProviderException(exceptionMessage);
                }
                else
                {
                    throw e;
                }
            }
        }
Ejemplo n.º 4
0
        public async Task Then_The_Attributes_Are_Returned_From_Mediator(
            GetAttributesResult queryResult,
            [Frozen] Mock <IMediator> mockMediator,
            [Greedy] ProviderAttributesController controller)
        {
            mockMediator
            .Setup(x => x.Send(It.IsAny <GetAttributesQuery>(), CancellationToken.None))
            .ReturnsAsync(queryResult);

            var actual = await controller.GetProviderAttributes() as ObjectResult;

            Assert.IsNotNull(actual);
            actual.StatusCode.Should().Be((int)HttpStatusCode.OK);
            actual.Value.Should().BeEquivalentTo(queryResult.Attributes);
        }
Ejemplo n.º 5
0
        public override bool ValidateUser(string username, string password)
        {
            bool   isValid    = false;
            string dbpassword = "";

            try
            {
                GetAttributesRequest  request  = new GetAttributesRequest().WithDomainName(domain).WithItemName(username).WithAttributeName(new string[] { "Password", "PasswordAnswer" });
                GetAttributesResponse response = client.GetAttributes(request);
                if (response.IsSetGetAttributesResult())
                {
                    GetAttributesResult result = response.GetAttributesResult;
                    foreach (Attribute att in result.Attribute)
                    {
                        switch (att.Name)
                        {
                        case "Password": dbpassword = att.Value; break;

                        default: break;
                        }
                    }
                }
                else
                {
                    throw new MembershipPasswordException("User not found");
                }
                if (dbpassword == password)
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                if (WriteExceptionsToEventLog)
                {
                    WriteToEventLog(e, "ValidateUser");

                    throw new ProviderException(exceptionMessage);
                }
                else
                {
                    throw e;
                }
            }

            return(isValid);
        }
Ejemplo n.º 6
0
        bool DoAttributesExistForItem(IAmazonSimpleDB sdb, String itemName, String domainName, List <String> attributeNames)
        {
            GetAttributesRequest request = new GetAttributesRequest()
            {
                DomainName     = domainName,
                AttributeNames = attributeNames,
                ItemName       = itemName,
                ConsistentRead = true
            };

            GetAttributesResult         result = sdb.GetAttributes(request);
            Dictionary <string, string> attributeValuesByName = ConvertAttributesToMap(result.Attributes);

            foreach (string expectedAttributeName in attributeNames)
            {
                if (!attributeValuesByName.ContainsKey(expectedAttributeName))
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 7
0
        public override string ResetPassword(string username, string answer)
        {
            if (!EnablePasswordReset)
            {
                throw new NotSupportedException("Password reset is not enabled.");
            }

            if (answer == null && RequiresQuestionAndAnswer)
            {
                throw new ProviderException("Password answer required for password reset.");
            }

            string newPassword =
                System.Web.Security.Membership.GeneratePassword(6, 0);

            string passwordAnswer = "";

            try
            {
                GetAttributesRequest  request  = new GetAttributesRequest().WithDomainName(domain).WithItemName(username).WithAttributeName(new string[] { "Password", "PasswordAnswer" });
                GetAttributesResponse response = client.GetAttributes(request);
                if (response.IsSetGetAttributesResult())
                {
                    GetAttributesResult result = response.GetAttributesResult;
                    foreach (Attribute att in result.Attribute)
                    {
                        switch (att.Name)
                        {
                        case "PasswordAnswer": passwordAnswer = att.Value; break;

                        default: break;
                        }
                    }
                }
                else
                {
                    throw new MembershipPasswordException("User not found");
                }

                if (RequiresQuestionAndAnswer && !CheckPassword(answer, passwordAnswer))
                {
                    throw new MembershipPasswordException("Incorrect password answer.");
                }

                // Update the new password here
                ReplaceableAttribute replace  = new ReplaceableAttribute().WithName("Password").WithValue(newPassword).WithReplace(true);
                PutAttributesRequest prequest = new PutAttributesRequest().WithDomainName(domain).WithItemName(username).WithAttribute(replace);
                client.PutAttributes(prequest);
            }
            catch (Exception e)
            {
                if (WriteExceptionsToEventLog)
                {
                    WriteToEventLog(e, "ResetPassword");

                    throw new ProviderException(exceptionMessage);
                }
                else
                {
                    throw e;
                }
            }

            return(newPassword);
        }
Ejemplo n.º 8
0
        //
        // MembershipProvider.GetPassword
        //

        public override string GetPassword(string username, string answer)
        {
            if (!EnablePasswordRetrieval)
            {
                throw new ProviderException("Password Retrieval Not Enabled.");
            }

            if (PasswordFormat == MembershipPasswordFormat.Hashed)
            {
                throw new ProviderException("Cannot retrieve Hashed passwords.");
            }

            string password       = "";
            string passwordAnswer = "";

            try
            {
                GetAttributesRequest  request  = new GetAttributesRequest().WithDomainName(domain).WithItemName(username).WithAttributeName(new string[] { "Password", "PasswordAnswer" });
                GetAttributesResponse response = client.GetAttributes(request);
                if (response.IsSetGetAttributesResult())
                {
                    GetAttributesResult result = response.GetAttributesResult;
                    foreach (Attribute att in result.Attribute)
                    {
                        switch (att.Name)
                        {
                        case "Password": password = att.Value; break;

                        case "PasswordAnswer": passwordAnswer = att.Value; break;

                        default: break;
                        }
                    }
                }
                else
                {
                    throw new MembershipPasswordException("User not found");
                }
            }
            catch (Exception e)
            {
                if (WriteExceptionsToEventLog)
                {
                    WriteToEventLog(e, "GetPassword");

                    throw new ProviderException(exceptionMessage);
                }
                else
                {
                    throw e;
                }
            }

            if (RequiresQuestionAndAnswer && !CheckPassword(answer, passwordAnswer))
            {
                throw new MembershipPasswordException("Incorrect password answer.");
            }

            if (PasswordFormat == MembershipPasswordFormat.Encrypted)
            {
                password = UnEncodePassword(password);
            }

            return(password);
        }