Пример #1
0
 internal bool Match(WSAccessKey key)
 {
     try
     {
         return
             (key != null &&
              !string.IsNullOrEmpty(key.hostKey) &&
              key.hostKey.Equals(hostKey) &&
              !string.IsNullOrEmpty(key.MD5Key) &&
              key.MD5Key.Equals(MD5Key) &&
              ((startDate == null && key.startDate == null) || (key.startDate == startDate)) &&
              ((endDate == null && key.endDate == null) || (key.endDate == endDate)));
     }
     catch (Exception) { }
     return(false);
 }
Пример #2
0
        internal bool validateWSAccessKey(string hostKey, WSJson accessKey, out WSAccessKey key)
        {
            key = null;
            try
            {
                string   _MD5Key    = null;
                DateTime?_startDate = null;
                DateTime?_endDate   = null;
                #region read 'accessKey'
                if (accessKey is WSJValue)
                {
                    _MD5Key = ((WSJValue)accessKey).Value;
                }
                else if (accessKey is WSJObject)
                {
                    List <WSJProperty> props = ((WSJObject)accessKey).Value;
                    foreach (WSJProperty prop in props)
                    {
                        string   val      = ((WSJValue)prop.Value).Value;
                        DateTime tempDate = DateTime.MinValue;
                        switch (prop.Key)
                        {
                        case "MD5Key":
                            _MD5Key = val;
                            break;

                        case "startDate":
                            tempDate = DateTime.MinValue;
                            if (new WSConverter().ToDate(val, out tempDate))
                            {
                                _startDate = tempDate;
                            }
                            else
                            {
                                _MD5Key = null;
                            }
                            break;

                        case "endDate":
                            tempDate = DateTime.MaxValue;
                            if (new WSConverter().ToDate(val, out tempDate))
                            {
                                _endDate = tempDate;
                            }
                            else
                            {
                                _MD5Key = null;
                            }
                            break;
                        }
                    }
                }
                #endregion
                if (!string.IsNullOrEmpty(_MD5Key))
                {
                    #region validate 'accessKey'
                    key = new WSAccessKey(this, hostKey, _MD5Key, _startDate, _endDate);
                    WSAccessKey tempKey = new WSAccessKey(
                        this,
                        hostKey,
                        generateKey(
                            hostKey,
                            _startDate == null ? null : ((DateTime)_startDate).ToString(WSConstants.DATE_FORMAT_MIN),
                            _endDate == null ? null : ((DateTime)_endDate).ToString(WSConstants.DATE_FORMAT_MIN)
                            ),
                        _startDate,
                        _endDate
                        );
                    if (key.Match(tempKey))
                    {
                        return(true);
                    }
                    else
                    {
                        key = null;
                    }
                    #endregion
                }
            }
            catch (Exception e) { key = null; CFunc.RegError(GetType(), e, ref status); }
            return(false);
        }