/// <summary> /// The revolution cookie authentication server operation did fail. /// </summary> /// <param name="operation"> /// The operation. /// </param> /// <param name="error"> /// The error. /// </param> public void AuthenticateRevolutionCookieServerOperationDidFail( RevolutionCookieServerOperation operation, Exception error) { if (error != null) { this.Logger.LogError($"AuthenticateRevolutionCookieServerOperation {error.Message}"); } this.CleanUpFinishedServerOperation(); PasswordChangeResult passwordChangeResult; if (!string.IsNullOrEmpty(this.newPassword)) { this.newPassword = null; passwordChangeResult = PasswordChangeResult.PasswordNotChanged; } else { passwordChangeResult = PasswordChangeResult.NoPasswordChangeRequested; } this.Delegate?.ServerOperationManagerDidFailServerLogin(this, error, passwordChangeResult); }
/// <summary> /// Performs the login operation and Start processing the operation queue. /// </summary> public void Login() { if (this.serverOperations == null) { return; } if (this.ConnectionWatchDog != null && (this.ConnectionWatchDog.HasServerConnection == false || this.ConnectionWatchDog.HasInternetConnection == false)) { this.TimeoutLogin(); return; } var alreadyQueued = false; var queuePosition = 0; foreach (var operation in this.serverOperations) { if (operation is AuthenticateServerOperation) { alreadyQueued = true; break; } if (operation is RevolutionCookieServerOperation) { alreadyQueued = true; break; } ++queuePosition; } if (alreadyQueued) { if ((this.currentServerOperation == null && queuePosition > 0) || queuePosition > 1) { var serverOperation = this.serverOperations[queuePosition]; this.serverOperations.RemoveAt(queuePosition); this.serverOperations.Insert(this.currentServerOperation != null ? 1 : 0, serverOperation); } this.StartNextOperation(); } else { ServerOperation serverOperation; if (this.crmServer.AuthenticationType == ServerAuthenticationType.Revolution) { string usedRasUsername; if (!string.IsNullOrEmpty(this.RasInstanceName) && this.loginName.IndexOf("\\", StringComparison.OrdinalIgnoreCase) < 0 && !this.startingUp) { this.Logger.LogDebug($"ServerOperationManager RAS relogon with prefix: {this.RasInstanceName}", LogFlag.LogNetwork); usedRasUsername = $"{this.RasInstanceName}\\{this.loginName}"; } else { this.Logger.LogDebug($"ServerOperationManager RAS logon with loginName: {this.loginName}", LogFlag.LogNetwork); usedRasUsername = this.loginName; } serverOperation = new RevolutionCookieServerOperation(usedRasUsername, this.Password, this); } else { serverOperation = new AuthenticateServerOperation( this.loginName, this.Password, true, true, this.languageKey, this); if (!string.IsNullOrEmpty(this.newPassword)) { ((AuthenticateServerOperation)serverOperation).ChangePasswordTo(this.newPassword); } } this.QueueServerOperationAtTopOfTheQueue(serverOperation); } }
/// <summary> /// The revolution cookie authentication server operation did finish. /// </summary> /// <param name="operation"> /// The operation. /// </param> /// <param name="cookies"> /// The cookies. /// </param> /// <param name="serverUrl"> /// The server URL. /// </param> /// <param name="headerParameters"> /// The header parameters. /// </param> public void AuthenticateRevolutionCookieServerOperationDidFinish( RevolutionCookieServerOperation operation, List <Cookie> cookies, Uri serverUrl, Dictionary <string, string> headerParameters) { this.crmServer.ServerUrl = serverUrl; var dictionary = ServerSession.CurrentLocalJsonConfigDictionary(); var newPasswordRequired = string.Empty; if (!dictionary.ValueEquals("oldRasHandling", "true")) { this.RasUsername = headerParameters.ValueOrDefault("Ras-User-Email"); this.RasApplicationId = headerParameters.ValueOrDefault("Ras-App-Id"); this.RasInstanceName = headerParameters.ValueOrDefault("Ras-App-Type"); newPasswordRequired = headerParameters.ValueOrDefault("Ras-User-PwChange"); } else { this.Logger.LogDebug("using oldRasHandling", LogFlag.LogNetwork); } // newPassword.length != 0 --> A new password will be transmitted if (newPasswordRequired != null && newPasswordRequired == "true" && string.IsNullOrEmpty(this.newPassword)) { var mandatory = this.startingUp; if (!mandatory) { this.Delegate?.ServerOperationManagerPasswordChangeRequested(this, true); } if (mandatory) { // var error = NSError.ErrorWithDomainCodeUserInfo("New password required",SessionErrorCode.PasswordExpired, NSDictionary.DictionaryWithObjectForKey(newPasswordRequired, kUPErrorRASErrorPasswordExpired)); this.Delegate?.ServerOperationManagerDidFailServerLogin( this, new Exception("New password required"), PasswordChangeResult.NoPasswordChangeRequested); return; } } else { this.Delegate?.ServerOperationManagerPasswordChangeRequested(this, false); } if (string.IsNullOrEmpty(this.RasApplicationId)) { // Fallback for Old Ras version this.RasUsername = this.loginName; this.RasInstanceName = null; // Bei nächsten login mit Header Parameter InstanzName übernehmen this.RasApplicationId = this.crmServer.Name; this.Logger.LogDebug("ServerOperationManager - No RAS Header Parameter", LogFlag.LogNetwork); } else { this.Logger.LogDebug( $"ServerOperationManager - RAS AppId: {this.RasApplicationId} instanceName: {this.RasInstanceName}", LogFlag.LogNetwork); } var revolutionLoginOperation = new RevolutionAuthenticationServerOperation( cookies, true, true, this.languageKey, this); if (!string.IsNullOrEmpty(this.newPassword)) { revolutionLoginOperation.ChangePasswordTo(this.newPassword); } this.QueueServerOperationAtTopOfTheQueue(revolutionLoginOperation); }