private bool HandleSystem(string token, string host) { Tuple <bool, bool> inCache = IsInCache(host, token); if (inCache.Item1) { return(inCache.Item2); } HomeOS.Hub.Common.SafeTokenHandler.SafeTokenHandler tokenHandler = new HomeOS.Hub.Common.SafeTokenHandler.SafeTokenHandler(Constants.TokenEncryptionSecret); HomeOS.Hub.Common.SafeTokenHandler.SafeTokenUser user = tokenHandler.ProcessToken(token); if (user == null) { ThrowRejection(HttpStatusCode.Unauthorized, "Invalid user token in authorization header."); } if (!(user.Name.Equals(Constants.SystemLow) || user.Name.Equals(Constants.SystemHigh))) { ThrowRejection(HttpStatusCode.Unauthorized, "Invalid user token in authorization header."); } if (DateTime.UtcNow.Subtract(user.Timestamp).TotalMilliseconds > Constants.PrivilegeLevelTokenExpiry[user.Name] * 1000) { ThrowRejection(HttpStatusCode.Unauthorized, "Expired token being presented. Token Expiry: " + Constants.PrivilegeLevelTokenExpiry[user.Name] + " seconds"); } bool retVal = IsValidAccess(host, user.Name, user.Name); UpdateCache(host, token, user.Timestamp, retVal); // *** updating cache //hostTokenResultCache[host + "," + token]= new Dictionary<DateTime, bool>() { { user.Timestamp, retVal } }; return(retVal); }
private bool HandleSystem(string token, string host) { Tuple<bool, bool> inCache = IsInCache(host, token); if (inCache.Item1) return inCache.Item2; HomeOS.Hub.Common.SafeTokenHandler.SafeTokenHandler tokenHandler = new HomeOS.Hub.Common.SafeTokenHandler.SafeTokenHandler(Constants.TokenEncryptionSecret); HomeOS.Hub.Common.SafeTokenHandler.SafeTokenUser user = tokenHandler.ProcessToken(token); if (user == null) ThrowRejection(HttpStatusCode.Unauthorized, "Invalid user token in authorization header."); if (!(user.Name.Equals(Constants.SystemLow) || user.Name.Equals(Constants.SystemHigh))) ThrowRejection(HttpStatusCode.Unauthorized, "Invalid user token in authorization header."); if (DateTime.UtcNow.Subtract(user.Timestamp).TotalMilliseconds > Constants.PrivilegeLevelTokenExpiry[user.Name] * 1000) ThrowRejection(HttpStatusCode.Unauthorized, "Expired token being presented. Token Expiry: " + Constants.PrivilegeLevelTokenExpiry[user.Name] + " seconds"); bool retVal = IsValidAccess(host, user.Name, user.Name); UpdateCache(host, token, user.Timestamp, retVal); // *** updating cache //hostTokenResultCache[host + "," + token]= new Dictionary<DateTime, bool>() { { user.Timestamp, retVal } }; return retVal; }