public string ResetPasswordAndRedirect(BOPasswordReset passwordReset) { SessionInfo objInfo = new SessionInfo(); string errorMessage = ""; try { using (SessionPortClient objClient = new SessionPortClient("BOSession")) { _logMessages.AppendFormat("Performing password reset for user:{0}.", passwordReset.Username); if (passwordReset.AccountLocked) { _logMessages.AppendFormat("Account locked.Performing change password for user:{0}.", passwordReset.Username); objClient.changePassword(passwordReset.SAPLoginToken, passwordReset.OldPassword, passwordReset.NewPassword); } else { EnterpriseCredential creds = new EnterpriseCredential(); creds.Login = passwordReset.Username; creds.Password = passwordReset.OldPassword; creds.AuthType = "secEnterprise"; _logMessages.Append("Performing logon to the sap BO"); objInfo = objClient.login(creds, ""); if (objInfo != null) { objClient.changePassword(objInfo.SessionID, passwordReset.OldPassword, passwordReset.NewPassword); } } } } catch (System.Exception ex) { errorMessage = ex.Message; _logMessages.AppendFormat("Error occurred in password reset. Exception message {0}.", ex.Message); _logger.Info(_logMessages.ToString()); return(errorMessage); } _logger.Info(_logMessages.ToString()); return(errorMessage); }
public BOAuthentication AuthenticateUserAndGetToken(BOAuthentication authModel) { EnterpriseCredential creds = new EnterpriseCredential(); SessionInfo objInfo = new SessionInfo(); using (SessionPortClient objClient = new SessionPortClient("BOSession")) { try { creds.Login = authModel.UserName; creds.Password = authModel.Password; creds.AuthType = authModel.UserAuth; _logMessages.AppendFormat("Performing logon with username {0} and authentication type {1}.", authModel.UserName, authModel.UserAuth); objInfo = objClient.login(creds, string.Empty); if (objInfo != null) { authModel.StatusCode = 0; // concatenate with double quotes and store as member authModel.LogonToken = "\"" + objInfo.DefaultToken + "\""; authModel.MustChangePassword = objInfo.MustChangePassword; authModel.BOSesssionID = objInfo.SessionID; authModel.BOSerializedSessionId = objInfo.SerializedSession; _logMessages.AppendFormat("Logon successfull for the user {0}.", authModel.UserName); } else { _logMessages.Append("Logon failed for an unknown reason."); authModel.StatusCode = 4; } _logger.Info(_logMessages.ToString()); return(authModel); } catch (System.Exception ex) { _logMessages.AppendFormat("Error occurred during logon {0}.", ex.Message); _logger.Info(_logMessages.ToString()); throw; } } }