Exemple #1
0
 /// <summary>
 /// 缓存当前上下文
 /// </summary>
 public void Cache()
 {
     using (var proxy = new RedisProxy())
     {
         proxy.Client.Set(RedisKeyBuilder.ToSystemKey("api", "ctx", this.Request.RequestId), this);
     }
 }
Exemple #2
0
        /// <summary>
        ///     检查AccessToken
        /// </summary>
        /// <returns>
        ///     0:表示通过验证,可以继续
        ///     1:令牌为空
        ///     2:令牌是伪造的
        /// </returns>
        private bool CheckAccessToken()
        {
            if (Bearer.Length != 33)
            {
                return(false);
            }
            for (var index = 1; index < Bearer.Length; index++)
            {
                var ch = Bearer[index];
                if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'))
                {
                    continue;
                }
                Status = ErrorCode.Auth_AccessToken_Unknow;
                return(false);
            }
            if (!AppConfig.Config.Security.CheckBearerCache)
            {
                return(true);
            }

            bool hase;

            lock (Keys)
            {
                if (Keys.TryGetValue(Bearer, out hase))
                {
                    return(hase);
                }
            }
            using (var proxy = new RedisProxy(RedisProxy.DbAuthority))
            {
                hase = proxy.Client.KeyExists(RedisKeyBuilder.ToAuthKey("at", Bearer));
            }
            lock (Keys)
            {
                if (!Keys.ContainsKey(Bearer))
                {
                    Keys.Add(Bearer, hase);
                }
            }
            return(hase);
        }
Exemple #3
0
 /// <summary>
 /// 得到缓存的键
 /// </summary>
 public static string GetCacheKey(string requestId)
 {
     return(RedisKeyBuilder.ToSystemKey("api", "ctx", requestId.Trim('$').ToUpper()));
 }
Exemple #4
0
 /// <summary>
 /// 得到缓存的键
 /// </summary>
 public static string GetCacheKey(Guid requestId)
 {
     return(RedisKeyBuilder.ToSystemKey("api", "ctx", requestId.ToString().ToUpper()));
 }