示例#1
0
        /// <summary>
        /// Application Error event receiver. Overide this to process error events.
        /// Remember to call base.Application_Error after you have completed processing or
        /// error handling for proper logging/redirection will be broken site-wide.
        ///
        /// Alternatively you may also listen for the Error event from this class which does not
        /// have the base call requirement post processing.
        /// </summary>
        /// <param name="sender">HttpApplication</param>
        /// <param name="e">Event arguments</param>
        protected virtual void Application_Error(object sender, EventArgs e)
        {
            String logMethodName = ".Application_Error(object sender, EventArgs e) - ";

            _log.Debug(logMethodName + "Begin Method");

            Exception exception = Server.GetLastError();

            //TODO: Right now any error that makes it this far is just logged and sent
            //on its way for ASP.NET and IIS to handle with the correct re-directs.
            //There may be states where we want to do something else instead of the defalt
            //redirect configuration. Analysis should be done on various negative case
            //states we may want to handle for here, in particular for any security vectors
            //that throwing/processing a default response may be undesirable.

            // cmak. SWD-5581. log Request.Path errors as WARN.  else log exception as error.  note that string compare is case sensitive.
            Mvc3Helper helper = new Mvc3Helper();

            if (helper.IsRequestPathException(exception))
            {
                _log.Warn(logMethodName + "There has been a possible security warning with the ASA Web Application", exception);
            }
            else
            {
                _log.Error(logMethodName + "There has been an error with the ASA Web Application", exception);
            }

            _log.Debug(logMethodName + "End Method");
        }
示例#2
0
        private static SearchResultsModel handleNoResults(string input)
        {
            if (input != null)
            {
                _log.Warn("search results were null: " + input);
            }
            else
            {
                _log.Warn("search results were null and input was null");
            }

            SearchResultsModel results = new SearchResultsModel();

            results.ErrorList.Add(new ErrorModel("There was a problem performing the search"));
            return(results);
        }
示例#3
0
        /// <summary>
        /// Save any changes to the profile.
        ///
        /// Profile default validation requires the user to own the record being created/updated and requires them to be logged in.
        /// </summary>
        /// <returns>true=success; false=failure</returns>
        public bool Save()
        {
            String logMethodName = ".Save() - ";

            _log.Debug(logMethodName + "Begin Method");
            if (_isAnonymous)
            {
                _log.Warn(logMethodName + "Cannot save the information of an anonymous user");
                throw new WtfException("Cannot save the information of an anonymous user");
            }

            // Stage 1: Hard coded validators <-- You are here
            // Stage 2: Load Validators from Config <-- FUTURE
            // Stage 3: Internal Validator Configuration Support <-- FUTURE

            Boolean validated = false;

            _log.Debug(logMethodName + "Loading save data validators");
            try
            {
                //First load validators
                List <IContextActionValidationRequest <IContextActionValidator> > validationRequests =
                    new List <IContextActionValidationRequest <IContextActionValidator> >();

                // Two rulesets right now for saving:
                // 1. new user accounts with no profiles get one created (this is mainly for testing and will be disabled or not
                // exposed in prod will be supported in prod at some point post decemeber launch as needed)
                //
                // 2. User can save only own records. Internalizes a common type of fine grained security check
                validationRequests.Add((IContextActionValidationRequest <IContextActionValidator>)
                                       new ContextActionValidationRequest <MustbeLoggedInValidator>());

                if (!_newProfile)
                {
                    validationRequests.Add((IContextActionValidationRequest <IContextActionValidator>)
                                           new ContextActionValidationRequest <ManageOwnRecordsValidator>(_orignalProfileData, _profileData));
                }

                //NOTE For now ALL validators must return true for a successful save
                _log.Debug(logMethodName + "Validating save data request");
                foreach (IContextActionValidationRequest <IContextActionValidator> request in validationRequests)
                {
                    if (!request.Process())
                    {
                        validated = false;
                        break;
                    }

                    validated = true;
                }
            }
            catch (Exception ex)
            {
                throw new WtfException("Profile save request validation failure. Data save aborted.", ex);
            }

            if (validated)
            {
                _log.Debug(logMethodName + "Save request validated successfully, saving changes");

                _profileData.LastModified   = DateTime.Now;
                _profileData.LastModifiedBy = _memberId;

                #region Save Data Logic
                //update already exsiting member profile
                try
                {
                    _log.Debug(logMethodName + "Calling IContextDataProvider.UpdateMemberProfile(_profileData, _profileData.ProviderKeys) - Attempting to save the member profile data");
                    _profileData = new MemberProfileData(_provider.UpdateMemberProfile(_profileData, _profileData.ProviderKeys));
                }
                catch (Exception ex)
                {
                    _log.Error(logMethodName + "Error occured while attempting to save the profile.", ex);
                    throw new WtfException("Error occured while attempting to save the profile.", ex);
                }
                #endregion

                //After a successful save or update take the current profile data and copy it to the back-up
                //data variable.
                _orignalProfileData = _profileData;
                _isDirty            = false;

                _log.Debug(logMethodName + "Save request was successful!");
                _log.Debug(logMethodName + "End Method");
                return(true);
            }
            else
            {
                _log.Debug(logMethodName + "Save request did not validate successfully, skipping save");
            }

            _log.Debug(logMethodName + "End Method");
            return(false);
        }
示例#4
0
        private XmlNode getQuery(string objectName, string columnList, string whereClause, string orderBy, bool isRetry)
        {
            String logMethodName = ".getQuery(string objectName, string columnList, string whereClause, string orderBy, bool isRetry) - ";

            _log.Debug(logMethodName + "Begin Method");

            XmlNode queryResults             = null;
            netForumXMLSoapClient xWebClient = null;

            try
            {
                _log.Debug(logMethodName + "Creating netForumXMLSoapClient.");
                xWebClient = new netForumXMLSoapClient();
                _log.Debug(logMethodName + "netForumXMLSoapClient Created Successfully");

                logGetQuery(objectName, columnList, whereClause, orderBy, isRetry);
                _log.Debug(logMethodName + "Calling netForumXMLSoapClient.GetQuery(ref ASA.Web.Services.Common.xWeb.AuthorizationToken AuthorizationToken, string szObjectName, string szColumnList, string szWhereClause, string szOrderBy)");
                queryResults = xWebClient.GetQuery(ref _authToken, objectName, columnList, whereClause, orderBy);
                _log.Debug(logMethodName + "xWebClient.GetQuery(...) completed");
            }
            catch (TimeoutException te)
            {
                _log.Error(logMethodName + "getQuery: TimeoutException on xWeb service call.  make sure endpoint is reachable and configured correctly.", te);

                if (!retryGet(xWebClient, out queryResults, objectName, columnList, whereClause, orderBy))
                {
                    ProxyHelper.HandleServiceException(xWebClient);
                    throw te;
                }
            }
            //we do not want to retry these. These are errors that will not be fixed by a retry, i.e. invalid credentials
            //catch (FaultException fe)
            //{
            //    _log.Error(logMethodName + "There has been an error for an xWeb GET operation: " + objectName, fe);
            //    throw fe;
            //}
            catch (CommunicationException ce)
            {
                _log.Error(logMethodName + "There has been an error attempting to communicate with XWeb, attempting retry (if enabled)", ce);


                // This will cause the AuthorizationToken to be refreshed,
                // and it will perform ONE retry call to xWeb to GetQuery() following this CommunicationException
                if (isRetry == false && ce.Message.StartsWith("System.Web.Services.Protocols.SoapException: Failed"))
                {
                    ProxyHelper.HandleServiceException(xWebClient);
                    _log.Info(logMethodName + "getQuery: Going to retry after getting a new Auth Token");
                    getNewAuthToken();

                    _log.Debug(logMethodName + "Calling netForumXMLSoapClient.GetQuery(ref ASA.Web.Services.Common.xWeb.AuthorizationToken AuthorizationToken, string szObjectName, string szColumnList, string szWhereClause, string szOrderBy)");
                    queryResults = getQuery(objectName, columnList, whereClause, orderBy, true);
                    _log.Debug(logMethodName + "xWebClient.GetQuery(...) completed");
                }
                else
                {
                    _log.Warn(logMethodName + "getQuery: CommunicationException on xWeb service call.  make sure endpoint is reachable and configured correctly... this may be due to Token expiration", ce);
                    if (!retryGet(xWebClient, out queryResults, objectName, columnList, whereClause, orderBy))
                    {
                        ProxyHelper.HandleServiceException(xWebClient);
                        throw ce;
                    }
                }
            }
            finally
            {
                if (xWebClient.State != CommunicationState.Closed)
                {
                    ProxyHelper.CloseChannel(xWebClient);
                }
            }

            _log.Debug(logMethodName + "End Method");
            return(queryResults);
        }
示例#5
0
        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);
        }
示例#6
0
        public SiteMember CreateMember(MemberAuthInfo authInfo, MemberProfileData profile, out MemberCreationStatus status, IList <IContextActionValidationRequest <IContextActionValidator> > validationRequests = null)
        {
            const string logMethodName = ".CreateMember(MemberAuthInfo, MemberProfileData, out MemberCreationStatus, IList<IContextActionValidationRequest<IContextActionValidator>>)";
            const string logEndMessage = logMethodName + " - End Method";

            _log.Info(logMethodName + " - Creating new SiteMember");
            _log.Debug(logMethodName + " - Begin Method");
            SiteMember newMember = null;

            status = MemberCreationStatus.Error;

            IMemberAccountData accountData = null;
            int timesToTry = 2;

            //SWD-7461 - adding retry logic.
            for (int i = 0; i < timesToTry; i++)
            {
                try
                {
                    _log.Debug(logMethodName + " - Calling ISecurityAdapter.CreateMember(MemberAuthInfo authInfo, MemberProfileData data, out MemberCreationStatus status)");
                    status      = MemberCreationStatus.Error;
                    accountData = _adapter.CreateMember(authInfo, profile, out status);
                    break;
                }
                catch (Exception ex)
                {
                    _log.Error(logMethodName + " - Error Creating new member account using the ISecurityAdapter.CreateMember will retry again", ex);
                    System.Threading.Thread.Sleep(1000);
                    accountData = null;
                }
            }

            if (status == MemberCreationStatus.Success)
            {
                _log.Info(logMethodName + " - MemberAccount created successfully by ISecurityAdapter.CreateMember - Creating MemberProfile");

                var memberProfile = new MemberProfileData(profile)
                {
                    MemberId       = accountData.MemberId,
                    LastModified   = DateTime.Now,
                    LastModifiedBy = accountData.MemberId
                };
                if (memberProfile.ProviderKeys == null)
                {
                    memberProfile.ProviderKeys = new Dictionary <string, object>();
                }
                memberProfile.ProviderKeys.Add("ActiveDirectoryKey", accountData.MemberId); // We prob dont need this, code using the ADKey lower in the framework will be ignored

                try
                {
                    IMemberProfileData data;
                    _log.Debug(logMethodName + " - Calling IContextDataProvider.CreateMemberProfile(MemberProfileData data, ProviderKeys keys)");
                    //TODO verify and remove provider key integration at this layer. - May need pin based lookup for pre-registered accounts to call update.
                    data          = _provider.CreateMemberProfile(memberProfile, memberProfile.ProviderKeys);
                    memberProfile = new MemberProfileData(data);
                }
                catch (Exception ex)
                {
                    _log.Error(logMethodName + " - Error Creating new member profile using the IContextDataProvider - Rolling back new account", ex);
                    _log.Info(logMethodName + " - Rolling back - STEP 1. DELETE MEMBER ACCOUNT");
                    _log.Debug(logMethodName + " - Calling ISecurityAdapter.DeleteMember(Object memberId)");

                    _adapter.DeleteMember(accountData.Username);
                    status = MemberCreationStatus.AdapterError;

                    _log.Debug(logEndMessage);
                    accountData = null;
                }

                try
                {
                    newMember = new SiteMember(accountData, memberProfile);
                }
                catch (Exception ex)
                {
                    _log.Error(logMethodName + " - Error Creating new sitemember instance", ex);
                    _log.Debug(logEndMessage);
                    newMember = null;
                }
            }
            else
            {
                // SWD-5616
                _log.Warn(logMethodName + " - Member Creation Unsuccessful.  Status: " + status);
            }

            _log.Debug(logEndMessage);
            return(newMember);
        }