public string GetReport(BOAuthentication authModel, string reportId) { _logMessages.AppendFormat("Retrieving opendocument url for report {0}.", reportId); // Get OpenDocumentURI XmlDocument docRecv = new System.Xml.XmlDocument(); _biRepository.CreateWebRequest(send: null, recv: docRecv, method: "GET", URI: authModel.URI, URIExtension: "/biprws/infostore/" + reportId, pLogonToken: authModel.LogonToken); var links = docRecv.GetElementsByTagName("link"); string openDocumentUri = string.Empty; for (int counter = 0, reverseCounter = links.Count - 1; counter < links.Count / 2; counter++, reverseCounter--) { if (GetOpenDocumentUri(links[counter], ref openDocumentUri) || GetOpenDocumentUri(links[reverseCounter], ref openDocumentUri)) { _logMessages.Append("BO REST responded back with valid opendocument url."); break; } } //append open doc url with session since it occupies only one license openDocumentUri = string.Format("{0}&serSes={1}", openDocumentUri, System.Web.HttpUtility.UrlEncode(authModel.BOSesssionID)); _logMessages.AppendFormat("Final Opendocument url is {0}.", openDocumentUri); _logger.Info(_logMessages.ToString()); return(openDocumentUri); }
public bool GetBOUserLogoff(string authToken, string sessionId) { string baseUrl = ConfigurationManager.AppSettings["BOBaseUrl"]; string userAuth = ConfigurationManager.AppSettings["BOExternalAuth"]; _errorMessageBuilder.AppendFormat("Logging user out of system. BO Base Url {0} and External Auth type {1}", baseUrl, userAuth); bool response = false; BOAuthentication boAuthmodel = new BOAuthentication() { UserName = string.Empty, Password = string.Empty, URI = baseUrl, UserAuth = userAuth, LogonToken = authToken, BOSesssionID = sessionId }; try { _errorMessageBuilder.Append("Invoking logout in authentication service"); var authResult = _authenticationService.Logoff(boAuthmodel); response = authResult; } catch (System.Exception ex) { _errorMessageBuilder.AppendFormat("An error occurred. But could be ignored if system says token expired. Exception details {0}", ex.Message); Elmah.ErrorLog.GetDefault(null).Log(new Elmah.Error(ex)); response = false; } _logger.Info(_errorMessageBuilder.ToString()); return(response); }
private List <string> GetFolders(BOAuthentication authModel) { XmlDocument docRecv = new System.Xml.XmlDocument(); List <string> _lstfolderIds = new List <string>(); _biRepository.CreateWebRequest(send: null, recv: docRecv, method: "GET", URI: authModel.URI, URIExtension: "/biprws/infostore/Root%20Folder/children", pLogonToken: authModel.LogonToken); XmlNamespaceManager nsmgrGET = new XmlNamespaceManager(docRecv.NameTable); nsmgrGET.AddNamespace("rest", authModel.NameSpace); ReportCategory category = new ReportCategory(); XmlNodeList nodeList = docRecv.SelectNodes("//rest:attr[@name='type']", nsmgrGET); for (int i = 0; i < nodeList.Count; i++) { if (nodeList.Item(i).InnerText == "Folder") { category.Name = docRecv.SelectNodes("//rest:attr[@name='name']", nsmgrGET)[i].InnerText; category.InfoStoreId = docRecv.SelectNodes("//rest:attr[@name='id']", nsmgrGET)[i].InnerText; category.Description = docRecv.SelectNodes("//rest:attr[@name='description']", nsmgrGET)[i].InnerText; category.Cuid = docRecv.SelectNodes("//rest:attr[@name='cuid']", nsmgrGET)[i].InnerText; _lstfolderIds.Add(category.InfoStoreId); //GetChildren(authModel, category); } } return(_lstfolderIds); }
private void GetChildren(BOAuthentication authModel, ReportCategory parentCat) { XmlDocument docRecv = new System.Xml.XmlDocument(); _biRepository.CreateWebRequest ( send: null, recv: docRecv, method: "GET", URI: authModel.URI, URIExtension: string.Format("/biprws/infostore/{0}/children", parentCat.InfoStoreId), pLogonToken: authModel.LogonToken ); XmlNamespaceManager nsmgrGET = new XmlNamespaceManager(docRecv.NameTable); nsmgrGET.AddNamespace("rest", authModel.NameSpace); XmlNodeList list = docRecv.GetElementsByTagName("entry"); for (int i = 1; i <= list.Count; i++) { XmlNode x = list[i - 1]; string format = "(//rest:attr[@name='{0}'])[{1}]"; if (x.SelectSingleNode(string.Format(format, "type", i), nsmgrGET).InnerText == "Folder" && x.SelectSingleNode(string.Format(format, "name", i), nsmgrGET).InnerText != "Dashboards") { ReportCategory subCat = new ReportCategory() { Name = x.SelectSingleNode(string.Format(format, "name", i), nsmgrGET).InnerText, InfoStoreId = x.SelectSingleNode(string.Format(format, "id", i), nsmgrGET).InnerText, Description = x.SelectSingleNode(string.Format(format, "description", i), nsmgrGET).InnerText, Cuid = x.SelectSingleNode(string.Format(format, "cuid", i), nsmgrGET).InnerText }; parentCat.SubCategories.Add(subCat); GetChildren(authModel, subCat); } else if (x.SelectSingleNode(string.Format(format, "name", i), nsmgrGET).InnerText != "Dashboards") { parentCat.Reports.Add(new Report() { Name = x.SelectSingleNode(string.Format(format, "name", i), nsmgrGET).InnerText, InfoStoreId = x.SelectSingleNode(string.Format(format, "id", i), nsmgrGET).InnerText, Description = x.SelectSingleNode(string.Format(format, "description", i), nsmgrGET).InnerText, Cuid = x.SelectSingleNode(string.Format(format, "cuid", i), nsmgrGET).InnerText }); } } }
public ReportCategory GetReportList(BOAuthentication authModel, string defaultFolderId) { //TODO: Unit test it or Understand refactor it for readability ReportCategory category = new ReportCategory(); XmlDocument docRecv = new System.Xml.XmlDocument(); try { _logMessages.Append("Getting reports list from BO System."); //Get all folders from Root Folder List <string> _lstfolderIds = GetFolders(authModel); //For every folder for (int i = 0; i < _lstfolderIds.Count(); i++) { //Get the list of reports within that folder //TODO: Check with the send param,it should not be null _biRepository.CreateWebRequest(send: null, recv: docRecv, method: "GET", URI: authModel.URI, URIExtension: "/biprws/infostore/" + _lstfolderIds[i], pLogonToken: authModel.LogonToken); XmlNamespaceManager nsmgrGET = new XmlNamespaceManager(docRecv.NameTable); nsmgrGET.AddNamespace("rest", authModel.NameSpace); XmlNodeList nodeList = docRecv.SelectNodes("//rest:attr[@name='type']", nsmgrGET); if (nodeList.Item(0).InnerText.Equals("Folder", StringComparison.OrdinalIgnoreCase)) { ReportCategory parentCat = new ReportCategory() { Name = docRecv.SelectSingleNode("//rest:attr[@name='name']", nsmgrGET).InnerText, InfoStoreId = docRecv.SelectSingleNode("//rest:attr[@name='id']", nsmgrGET).InnerText, Description = docRecv.SelectSingleNode("//rest:attr[@name='description']", nsmgrGET).InnerText, Cuid = docRecv.SelectSingleNode("//rest:attr[@name='cuid']", nsmgrGET).InnerText }; category.ParentCategories.Add(parentCat); //Find sub reports of this report GetChildren(authModel, parentCat); } } _logMessages.Append("Finished Iterating all reports folder"); } catch (Exception ex) { _logMessages.AppendFormat("An Error occurred getting reports list Exception message {0}.", ex.Message); _logger.Info(_logMessages.ToString()); throw; } _logger.Info(_logMessages.ToString()); return(category); }
public BOUser AuthenticateWithSAPAndGetToken(UserCredential userCredential) { string baseUrl = ConfigurationManager.AppSettings["BOBaseUrl"]; _errorMessageBuilder.AppendFormat("User Login Attempt with BO Server {0}.", baseUrl); string userAuth = (userCredential.IsInternalUser) ? ConfigurationManager.AppSettings["BOInternalAuth"] : ConfigurationManager.AppSettings["BOExternalAuth"]; _errorMessageBuilder.AppendFormat("User Login Type {0}. Login details {1}.", userCredential.IsInternalUser ? "Internal":"External", userAuth); BOAuthentication boAuthmodel = new BOAuthentication() { UserName = userCredential.Username, Password = userCredential.Password, URI = baseUrl, UserAuth = userAuth }; try { _errorMessageBuilder.Append("Invoking Authentication Service."); var authResult = _authenticationService.AuthenticateUserAndGetToken(boAuthmodel); if (authResult.StatusCode == 0) { _errorMessageBuilder.Append("User successfully logged in."); BOUser retValue = new BOUser { LoginToken = authResult.LogonToken, MustChangePassword = authResult.MustChangePassword, BOSessionId = authResult.BOSesssionID, BOSerializedSessionId = authResult.BOSerializedSessionId }; _errorMessageBuilder.AppendFormat("User :{0} Successfully logged into BO System as external user.", userCredential.Username); _logger.Info(_errorMessageBuilder.ToString()); return(retValue); } _errorMessageBuilder.Append("Successfully invoked authentication service. But did not receive valid output. Status Code : " + authResult.StatusCode); } catch (System.Exception ex) { _errorMessageBuilder.Append("An error occurred calling authentication service. Exception details " + ex.Message); Elmah.ErrorLog.GetDefault(null).Log(new Elmah.Error(ex)); } _logger.Info(_errorMessageBuilder.ToString()); //TODO: Check if null is handled or return expected return type. Just have one return. return(null); }
public WebiReportsController(IBOReportService boReportService, IActiveAnalyticsLogger logger) { _boReportService = boReportService; _baseUrl = ConfigurationManager.AppSettings["BOBaseUrl"]; _defaultFolderId = ConfigurationManager.AppSettings["BIRepositoryDefaultReportsFolderId"]; _baseUrlWithHostName = ConfigurationManager.AppSettings["BOBaseUrlWithHostName"]; _logger = logger; _logMessages = new StringBuilder(); _boAuthmodel = new BOAuthentication() { UserName = string.Empty, Password = string.Empty, URI = _baseUrl, LogonToken = string.Empty, BOSesssionID = string.Empty, UriWithHostName = _baseUrlWithHostName }; }
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; } } }
public bool Logoff(BOAuthentication authModel) { bool response = false; using (SessionPortClient serviceProxy = new SessionPortClient()) { try { _logMessages.AppendFormat("Performing logout for user with session id {0}.", authModel.BOSesssionID); serviceProxy.logout(authModel.BOSesssionID); response = true; _logMessages.Append("Successfully logged out"); } catch (System.Exception ex) { _logMessages.AppendFormat("Logged out exception occurred. Can ignore exception message {0}.", ex.Message); response = false; //eat up exception, UI really doesn't care for it } } _logger.Info(_logMessages.ToString()); return(response); }