protected override SecurityToken ReadTokenCore(XmlReader reader, SecurityTokenResolver tokenResolver)
        {
            if (reader == null) throw new ArgumentNullException("reader");

            if (reader.IsStartElement(Constants.CreditCardTokenName, Constants.CreditCardTokenNamespace))
            {
                string id = reader.GetAttribute(Constants.Id, Constants.WsUtilityNamespace);

                reader.ReadStartElement();

                // read the credit card number
                string creditCardNumber = reader.ReadElementString(Constants.CreditCardNumberElementName, Constants.CreditCardTokenNamespace);

                // read the expiration date
                string expirationTimeString = reader.ReadElementString(Constants.CreditCardExpirationElementName, Constants.CreditCardTokenNamespace);
                DateTime expirationTime = XmlConvert.ToDateTime(expirationTimeString, XmlDateTimeSerializationMode.Utc);

                // read the issuer of the credit card
                string creditCardIssuer = reader.ReadElementString(Constants.CreditCardIssuerElementName, Constants.CreditCardTokenNamespace);
                reader.ReadEndElement();

                CreditCardInfo cardInfo = new CreditCardInfo(creditCardNumber, creditCardIssuer, expirationTime);

                return new CreditCardToken(cardInfo, id);
            }
            else
            {
                return WSSecurityTokenSerializer.DefaultInstance.ReadToken(reader, tokenResolver);
            }
        }
 /// <summary>
 /// Helper method to check if a given credit card entry is present in the User DB
 /// </summary>
 private bool IsCardNumberAndExpirationValid(CreditCardInfo cardInfo)
 {
     try
     {
         using (StreamReader myStreamReader = new StreamReader(this.creditCardsFile))
         {
             string line = "";
             while ((line = myStreamReader.ReadLine()) != null)
             {
                 string[] splitEntry = line.Split('#');
                 if (splitEntry[0] == cardInfo.CardNumber)
                 {
                     string expirationDateString = splitEntry[1].Trim();
                     DateTime expirationDateOnFile = DateTime.Parse(expirationDateString, System.Globalization.DateTimeFormatInfo.InvariantInfo, System.Globalization.DateTimeStyles.AdjustToUniversal);
                     if (cardInfo.ExpirationDate == expirationDateOnFile)
                     {
                         string issuer = splitEntry[2];
                         return issuer.Equals(cardInfo.CardIssuer, StringComparison.InvariantCultureIgnoreCase);
                     }
                     else
                     {
                         return false;
                     }
                 }
             }
             return false;
         }
     }
     catch (Exception e)
     {
         throw new Exception("BookStoreService: Error while retrieving credit card information from User DB " + e.ToString());
     }
 }
        public CreditCardClientCredentials(CreditCardInfo creditCardInfo)
            : base()
        {
            if (creditCardInfo == null)
                throw new ArgumentNullException("creditCardInfo");

            this.creditCardInfo = creditCardInfo;
        }
 public CreditCardTokenProvider(CreditCardInfo creditCardInfo)
     : base()
 {
     if (creditCardInfo == null)
     {
         throw new ArgumentNullException("creditCardInfo");
     }
     this.creditCardInfo = creditCardInfo;
 }
Пример #5
0
        public CreditCardToken(CreditCardInfo cardInfo, string id)
        {
            if (cardInfo == null)
                throw new ArgumentNullException("cardInfo");

            if (id == null)
                throw new ArgumentNullException("id");

            this.cardInfo = cardInfo;
            this.id = id;

            // the credit card token is not capable of any crypto
            this.securityKeys = new ReadOnlyCollection<SecurityKey>(new List<SecurityKey>());
        }
Пример #6
0
 public CreditCardToken(CreditCardInfo cardInfo)
     : this(cardInfo, Guid.NewGuid().ToString())
 {
 }
Пример #7
0
 public CreditCardToken(CreditCardInfo cardInfo) : this(cardInfo, Guid.NewGuid().ToString())
 {
 }