public static void LogRequestHeaders(WebOperationContext context) { StringBuilder sb = new StringBuilder("\n"); try { if (context != null && context.IncomingRequest != null && context.IncomingRequest.Headers != null) { for (int i = 0; i < context.IncomingRequest.Headers.Count; i++) { String header = context.IncomingRequest.Headers.GetKey(i); String[] values = context.IncomingRequest.Headers.GetValues(header); if (values.Length > 0) { sb.AppendLine(string.Format("The values of {0} header are : ", header)); for (int j = 0; j < values.Length; j++) { sb.Append(string.Format("\t{0}", values[j])); } } else { sb.AppendLine("There is no value associated with the header"); } } } _log.Debug(sb.ToString()); } catch { _log.Debug("Problem logging Http headers."); } }
//Since all the commidized functions are now in AsaMvcApplication we only need to register //the routes and polices we care about. The base implmentation will handle adding the correct //routes for error, published content and common handling needs for the framework. protected override void RegisterRoutes(RouteCollection routes) { String logMethodName = ".RegisterSiteRoutes() - "; _log.Debug(logMethodName + "Begin Method"); if (routes != null) { // Dont bother routing these.... routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" }); //Standard controller routes, Required due to catch all PublishedContentController routes.MapRoute("Home", "Home/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional }); // What is this one for? Login modals? Please comment routes.MapRoute("Account", "Account/{action}/{id}", new { controller = "Account", action = "Index", id = UrlParameter.Optional }); routes.MapRoute("Root", "", new { controller = "Home", action = "Index" }); //routes all requests to root --> Home/Index routes.MapRoute("Config", "Config/{action}", new { controller = "Config", action = "Index" }); } else { //Is it actually possible for this to happen? Is there a case where we expect an external //instnace consumer to call this method rather than it being called from within the Global.asax.cs? //Is there a case where MVC may pass us a null object collection here? _log.Error(logMethodName + "The RouteCollection is null!"); throw new SALTException("The RouteCollection is null!"); } //Alwyas run the base method last here. If there needs to be inserts at the head or foot of the collections //its best to do this witl a completed collection. base.RegisterRoutes(routes); _log.Debug(logMethodName + "End Method"); }
//This is only used in 2 actions, replacing with calls in the methods responsible //private IAsaMemberAdapter _memberAdapter = null; public HomeController() { String logMethodName = ".ctor() - "; _log.Debug(logMethodName + "Begin Method"); //We don't need to do this here, there are a couple actions that need the member adapter //but we can load the adapter in those actions rather than loading the adapter for the //whole class //_memberAdapter = new AsaMemberAdapter(); _log.Debug(logMethodName + "End Method"); }
/// <summary> /// Object will attempt to initalize using the configured providers and the currently logged in user. /// </summary> /// <exception cref="WtfException">Loading wither the security adapter or the profile data provide has failed with an exception.</exception> public SiteMember() { String logMethodName = ".ctor() - "; _log.Debug(logMethodName + "Begin Method"); Init(); _log.Debug(logMethodName + "End Method"); }
static IntegrationLoader() { String logMethodName = ".ctor() - "; _log.Debug(logMethodName + "Begin Method"); Init(); _log.Debug(logMethodName + "End Method"); }
public static string CreateFormsAuthenticationTicket(string partnerId, string saltMemberId) { const string logMethodName = ". GetEncryptedToken()"; _log.Debug(logMethodName + "Begin Method"); string toReturn = ""; if (!string.IsNullOrEmpty(partnerId) && !string.IsNullOrEmpty(saltMemberId)) { DateTime currentDate = DateTime.Now; // Create a forms authentication ticket what will expire in 1 hour FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, saltMemberId, currentDate, currentDate.AddHours(1), true, partnerId); // Encrypt the authentication ticket string encryptedToken = FormsAuthentication.Encrypt(ticket); if (!string.IsNullOrEmpty(encryptedToken)) { toReturn = encryptedToken; } else { _log.Debug("Something wrong during the encryption process!"); } } else { _log.Debug("One of the parameters is empty!"); } _log.Debug(logMethodName + "End Method"); return(toReturn); }
public bool PostJellyVisionQuizResponse(string id, string referrerID, string responses, string personalityType, string encryptedToken) { const string logMethodName = ".PostJellyVisionQuizResponse(string id, string referrerID, string responses, string personalityType) - "; _log.Debug(logMethodName + "Begin Method"); _log.Debug(logMethodName + string.Format("id = [{0}], referrerID = [{1}], responses = [{2}], personalityType = [{3}]", id, referrerID, responses, personalityType)); try { bool toReturn = false; //allow all the origin url to avoid cross domain issue. if (WebOperationContext.Current != null) { WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*"); } FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(encryptedToken); if (string.IsNullOrEmpty(ticket.ToString())) { _log.Debug("Something wrong during the decryption process!"); return(false); } //validate the request with the values extracted from the token if (!ticket.Expired && ticket.Name == id && ticket.UserData == "1") { JellyVisionQuizResponseModel jvqResponse = new JellyVisionQuizResponseModel(); //hardcoding the quizName for now. If we get another then we'll have to change this. jvqResponse.quizName = "Money Personality Quiz"; jvqResponse.Id = !string.IsNullOrWhiteSpace(id) ? int.Parse(id) : 0; jvqResponse.referrerID = referrerID; jvqResponse.responses = responses; jvqResponse.personalityType = personalityType; if (JellyVisionQuizResponseValidation.validateQuizResponseModel(jvqResponse)) { toReturn = _surveyAdapter.AddJellyVisionQuizResponse(jvqResponse); } } else { _log.Debug(logMethodName + "the request expired."); } _log.Debug(logMethodName + "End Method"); return(toReturn); } catch (Exception ex) { _log.Error(logMethodName + ": Exception => " + ex.ToString()); return(false); //throw new SurveyOperationException("Web Survey Service - Exception in ASA.Web.Services.SurveyService.PostJellyVisionQuizResponse()", ex); } }
protected static void SetSessionValue <T>(string strKey, T strValue) { if (System.Web.HttpContext.Current.Session != null) { System.Web.HttpContext.Current.Session[APP_PREFIX + strKey] = strValue; } else { if (!System.Web.HttpContext.Current.Items.Contains("FakeSession")) { System.Web.HttpContext.Current.Items["FakeSession"] = new Dictionary <string, object>(); } ((Dictionary <string, object>)System.Web.HttpContext.Current.Items["FakeSession"])[APP_PREFIX + strKey] = strValue; } try { _log.Debug(string.Format("\nBaseSession: Key = {0}, Value = {1}", strKey, strValue != null ? strValue.ToString() : "NULL")); } catch { _log.Debug(string.Format("\nBaseSession: Key = {0} could not be logged", strKey != null ? strKey : "NULL")); } }
public static void HandleServiceException <T>(T client) where T : ICommunicationObject { _log.Debug("HandleServiceException<T> start"); if (client != null) { if (client.State == CommunicationState.Created) { CloseChannel(client); } else if (client.State == CommunicationState.Faulted) { _log.Debug("HandleServiceException<T> client.Abort();"); client.Abort(); } } _log.Debug("HandleServiceException<T> end"); }
/// <summary> /// Class Constructor - Best pratice is not to override or use this. /// Keep in mind if you do that this is called with every request and your /// context at this state is uncertian without doing pre-checking of multiple values /// </summary> public AsaMvcApplication() { String logMethodName = ".ctor() - "; BeginRequest += (o, e) => { OnAfterRequestStart(e); }; EndRequest += (o, e) => { OnAfterRequestEnd(e); }; MapRequestHandler += (o, e) => { OnAfterApplicationRequestStart(e); }; PostRequestHandlerExecute += (o, e) => { OnAfterApplicationRequestEnd(e); }; CurrentAppState = ApplicationState.NotStarted; if (!_loggingStarted) { //We load logging first and foremost so we can start tracking the //application load process as early as possible. Further this way //if logging load fails we can simply ingore it and move on //while a failure in filters or routes will cause the application startup to //abort. try { log4net.Config.XmlConfigurator.Configure(); _log.Info(logMethodName + "ASA MVC Web Application Logger Started - APPLICATION LOGGING START"); } catch (Exception ex) { //There is nothing we can do here, there is no way to log this failue //and we don't want to abort the application just because logging won't load _log.Info(logMethodName + "Exception caught. Message: " + ex.Message); } _loggingStarted = true; } //NOTE: Logging statements from this method will not show up on initial load. //post application launch they will behave normally _log.Debug(logMethodName + "Begin Method"); if (_configuration == null) { try { _log.Debug(logMethodName + "Getting ASAIntegration Config"); _configuration = (ASAIntegration)ConfigurationManager.GetSection("asaIntegration"); } catch (Exception ex) { _log.Error(logMethodName + "Unable to load integration configuration", ex); throw new MVCIntegrationException("Unable to load integration configuration", ex); } } //ASAContextLoader handles lower level lifecycle concerns //like preloading integration/content, and providing application //level context for integration interactions. //This call give the context loader an easy way to hook into the application lifecycle //at the earliest possible point. ASAContextLoader.RegisterApplication(this); _log.Debug(logMethodName + "End Method"); }
public static string GetObjectGUID(string userName) { String logMethodName = ".GetObjectGUID(string userName)"; _log.Debug(logMethodName + "Method Begin"); _log.Debug(logMethodName + "Looking up ActiveDirectory Object ID using ADSI : " + userName); string objectGuid = string.Empty; if (string.IsNullOrEmpty(userName)) { _log.Warn(logMethodName + "Error: Username is empty"); return(objectGuid); } _log.Debug(logMethodName + "Provided username is valid, looking user up in ActiveDirectory"); try { SearchResult result = null; for (int i = 0; i < retries; i++) { _log.Debug(logMethodName + "Attempting directory entry search for " + userName + " Attempt#: " + i); string path = string.Format("LDAP://{0}/{1}", domain, userContainer); using (DirectoryEntry directoryEntry = new DirectoryEntry(path, userId, password, AuthenticationTypes.Secure)) { using (DirectorySearcher search = new DirectorySearcher(directoryEntry)) { search.Filter = String.Format("(cn={0})", userName); search.SearchScope = SearchScope.Subtree; result = search.FindOne(); _log.Debug(logMethodName + "Finished searching active directory"); if (result != null) { _log.Debug(logMethodName + "User found...getting user ObjectId"); objectGuid = new Guid(result.GetDirectoryEntry().NativeGuid).ToString(); break; } else { _log.Debug(logMethodName + "No user found in active directory"); } } } _log.Debug(logMethodName + "There was a problem accessing active directory, retrying..."); System.Threading.Thread.Sleep(sleepTime); } } catch (Exception ex) { throw new Exception("Error attempting to get the AD directory entry for the user", ex); } String guidString = objectGuid != null?objectGuid.ToString() : "NULL"; _log.Debug(logMethodName + "User objectid has been retrieved the id is: " + guidString); return(objectGuid); }
public SearchAdapter() { _log.Debug("START SearchAdapter"); _log.Debug("END SearchAdapter"); }
public AsaController() { String logMethodName = ".ctor() - "; _log.Debug(logMethodName + "Begin Method"); _log.Debug(logMethodName + "End Method"); }
private void Init() { String logMethodName = ".Init() - "; _log.Debug(logMethodName + "Begin Method"); try { _adapter = IntegrationLoader.CurrentSecurityAdapter; } catch (Exception ex) { _log.Error(logMethodName + "Unable to get security adapter", ex); throw new WtfException("Unable to get security adapter", ex); } _log.Debug(logMethodName + "End Method"); }
//private IServiceLocator _serviceLocator = null; //private void SetDefaultLocator() //{ // //Spring.Context.IApplicationContext springContainer = Spring.Context.Support.ContextRegistry.GetContext(); // //_serviceLocator = new CommonServiceLocator.SpringAdapter.SpringServiceLocatorAdapter(springContainer); // var simpleInjectorContainer = new SimpleInjector.Container(); // simpleInjectorContainer.Register<InetForumXMLSoapClient>(() => new netForumXMLSoapClient()); // _serviceLocator = new CommonServiceLocator.SimpleInjectorAdapter.SimpleInjectorServiceLocatorAdapter(simpleInjectorContainer); //} ///// <summary> ///// Test Constructor ///// </summary> ///// <param name="serviceLocator"></param> //public xWebWrapper(IServiceLocator serviceLocator) //{ // if (serviceLocator != null) // { // _serviceLocator = serviceLocator; // } // else // { // SetDefaultLocator(); // } // String logMethodName = ".ctor(IServiceLocator serviceLocator) - "; // _log.Debug(logMethodName + "Begin Method"); // GetAuthorizationToken(); // _log.Debug(logMethodName + "End Method"); //} public xWebWrapper() { // SetDefaultLocator(); String logMethodName = ".ctor() - "; _log.Debug(logMethodName + "Begin Method"); GetAuthorizationToken(); _log.Debug(logMethodName + "End Method"); }
public ChangePasswordStatus ChangePassword(String oldPassword, String newPassword) { String logMethodName = ".ChangePassword(String oldPassword, String newPassword) - "; _log.Debug(logMethodName + " - Begin Method"); MembershipUser user = GetUser(); Boolean changeResponse = false; ChangePasswordStatus status = ChangePasswordStatus.Error; try { changeResponse = user.ChangePassword(oldPassword, newPassword); } catch (Exception ex) { throw new SecurityAdapterException("An error has occured in the .NET Membership provider while calling MembershipUser.ChangePassword(oldPassword, newPassword)", ex); } if (changeResponse) { status = ChangePasswordStatus.Success; } else { status = ChangePasswordStatus.Failure; } _log.Debug(logMethodName + " - End Method"); return(status); }
private string RenderWidget(ASA.Web.Services.SearchService.DataContracts.SearchRecordModel record) { string strReturn = ""; if (HttpContext.Current.Cache[record.Fields["P_Tile_Xml_Path"][0]] != null && HttpContext.Current.Cache[record.Fields["P_Tile_Xml_Path"][0]].ToString() != "") { strReturn = HttpContext.Current.Cache[record.Fields["P_Tile_Xml_Path"][0]].ToString(); } else { string name = ""; string path = HttpContext.Current.Server.MapPath("/PublishedContent" + record.Fields["P_Tile_Xml_Path"][0]); if (File.Exists(path)) { using (XmlTextReader reader = new XmlTextReader(path)) { if (reader != null) { try { _log.Debug("begin reading from the XmlReader"); //position cursor at first properly readable XML element reader.MoveToContent(); bool bFoundElement = false; while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: if (reader.Name == "content") { //read again to retrieve data for "content" reader.Read(); name = reader.Value; bFoundElement = true; } break; default: break; } if (bFoundElement) { break; } } if (!bFoundElement) { _log.Error("ASA.Web.Services.SearchService.Search.RenderWidget(): Search key not found."); } else { //remove chars needed for razor templates name = name.Replace("|%~", ""); name = name.Replace("%|", ""); HttpContext.Current.Cache[record.Fields["P_Tile_Xml_Path"][0]] = name; strReturn = name; } } catch (Exception ex) { _log.Error("ASA.Web.Services.SearchService.RenderWidget(): Exception =>" + ex.ToString()); //assume reader is null strReturn = ""; throw new Exception("Web Search Service - RenderWidget()", ex); } finally { _log.Debug("closing the XmlReader"); reader.Close(); } } } } } return(strReturn); }
/// <summary> /// Creates and instance of the member profile using the passed memberID and accepting the boolean to set anonymous on this instance. /// /// NOTE: All data is lazy loaded on first property access. /// </summary> /// <param name="memberId">Unique member ID to load</param> /// <param name="isAnonymous">true=anonymous; false=not anonymous</param> internal MemberProfile(Object memberId, Boolean isAnonymous) { String logMethodName = ".ctor(Object memberId, Boolean isAnonymous) - "; _log.Debug(logMethodName + "Begin Method"); _isAnonymous = isAnonymous; _memberId = memberId; _provider = IntegrationLoader.CurrentContextDataProvider; _profileData = new MemberProfileData(); _profileData.MemberId = memberId; _orignalProfileData = _profileData; _newProfile = true; if (_isAnonymous) { _profileDataLoaded = true; } _log.Debug(logMethodName + "End Method"); }
public override IMemberAccountData GetMember() { String logMethodName = ".GetMember() - "; _log.Debug(logMethodName + "Begin Method"); MemberAccountData accountData = null; // If we are calling GetMember() then we are looking for the currently logged in user // to prevent uneccassary calls to load Account data we store the member // instance in the Request store. _log.Debug(logMethodName + "Checking Request memory for existing MemberAccountData for the current user"); accountData = GetMemberAccountDataFromRequestContext(); if (accountData == null) { _log.Debug(logMethodName + "MemberAccountData not found or unsuccessful in loading from memory, getting the member account from the data store (ActiveDirectory)"); accountData = (MemberAccountData)base.GetMember(); SetAccountDataFromAD(ref accountData); HttpContext.Current.Items["AsaWebSecurityAdapter[MemberAccountData]"] = accountData; //persistence.Request["AsaWebSecurityAdapter[MemberAccountData]"] = accountData; } _log.Debug(logMethodName + "End Method"); return(accountData); }
static ASAContextLoader() { String logMethodName = ".ctor() - "; _log.Debug(logMethodName + "Begin Method"); try { _log.Debug(logMethodName + "Getting ASAIntegration Config"); _configuration = (ASAIntegration)ConfigurationManager.GetSection("asaIntegration"); } catch (Exception ex) { _log.Error(logMethodName + "Unable to load integration configuration", ex); throw new MVCIntegrationException("Unable to load integration configuration", ex); } _log.Debug(logMethodName + "End Method"); }
public SiteMembership() { String logMethodName = ".ctor()"; _log.Info(logMethodName + " - Creating new static SiteMembership Instance"); _log.Debug(logMethodName + " - Begin Constructor"); try { _log.Debug(logMethodName + " - Retrieving IntegrationLoader.CurrentSecurityAdapter"); _adapter = IntegrationLoader.CurrentSecurityAdapter; } catch (Exception ex) { String message = logMethodName + " - Unable to load security adapter, context init failure"; _log.Fatal(message, ex); throw new WtfException(message, ex); } try { _log.Debug(logMethodName + " - Retrieving IntegrationLoader.CurrentContextDataProvider"); _provider = IntegrationLoader.CurrentContextDataProvider; } catch (Exception ex) { String message = logMethodName + "Unable to load context data provider, context init failure"; _log.Fatal(message, ex); throw new WtfException(message, ex); } _log.Debug(logMethodName + " - End Constructor"); }