public AsyncRequestState(Guid appId, HttpRequestQueue httpQueue, Action <AsyncRequestState> callback, /*bool isBlobStoreQueue,*/ LogCountGuard logGuard) { this.Callback = callback; // this.IsBlobStoreQueue = isBlobStoreQueue; this.LogGuard = logGuard; this.HttpQueue = httpQueue; this.AppId = appId; }
public static void CheckEncryptedToken(AuthTokenFactory tokenFactory, LogCountGuard appCheckGuard, object encryptedToken, AuthenticationToken unencryptedToken, ApplicationAccount applicationAccount, bool binaryToken) { AuthenticationToken token; string errorMsg; if (binaryToken) { var binArray = encryptedToken as byte[]; if (binArray == null) { log.WarnFormat(appCheckGuard, "AppId Check: Failed to cast just created binary token to byte[]. AppId:{0}/{1}, token:'{2}'", unencryptedToken.ApplicationId, unencryptedToken.ApplicationVersion, encryptedToken); return; } if (!tokenFactory.DecryptAuthenticationTokenBynary(binArray, 0, binArray.Length, out token, out errorMsg)) { log.WarnFormat(appCheckGuard, "AppId Check: Failed to decrypt just created binary token. errorMsg:{0}, AppId:{1}/{2}, " + "unencryptedToken:{3}, token:{4}", errorMsg, unencryptedToken.ApplicationId, unencryptedToken.ApplicationVersion, Newtonsoft.Json.JsonConvert.SerializeObject(unencryptedToken), BitConverter.ToString(binArray)); return; } } else { var strToken = encryptedToken as string; if (string.IsNullOrEmpty(strToken)) { return; } if (!tokenFactory.DecryptAuthenticationToken(strToken, out token, out errorMsg)) { log.WarnFormat(appCheckGuard, "AppId Check: Failed to decrypt just created token. errorMsg:{0}, AppId:{1}/{2}, " + "unencryptedToken:{3}, token:{4}", errorMsg, unencryptedToken.ApplicationId, unencryptedToken.ApplicationVersion, Newtonsoft.Json.JsonConvert.SerializeObject(unencryptedToken), strToken); return; } } Guid guid; if (!Guid.TryParse(token.ApplicationId, out guid)) { log.WarnFormat(appCheckGuard, "AppId Check: Wrong appId in token after encryption. appId:{0}, account appId:{1}, unencryptedToken:{2}, token:{0}", token.ApplicationId, applicationAccount.ApplicationId, Newtonsoft.Json.JsonConvert.SerializeObject(unencryptedToken), encryptedToken); } }
public static void CheckEncryptedToken(AuthTokenFactory tokenFactory, LogCountGuard appCheckGuard, object authToken, IAuthenticateRequest authenticateRequest, ApplicationAccount applicationAccount, bool useV1Token) { var strToken = authToken as string; if (string.IsNullOrEmpty(strToken)) { return; } AuthenticationToken token; string errorMsg; if (useV1Token) { if (!tokenFactory.DecryptAuthenticationTokenV1(strToken, out token, out errorMsg)) { log.WarnFormat(appCheckGuard, "AppId Check: Failed to decrypt just created V1 token. errorMsg:{3}, AppId:{0}/{1}, token:{2}", authenticateRequest.ApplicationId, authenticateRequest.ApplicationVersion, authToken, errorMsg); return; } } else { if (!tokenFactory.DecryptAuthenticationTokenV2(strToken, out token, out errorMsg)) { log.WarnFormat(appCheckGuard, "AppId Check: Failed to decrypt just created V2 token. ErrorMsg:{3}, AppId:{0}/{1}, token:{2}", authenticateRequest.ApplicationId, authenticateRequest.ApplicationVersion, authToken, errorMsg); return; } } Guid guid; if (!Guid.TryParse(token.ApplicationId, out guid)) { log.WarnFormat(appCheckGuard, "AppId Check: Wrong appId in token after encryption. appId:{0}, account appId:{1}, request appId:{2}, token:{0}", token.ApplicationId, applicationAccount.ApplicationId, authenticateRequest.ApplicationId, authToken); } }
// private static void LogApplicationAccount(string prefix, Guid id, TmpApplicationAccount account, long elapsedMilliseconds) // { // log.DebugFormat( // "{0} appID {1} - Result: {2} ({3}), CCUs: {4}, CCU Burst: {5}, Region: {6}, Cloud: {7}, Region/Cluster: {11}, Custom Auth Services: {8}, External APIs: {9}, (took {10} ms)", // prefix, // id, // account.ReturnCode, // account.Message, // account.ApplicationCcu, // account.ApplicationCcuBurst, // account.ApplicationRegion, // account.PrivateCloud, // account.ClientAuthenticationServiceInfoList == null ? 0 : account.ClientAuthenticationServiceInfoList.TotalRecordCount, // account.ExternalApiInfoList == null ? 0 : account.ExternalApiInfoList.TotalRecordCount, // elapsedMilliseconds, // account.RegionClusterInfo); // } private HttpWebRequest GetWebRequest(string address, /*string username, string password,*/ LogCountGuard logGuard) { try { var request = HttpWebRequest.Create(address); request.Proxy = null; request.Timeout = this.requestTimeout; /*if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password)) * { * var authInfo = string.Format("{0}:{1}", username, password); * authInfo = Convert.ToBase64String(Encoding.UTF8.GetBytes(authInfo)); * request.Headers["Authorization"] = "Basic " + authInfo; * }*/ return((HttpWebRequest)request); } catch (Exception e) { log.ErrorFormat(logGuard, "Monitoring service: Exception during Web Request creation. url:{0}, username:{1}, msg:{2}", address, "nA", e.Message); throw; } }