private static void UnmarshallResult(XmlUnmarshallerContext context, GetAttributesResponse response) { int originalDepth = context.CurrentDepth; int targetDepth = originalDepth + 1; if (context.IsStartOfDocument) { targetDepth += 2; } while (context.ReadAtDepth(originalDepth)) { if (context.IsStartElement || context.IsAttribute) { if (context.TestExpression("Attribute", targetDepth)) { var unmarshaller = AttributeUnmarshaller.Instance; var item = unmarshaller.Unmarshall(context); response.Attributes.Add(item); continue; } } } return; }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) { GetAttributesResponse response = new GetAttributesResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.IsStartElement) { if (context.TestExpression("GetAttributesResult", 2)) { UnmarshallResult(context, response); continue; } if (context.TestExpression("ResponseMetadata", 2)) { response.ResponseMetadata = ResponseMetadataUnmarshaller.Instance.Unmarshall(context); } } } return(response); }
private static void UnmarshallResult(XmlUnmarshallerContext context, GetAttributesResponse response) { int originalDepth = context.CurrentDepth; int targetDepth = originalDepth + 1; if (context.IsStartOfDocument) { targetDepth += 2; } while (context.Read()) { if (context.IsStartElement || context.IsAttribute) { if (context.TestExpression("Attribute", targetDepth)) { response.Attributes.Add(AttributeUnmarshaller.GetInstance().Unmarshall(context)); continue; } } else if (context.IsEndElement && context.CurrentDepth < originalDepth) { return; } } return; }
/// <summary> /// Returns a user's profile /// Currently assumes a single user will match the token. /// </summary> /// <param name="authenticationOption"></param> /// <param name="usernameToMatch"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="totalRecords"></param> /// <returns></returns> public override ProfileInfoCollection FindProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, int pageIndex, int pageSize, out int totalRecords) { // TODO: Take paging into account // TODO: Take auth option into account totalRecords = 0; ProfileInfoCollection profiles = new ProfileInfoCollection(); GetAttributesRequest request = new GetAttributesRequest().WithDomainName(domain).WithItemName(usernameToMatch); GetAttributesResponse response = client.GetAttributes(request); if (response.GetAttributesResult.Attribute.Count > 0) { ProfileInfo profile = null; List <Attribute> attributes = response.GetAttributesResult.Attribute; MCItem item = new MCItem(); item.Domain = domain; item.ItemName = usernameToMatch; item.Attributes = new Hashtable(); foreach (Attribute attribute in attributes) { item.Attributes.Add(attribute.Name, attribute.Value); } bool Anon = bool.Parse(item.Get("Anon").Replace("", "false")); DateTime LastActivity = DateTime.Parse(item.Get("LastActivity")); DateTime LastUpdated = DateTime.Parse(item.Get("LastUpdated")); profile = new ProfileInfo(item.Id, Anon, LastActivity, LastUpdated, 0); profiles.Add(profile); } totalRecords = profiles.Count; return(profiles); }
public override bool ValidateUser(string userName, string password) { this.VerifyKeys(); if (String.IsNullOrEmpty(userName) || String.IsNullOrEmpty(password)) { return(false); } bool retval = false; string dbpassword = String.Empty; GetAttributesRequest request = new GetAttributesRequest() { DomainName = Settings.Default.AWSMembershipDomain, ItemName = userName, AttributeNames = PasswordStrings }; GetAttributesResponse response = this._simpleDBClient.GetAttributes(request); foreach (Attribute att in response.Attributes) { switch (att.Name) { case "Password": { dbpassword = att.Value; break; } } } retval = dbpassword == password; return(retval); }
public override string GetPassword(string userName, string answer) { GetAttributesRequest request = new GetAttributesRequest() { DomainName = Settings.Default.AWSMembershipDomain, ItemName = userName, AttributeNames = PasswordStrings }; string password = String.Empty; GetAttributesResponse response = this._simpleDBClient.GetAttributes(request); foreach (Attribute att in response.Attributes) { switch (att.Name) { case "Password": { password = att.Value; break; } } } return(password); }
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); }
internal async Task <int> GetNextId() { var client = GetClient(); int nextId = -1; GetAttributesRequest request = new GetAttributesRequest(); request.DomainName = _domain; request.ItemName = "NextId"; request.AttributeNames = new List <string> { "Id" }; request.ConsistentRead = true; try { GetAttributesResponse response = await client.GetAttributesAsync(request); if (response.HttpStatusCode == System.Net.HttpStatusCode.OK) { if (response.Attributes.Count > 0) { nextId = Convert.ToInt32(response.Attributes[0].Value); } PutAttributesRequest putRequest = new PutAttributesRequest(); putRequest.DomainName = _domain; putRequest.ItemName = "NextId"; putRequest.Attributes.Add( new ReplaceableAttribute { Name = "Id", Value = numberToString(++nextId), Replace = true } ); try { PutAttributesResponse putResponse = await client.PutAttributesAsync(putRequest); } catch (AmazonSimpleDBException ex) { _logger.LogError(ex, $"Error Code: {ex.ErrorCode}, Error Type: {ex.ErrorType}"); throw; } } } catch (System.Exception) { throw; } return(nextId); }
public override string ResetPassword(string userName, string answer) { string newPassword = Membership.GeneratePassword(6, 0); string passwordAnswer = String.Empty; GetAttributesRequest request = new GetAttributesRequest() { DomainName = Settings.Default.AWSMembershipDomain, ItemName = userName, AttributeNames = PasswordStrings }; GetAttributesResponse response = this._simpleDBClient.GetAttributes(request); foreach (Attribute att in response.Attributes) { switch (att.Name) { case "PasswordAnswer": { passwordAnswer = att.Value; break; } } } if (this.RequiresQuestionAndAnswer && !this.CheckPassword(answer, passwordAnswer)) { throw new MembershipPasswordException("Incorrect password answer."); } ReplaceableAttribute replace = new ReplaceableAttribute() { Name = PasswordStrings[0], Value = newPassword, Replace = true }; PutAttributesRequest prequest = new PutAttributesRequest() { DomainName = Settings.Default.AWSMembershipDomain, ItemName = userName, Attributes = new List <ReplaceableAttribute>() { replace } }; this._simpleDBClient.PutAttributes(prequest); return(newPassword); }
// // RoleProvider.IsUserInRole // public override bool IsUserInRole(string username, string rolename) { GetAttributesRequest request = new GetAttributesRequest().WithDomainName(domain).WithItemName(username + "-" + rolename); GetAttributesResponse response = client.GetAttributes(request); if (response.GetAttributesResult.Attribute.Count > 0) { return(true); } else { return(false); } }
// // 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; } } }
/// <summary> /// Returns a SIMPLEDB object with ALL attributes. /// </summary> /// <param name="ItemName">Same as the item ID.</param> /// <param name="Domain"></param> /// <returns></returns> public override MCItem GetItem(string ItemName, string Domain) { string sdbDomain = SetDomain(Domain); GetAttributesRequest request = new GetAttributesRequest().WithDomainName(sdbDomain).WithItemName(ItemName); GetAttributesResponse response = client.GetAttributes(request); MCItem item = new MCItem(); item.Domain = Domain; item.ItemName = ItemName; item.Attributes = new Hashtable(); foreach (Attribute attribute in response.GetAttributesResult.Attribute) { item.Attributes.Add(attribute.Name, attribute.Value); } return(item); }
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); }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext sc, SettingsPropertyCollection collection) { string username = (string)sc["UserName"]; SettingsPropertyValueCollection properties = new SettingsPropertyValueCollection(); GetAttributesRequest request = new GetAttributesRequest().WithDomainName(domain).WithItemName(username); GetAttributesResponse response = client.GetAttributes(request); // Setup defaults ... foreach (SettingsProperty prop in collection) { SettingsPropertyValue value = new SettingsPropertyValue(prop); value.PropertyValue = prop.DefaultValue; properties.Add(value); } if (response.GetAttributesResult.Attribute.Count > 0) { List <Attribute> attributes = response.GetAttributesResult.Attribute; MCItem item = new MCItem(); item.Domain = domain; item.ItemName = username; item.Attributes = new Hashtable(); foreach (Attribute attribute in attributes) { item.Attributes.Add(attribute.Name, attribute.Value); } foreach (SettingsProperty prop in collection) { SettingsPropertyValue value = properties[prop.Name]; value.PropertyValue = item.Attributes[prop.Name]; //value.Deserialized = true; } } return(properties); }
/// <summary> /// Get a single attribute back from the item. /// </summary> /// <param name="domainName"></param> /// <param name="itemName"></param> /// <param name="name"></param> /// <returns>Returns the value of the attribute if it exists, otherwise an empty string.</returns> /// <remarks>Can't do multiple as no guarantee as to order.</remarks> public string GetAttribute(string domainName, string itemName, string name) { var request = new GetAttributesRequest { DomainName = domainName, ItemName = itemName, AttributeName = new List <string> { name } }; GetAttributesResponse response = Client.GetAttributes(request); if (response.IsSetGetAttributesResult()) { if (response.GetAttributesResult.Attribute.Count > 0) { return(response.GetAttributesResult.Attribute[0].Value); } } return(string.Empty); }
public override MembershipUser GetUser(string userName, bool userIsOnline) { this.VerifyKeys(); MembershipUser user = null; if (!String.IsNullOrEmpty(userName)) { DomainHelper.CheckForDomain(Settings.Default.AWSMembershipDomain, _simpleDBClient); GetAttributesRequest request = new GetAttributesRequest() { DomainName = Settings.Default.AWSMembershipDomain, ItemName = userName }; GetAttributesResponse response = this._simpleDBClient.GetAttributes(request); if (response.Attributes.Count == 0) { return(null); } string email = String.Empty; string passwordQuestion = String.Empty; bool isApproved = false; List <Attribute> attributes = response.Attributes; 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; } } user = new MembershipUser( this.Name, userName, String.Empty, email, passwordQuestion, String.Empty, isApproved, false, DateTime.Today, DateTime.Today, DateTime.Today, DateTime.Today, DateTime.Today ); } return(user); }
protected void Page_Load(object sender, EventArgs e) { if (this.Session[Settings.Default.FlashSessionKey] != null) { this.FlashLiteralWrapper.Visible = true; this.FlashLiteral.Text = this.Session[Settings.Default.FlashSessionKey].ToString(); this.Session[Settings.Default.FlashSessionKey] = null; } else { this.FlashLiteralWrapper.Visible = false; } this._petIdString = this.Request.QueryString["petid"]; if (String.IsNullOrEmpty(this._petIdString)) { this.StatsLiteral.Text = "Add a New Pet"; this.SaveStatsButton.Text = "Save New Pet"; } else { this.PhotoPanel.Visible = true; } this._userBucketName = String.Format(Settings.Default.BucketNameFormat, this.Context.User.Identity.Name, this._petIdString); this._itemName = this._petIdString ?? Guid.NewGuid().ToString(); this._domainName = String.Format(Settings.Default.SimpleDbDomainNameFormat, this.Context.User.Identity.Name); if (!this.Page.IsPostBack) { List <int> years = new List <int>(100); for (int i = 0; i < 100; i++) { years.Add(DateTime.Now.AddYears(i * -1).Year); } this.YearDropDownList.DataSource = years.OrderByDescending(y => y); this.YearDropDownList.DataBind(); this.SelectMonth(); this.SelectDay(); Pet pet = default(Pet); List <string> files = new List <string>(); if (!String.IsNullOrEmpty(this._petIdString)) { // // Try to get the requested pet from the user's private domain // DomainHelper.CheckForDomain(this._domainName, _simpleDBClient); GetAttributesRequest getAttributeRequest = new GetAttributesRequest() { DomainName = this._domainName, ItemName = this._itemName }; GetAttributesResponse getAttributeResponse = _simpleDBClient.GetAttributes(getAttributeRequest); List <Attribute> attrs = null; bool showPublic = false; attrs = getAttributeResponse.Attributes; showPublic = false; // // If we can't find it try the public domain // if (attrs.Count == 0) { showPublic = true; } if (showPublic) { Response.Redirect(String.Concat("PetProfile.aspx?petid", _petIdString)); return; } pet = new Pet { Name = attrs.First(a => a.Name == "Name").Value, Birthdate = attrs.First(a => a.Name == "Birthdate").Value, Sex = attrs.First(a => a.Name == "Sex").Value, Type = attrs.First(a => a.Name == "Type").Value, Breed = attrs.First(a => a.Name == "Breed").Value, Likes = attrs.First(a => a.Name == "Likes").Value, Dislikes = attrs.First(a => a.Name == "Dislikes").Value }; this.Public.Checked = bool.Parse(attrs.First(a => a.Name == "Public").Value); using (AmazonS3Client s3Client = new AmazonS3Client(Amazon.RegionEndpoint.USWest2)) { BucketHelper.CheckForBucket(this._petIdString, s3Client); ListObjectsRequest listObjectsRequest = new ListObjectsRequest() { BucketName = this._userBucketName }; ListObjectsResponse listObjectsResponse = s3Client.ListObjects(listObjectsRequest); { files = listObjectsResponse.S3Objects.Select(o => String.Format(Settings.Default.S3BucketUrlFormat, this._userBucketName, o.Key)).ToList(); string firstPhoto = files.FirstOrDefault(); this.PhotoThumbUrl.Value = firstPhoto ?? String.Empty; } } } if (pet != default(Pet)) { this.PetNameHeader.Text = pet.Name; this.NameTextBox.Text = pet.Name; this.AnimalDropDownList.SelectedValue = pet.Type; this.BreedTextBox.Text = pet.Breed; this.SexDropDownList.SelectedValue = pet.Sex; if (pet.Birthdate != null) { DateTime birthdate = DateTime.Parse(pet.Birthdate); this.YearDropDownList.SelectedValue = birthdate.Year.ToString(); this.MonthDropDownList.SelectedValue = birthdate.Month.ToString(); this.DayDropDownList.SelectedValue = birthdate.Day.ToString(); } this.LikesTextBox.Text = pet.Likes; this.DislikesTextBox.Text = pet.Dislikes; this.PhotoRepeater.DataSource = files; this.PhotoRepeater.DataBind(); } } }
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); }
// // 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); }