Пример #1
0
 /// <summary>
 /// Used by the Relying Party to add a given attribute with one or more values 
 /// to the request for storage.
 /// </summary>
 public void AddAttribute(AttributeValues attribute)
 {
     if (attribute == null) throw new ArgumentNullException("attribute");
     if (containsAttribute(attribute.TypeUri)) throw new ArgumentException(
           string.Format(CultureInfo.CurrentCulture, Strings.AttributeAlreadyAdded, attribute.TypeUri));
     attributesProvided.Add(attribute);
 }
Пример #2
0
		public void Store() {
			var request = new StoreRequest();
			var newAttribute = new AttributeValues(incrementingAttribute,
				"val" + (incrementingAttributeValue++).ToString(), 
				"val" + (incrementingAttributeValue++).ToString()
			);
			request.AddAttribute(newAttribute);

			var response = ParameterizedTest<StoreResponse>(
				TestSupport.Scenarios.ExtensionFullCooperation, Version, request);
			Assert.IsNotNull(response);
			Assert.IsTrue(response.Succeeded);
			Assert.IsNull(response.FailureReason);

			var fetchRequest = new FetchRequest();
			fetchRequest.AddAttribute(new AttributeRequest { TypeUri = incrementingAttribute });
			var fetchResponse = ParameterizedTest<FetchResponse>(
				TestSupport.Scenarios.ExtensionFullCooperation, Version, fetchRequest);
			Assert.IsNotNull(fetchResponse);
			var att = fetchResponse.GetAttribute(incrementingAttribute);
			Assert.IsNotNull(att);
			Assert.AreEqual(newAttribute.Values.Count, att.Values.Count);
			for (int i = 0; i < newAttribute.Values.Count; i++)
				Assert.AreEqual(newAttribute.Values[i], att.Values[i]);
		}
Пример #3
0
 /// <summary>
 /// Used by the Provider to add attributes to the response for the relying party.
 /// </summary>
 public void AddAttribute(AttributeValues attribute)
 {
     if (attribute == null)
     {
         throw new ArgumentNullException("attribute");
     }
     if (containsAttribute(attribute.TypeUri))
     {
         throw new ArgumentException(
                   string.Format(CultureInfo.CurrentCulture, Strings.AttributeAlreadyAdded, attribute.TypeUri));
     }
     attributesProvided.Add(attribute);
 }
Пример #4
0
        internal static IEnumerable <AttributeValues> DeserializeAttributes(IDictionary <string, string> fields)
        {
            AliasManager aliasManager = parseAliases(fields);

            foreach (string alias in aliasManager.Aliases)
            {
                AttributeValues att       = new AttributeValues(aliasManager.ResolveAlias(alias));
                int             count     = 1;
                bool            countSent = false;
                string          countString;
                if (fields.TryGetValue("count." + alias, out countString))
                {
                    if (!int.TryParse(countString, out count) || count <= 0)
                    {
                        Logger.ErrorFormat("Failed to parse count.{0} value to a positive integer.", alias);
                        continue;
                    }
                    countSent = true;
                }
                if (countSent)
                {
                    for (int i = 1; i <= count; i++)
                    {
                        string value;
                        if (fields.TryGetValue(string.Format(CultureInfo.InvariantCulture, "value.{0}.{1}", alias, i), out value))
                        {
                            att.Values.Add(value);
                        }
                        else
                        {
                            Logger.ErrorFormat("Missing value for attribute '{0}'.", att.TypeUri);
                            continue;
                        }
                    }
                }
                else
                {
                    string value;
                    if (fields.TryGetValue("value." + alias, out value))
                    {
                        att.Values.Add(value);
                    }
                    else
                    {
                        Logger.ErrorFormat("Missing value for attribute '{0}'.", att.TypeUri);
                        continue;
                    }
                }
                yield return(att);
            }
        }
Пример #5
0
		internal static IEnumerable<AttributeValues> DeserializeAttributes(IDictionary<string, string> fields) {
			AliasManager aliasManager = parseAliases(fields);
			foreach (string alias in aliasManager.Aliases) {
				AttributeValues att = new AttributeValues(aliasManager.ResolveAlias(alias));
				int count = 1;
				bool countSent = false;
				string countString;
				if (fields.TryGetValue("count." + alias, out countString)) {
					if (!int.TryParse(countString, out count) || count <= 0) {
						Logger.ErrorFormat("Failed to parse count.{0} value to a positive integer.", alias);
						continue;
					}
					countSent = true;
				}
				if (countSent) {
					for (int i = 1; i <= count; i++) {
						string value;
						if (fields.TryGetValue(string.Format(CultureInfo.InvariantCulture, "value.{0}.{1}", alias, i), out value)) {
							att.Values.Add(value);
						} else {
							Logger.ErrorFormat("Missing value for attribute '{0}'.", att.TypeUri);
							continue;
						}
					}
				} else {
					string value;
					if (fields.TryGetValue("value." + alias, out value))
						att.Values.Add(value);
					else {
						Logger.ErrorFormat("Missing value for attribute '{0}'.", att.TypeUri);
						continue;
					}
				}
				yield return att;
			}
		}