private void AsyncLoginCompletedCallback(ILoginProvider provider, LoginInfo loginInfo) { provider.Completed -= AsyncLoginCompletedCallback; bool success = false; switch (loginInfo.Status) { case LoginStatus.None: break; case LoginStatus.ExceedMaxRetryCount: var loginId = loginInfo.Parameter.LoginId; var password = loginInfo.Parameter.Password; var ip = loginInfo.Parameter.Request.ClientInfo.RemoteIp; _Logger.WarnFormat("{0} login failed: exceed max login retry times", loginId); AuditHelper.AddIllegalLogin(AppType.TradingConsole, loginId, password, ip); Application.Default.TradingConsoleServer.SaveLoginFail(loginId, password, ip); break; case LoginStatus.LoginIdIsEmpty: _Logger.Warn("LoginId is empty"); break; case LoginStatus.ParticipantServiceLoginFailed: break; case LoginStatus.UserIdIsEmpty: _Logger.WarnFormat("{0} is not a valid user", loginInfo.Parameter.LoginId); break; case LoginStatus.CheckPermissionFailed: break; case LoginStatus.NotAuthrized: _Logger.WarnFormat("{0} doesn't have the right to login trader", loginInfo.Parameter.LoginId); break; case LoginStatus.StateServerLoginFailed: break; case LoginStatus.StateServerNotLogined: break; case LoginStatus.Success: success = true; break; } if (!success) { LoginRetryTimeHelper.IncreaseFailedCount(loginInfo.Parameter.LoginId, ParticipantType.Customer, SettingManager.Default.ConnectionString); OnError(loginInfo.Parameter.Request, loginInfo.Parameter.AppType); } else { LoginRetryTimeHelper.ClearFailedCount(loginInfo.UserID, ParticipantType.Customer, SettingManager.Default.ConnectionString); ProcessPostAsyncLoginSuccess(loginInfo); } }
public IEnumerator <int> AsyncLogin(LoginParameter parameter, AsyncEnumerator ae) { string connectionString = SettingManager.Default.ConnectionString; LoginInfo loginInfo = new LoginInfo() { Parameter = parameter }; if (LoginRetryTimeHelper.IsFailedCountExceeded(parameter.LoginId, ParticipantType.Customer, connectionString)) { loginInfo.Status = LoginStatus.ExceedMaxRetryCount; OnCompleted(loginInfo); yield break; } if (!parameter.LoginId.HasValue()) { loginInfo.Status = LoginStatus.LoginIdIsEmpty; OnCompleted(loginInfo); yield break; } Application.Default.ParticipantService.BeginLogin(parameter.LoginId, parameter.Password, ae.End(), null); yield return(1); try { loginInfo.UserID = Application.Default.ParticipantService.EndLogin(ae.DequeueAsyncResult()); } catch (Exception ex) { _Logger.Error(ex); loginInfo.Status = LoginStatus.ParticipantServiceLoginFailed; OnCompleted(loginInfo); yield break; } if (loginInfo.UserID == Guid.Empty) { loginInfo.Status = LoginStatus.UserIdIsEmpty; OnCompleted(loginInfo); yield break; } Guid programID = new Guid(SettingManager.Default.GetJavaTraderSettings("TradingConsole")); Guid permissionID = new Guid(SettingManager.Default.GetJavaTraderSettings("Run")); Application.Default.SecurityService.BeginCheckPermission(loginInfo.UserID, programID, permissionID, "", "", loginInfo.UserID, ae.End(), null); yield return(1); bool isAuthrized = false; try { string message; isAuthrized = Application.Default.SecurityService.EndCheckPermission(ae.DequeueAsyncResult(), out message); } catch (Exception ex) { _Logger.Error(ex); loginInfo.Status = LoginStatus.CheckPermissionFailed; OnCompleted(loginInfo); yield break; } if (!isAuthrized) { loginInfo.Status = LoginStatus.NotAuthrized; OnCompleted(loginInfo); yield break; } var token = new Token(Guid.Empty, UserType.Customer, parameter.AppType); token.UserID = loginInfo.UserID; token.SessionID = parameter.Request.ClientInfo.Session.ToString(); SessionManager.Default.AddToken(parameter.Request.ClientInfo.Session, token); var stateServerCallToken = new Token { UserID = token.UserID, AppType = AppType.TradingConsole, SessionID = token.SessionID, UserType = token.UserType }; Application.Default.StateServer.BeginLogin(stateServerCallToken, ae.End(), null); yield return(1); bool isStateServerLogined = false; try { isStateServerLogined = Application.Default.StateServer.EndLogin(ae.DequeueAsyncResult()); } catch (Exception ex) { _Logger.Error(ex); loginInfo.Status = LoginStatus.StateServerLoginFailed; OnCompleted(loginInfo); yield break; } if (!isStateServerLogined) { loginInfo.Status = LoginStatus.StateServerNotLogined; OnCompleted(loginInfo); yield break; } loginInfo.Status = LoginStatus.Success; OnCompleted(loginInfo); }