public CreditCardTokenProvider(CreditCardInfo creditCardInfo)
     : base()
 {
     if (creditCardInfo == null)
     {
         throw new ArgumentNullException("creditCardInfo");
     }
     this.creditCardInfo = creditCardInfo;
 }
        public CreditCardClientCredentials(CreditCardInfo creditCardInfo)
            : base()
        {
            if (creditCardInfo == null)
            {
                throw new ArgumentNullException("creditCardInfo");
            }

            this.creditCardInfo = creditCardInfo;
        }
예제 #3
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 cryptography.
            this.securityKeys = new ReadOnlyCollection<SecurityKey>(new List<SecurityKey>());
        }
 // This helper method checks whether a given credit card entry is present in the user database.
 private bool IsCardNumberAndExpirationValid(CreditCardInfo cardInfo)
 {
     /** original version is using a creditcardfile to store all valid credit cards
     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());
     }
      * */
      // new version just using a list of credicards
     return allValidCreditCards.Exists(c=>c.CardNumber == cardInfo.CardNumber);
 }
예제 #5
0
 public CreditCardToken(CreditCardInfo cardInfo)
     : this(cardInfo, Guid.NewGuid().ToString())
 {
 }
        /// <summary>
        /// Override the ReadTokenCore(XmlReader, SecurityTokenResolver) method. 
        /// This method reads the XML content of the security token and constructs the appropriate in-memory representation for it. 
        /// If it does not recognize the XML element on which the passed-in XML reader is standing, 
        /// it calls the base class implementation to process the system-provided token types.
        /// 
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="tokenResolver"></param>
        /// <returns></returns>
        protected override SecurityToken ReadTokenCore(XmlReader reader, SecurityTokenResolver tokenResolver)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (reader.IsStartElement(CreditCardTokenConstants.CreditCardTokenName, CreditCardTokenConstants.CreditCardTokenNamespace))
            {
                string id = reader.GetAttribute(CreditCardTokenConstants.Id, CreditCardTokenConstants.WsUtilityNamespace);

                reader.ReadStartElement();

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

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

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

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

                return new CreditCardToken(cardInfo, id);
            }
            else
            {
                return WSSecurityTokenSerializer.DefaultInstance.ReadToken(reader, tokenResolver);
            }
        }