Exemplo n.º 1
0
        /// <summary>
        /// Gets the active directory key from context.
        /// </summary>
        /// <returns></returns>
        public string GetActiveDirectoryKeyFromContext()
        {
            const string logMethodName = "GetActiveDirectoryKeyFromContext() - ";

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

            var key = string.Empty;

            try
            {
                if (HttpContext.Current.Request.Cookies["IndividualId"] != null)
                {
                    key = HttpContext.Current.Request.Cookies["IndividualId"].Value;
                }
                else
                {
                    var user = Membership.GetUser();
                    if (user != null && user.UserName != null)
                    {
                        key = GetMemberByEmail(user.UserName).ActiveDirectoryKey;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("error with: " + logMethodName, ex);
                key = string.Empty;
            }

            Log.Debug(logMethodName + "End Method");

            return(key);
        }
Exemplo n.º 2
0
        static public void ValidateTicket(string Domain, string UserName, string EncTicket)
        {
            bool TicketValid = true;

            //Decrypt the ticket
            try
            {
                Ticket UserTicket = Encryption.Decrypt <Ticket>(EncTicket, _Password, UserName);

                //Check Username
                if (UserTicket.UserName != UserName || UserTicket.Domain != Domain)
                {
                    //Ticket is not valid
                    TicketValid = false;
                }
            }
            catch (Exception ee)
            {
                if (_Log.IsErrorEnabled)
                {
                    _Log.Error(String.Format("Invalid Ticket for user {0}\\{1}", Domain, UserName), ee);
                }
                TicketValid = false;
            }
            if (!TicketValid)
            {
                throw new InvalidTicketException("Invalid Ticket");
            }
        }
Exemplo n.º 3
0
        public AppToolModel GetAppTool(string toolType)//(string personId, string toolType)
        {
            AppToolModel AppTool = null;

            string personId = ""; // TODO: get "individualId" from security context here, and use that value.

            if (AppToolValidation.ValidateSearchId(personId) && AppToolValidation.ValidateSearchId(toolType))
            {
                int searchId; int toolTypeId;
                if (Int32.TryParse(personId, out searchId) && Int32.TryParse(toolType, out toolTypeId))
                {
                    if (_appToolAdapter == null)
                    {
                        _log.Error(_appToolAdapterExceptionMessage);
                        AppTool = new AppToolModel();
                        ErrorModel error = new ErrorModel(_appToolAdapterExceptionMessage, "Web AppTool Service");
                        AppTool.ErrorList.Add(error);
                    }
                    else
                    {
                        AppTool = _appToolAdapter.GetAppTool(searchId, toolTypeId);
                    }
                }
            }
            else
            {
                AppTool = new AppToolModel();
                ErrorModel error = new ErrorModel("Invalid search criteria", "Web AppTool Service");
                AppTool.ErrorList.Add(error);
            }

            return(AppTool);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds logging to the method invocation.
        /// </summary>
        /// <param name="invocation"></param>
        /// <returns> return value of the targetd method</returns>
        public object Invoke(IMethodInvocation invocation)
        {
            IASALog log = ASALogManager.GetLogger(invocation.TargetType);

            string        methodName = invocation.TargetType.ToString() + "." + invocation.Method.Name;
            StringBuilder arguments  = new StringBuilder();

            ParameterInfo[] parameterInfos = invocation.Method.GetParameters();
            object[]        argValues      = invocation.Arguments;
            for (int i = 0; i < parameterInfos.Length; i++)
            {
                arguments.Append(parameterInfos[i].Name).Append("=").Append(argValues[i]);
                if (i < (parameterInfos.Length - 1))
                {
                    arguments.Append("; ");
                }
            }
            if (LogEntry)
            {
                log.LogMethodEntry(methodName, arguments.ToString());
            }

            object   returnValue          = null;
            bool     exitThroughException = false;
            DateTime startTime            = DateTime.Now;

            try
            {
                returnValue = invocation.Proceed();
                return(returnValue);
            }
            catch (Exception e)
            {
                if (logException)
                {
                    log.Error("Exception occured while calling method " + methodName, e);
                }
                exitThroughException = true;
                throw;
            }
            finally
            {
                if (!exitThroughException && logExit)
                {
                    TimeSpan executionTime = DateTime.Now - startTime;
                    if (returnValue == null)
                    {
                        log.LogMethodExit(methodName, "", arguments.ToString(), executionTime);
                    }
                    else
                    {
                        log.LogMethodExit(methodName, returnValue.ToString(), arguments.ToString(), executionTime);
                    }
                }
            }
        }
Exemplo n.º 5
0
        public IdentityResult RetrieveIdentity(Dictionary <string, object> context)
        {
            const string logMethodName = ".RetrieveIdentity(Dictionary<string, object> context) - ";

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

            // Based on partner name, Populate sso custom attributes from ASAMember Model retrieved by call to SAL
            String         partnerName   = (String)context["partnerName"];
            String         optionalParam = (String)context["optionalParam"];
            IdentityResult result        = new IdentityResult();

            try
            {
                string          memberPath     = UtilityMethods.ReadConfigValue("pathGetMember");
                string          memberResponse = WebServiceRequester.MakeServiceCall(memberPath);
                SiteMemberModel memberModel    = UtilityMethods.DeserializeResponse <SiteMemberModel>(memberResponse);

                bool getsAdditionalValues = true;

                //Connection with Interships.com
                if (partnerName == "SaltIDP/Internships/PSP_OAuthDevConnection_To_Internships" || partnerName == "SaltIDP/Internships/PSP_OAuthProdConnection_To_Internships")
                {
                    getsAdditionalValues = false;
                    result = AddInternshipsAttributes(result, context, optionalParam, memberModel.PrimaryEmailKey);
                }

                //Connection with community Jive Prod
                if (partnerName.Contains("SaltIDP/Jive"))
                {
                    result = AddJiveAttributes(result, memberModel, optionalParam);
                }
                //Connection with remote Learner
                else if (partnerName == "SaltIDP/RemoteLearner/PSP_Dev_ConnectionTo_MoodlePortal" || partnerName == "SaltIDP/RemoteLearner/PSP_Test_ConnectionTo_MoodlePortal" || partnerName == "SaltIDP/RemoteLearner/PSP_Stage_ConnectionTo_MoodlePortal" || partnerName == "SaltIDP/RemoteLearner/PSP_Prod_ConnectionTo_MoodlePortal")
                {
                    result = AddRemoteLearnerAttributes(result, memberModel);

                    //Setup (create/update) user in Courses
                    MoodleUser mu = new MoodleUser(memberModel);
                    mu.SetupUser();
                }

                result = AddSSOCoreAttributes(result, memberModel, partnerName, getsAdditionalValues);
            }
            catch (Exception ex)
            {
                _log.Error(logMethodName + ex);
                throw ex;
            }
            _log.Debug(logMethodName + "End Method");

            return(result);
        }
Exemplo n.º 6
0
        /// <summary>
        /// QC Issue # 2123
        /// will retrieve the Ref_ExceptionError.BusinessDescription column value given the Ref_Exception.ExceptionErrorCode
        /// from the logging database and add it to the List.
        /// </summary>
        /// <param name="repsonseMessageList">List that the exception error will be added to.</param>
        /// <param name="messageDetails">string which contains the message details to be added to the response message list</param>
        /// <returns>Boolean - true/message added, false/failed to add message to list, instead "No Description Found" error was added </returns>
        public bool AddMessageDetails(ResponseMessageList responseMessageList, string messageDetails)
        {
            Log.Debug("Entering AddMessage() ...");
            bool            success = true;
            ResponseMessage responseMessage;

            if (messageDetails == String.Empty)
            {
                Log.Error("message Details Argument is empty.");
                string Msg = String.Format("Message Details argument is empty. ");
                responseMessage = new ResponseMessage(Msg);
                success         = false;
            }
            else
            {
                responseMessage = new ResponseMessage(messageDetails);
            }


            responseMessageList.Add(responseMessage);

            return(success);
        }
Exemplo n.º 7
0
        private UserModel GetUser()
        {
            const string logMethodName = ".GetUser() - ";

            _log.Debug(logMethodName + "Begin Method");
            UserModel moodleUser = new UserModel();

            string functionName = "core_user_get_users";
            String postData     = String.Format("{0}={1}", "criteria[0][key]=username&criteria[0][value]", this.muModel.username); //username in moodle is the SALT MemberID
            string callResult   = MoodleServiceCall(functionName, postData);

            if (callResult.Contains("exception"))
            {
                // Error (e.g. invalidtoken)
                MoodleExceptionModel moodleError = UtilityMethods.DeserializeResponse <MoodleExceptionModel>(callResult);
                _log.Error("Error in: " + logMethodName + " - " + moodleError.errorcode + " - " + moodleError.message);
                _log.Debug("Debug info in: " + logMethodName + " - " + moodleError.debuginfo);
                throw new Exception(moodleError.message);
            }
            else
            {
                MoodleGetUsersResponseModel responseModel = UtilityMethods.DeserializeResponse <MoodleGetUsersResponseModel>(callResult);
                if (HasAccount(responseModel))
                {
                    if (responseModel.users.Count > 0)
                    {
                        //update Model with the returned id, as update moodle account requires an id returned by get
                        muModel.id = responseModel.users[0].id;
                        moodleUser = responseModel.users[0];
                    }
                }
            }
            _log.Debug(logMethodName + "End Method");

            return(moodleUser);
        }
Exemplo n.º 8
0
 /// <summary>
 /// This method will be used to add the ASADispatchMessageInspector behavior
 /// to the Behaviors collection of the ServiceHost’s service description.
 /// </summary>
 public void AddCustomMessageInspectorBehavior()
 {
     try
     {
         //Add Custom Behavior to all services
         this.Description.Behaviors.Add(new ASADispatchMessageInspector());
     }
     catch (ASAException exASA)
     {
         IASALog Log = ASALogManager.GetLogger(typeof(ASAServiceHost));
         Log.Error("Couldn't add custom message inspection behavior", exASA);
         throw new ApplicationException("Couldn't add custom message inspection behavior:" + exASA.Message +
                                        " Error_code:" + exASA.ExceptionError_id + " Business Message:" + exASA.BusinessDescription);
     }
     catch (Exception ex)
     {
         IASALog Log = ASALogManager.GetLogger(typeof(ASAServiceHost));
         Log.Error("Couldn't add custom message inspection behavior", ex);
         throw new ApplicationException("Couldn't add custom message inspection behavior:" + ex.Message);
     }
 }
Exemplo n.º 9
0
 /// <summary>
 /// Add ASAFaultHandler to the ASAServiceHost
 /// </summary>
 public void AddCustomFaultHandling()
 {
     try
     {
         foreach (ChannelDispatcher dispatcher in    this.ChannelDispatchers)
         {
             dispatcher.ErrorHandlers.Add(new ASAFaultErrorHandler());
         }
     }
     catch (ASAException exASA)
     {
         IASALog Log = ASALogManager.GetLogger(typeof(ASAServiceHost));
         Log.Error("Couldn't add ASAFaultErrorHandler to the ASAServiceHost", exASA);
         throw new ApplicationException("Couldn't add ASAFaultErrorHandler to the ASAServiceHost:" + exASA.Message +
                                        " Error_code:" + exASA.ExceptionError_id + " Business Message:" + exASA.BusinessDescription);
     }
     catch (Exception ex)
     {
         IASALog Log = ASALogManager.GetLogger(typeof(ASAServiceHost));
         Log.Error("Couldn't add ASAFaultErrorHandler to the ASAServiceHost", ex);
         throw new ApplicationException("Couldn't add ASAFaultErrorHandler to the ASAServiceHost:" + ex.Message);
     }
 }
Exemplo n.º 10
0
        private void AddCustomSchemaValidation()
        {
            try
            {
                bool   validateRequest            = Parameters.Instance.EnableASAServiceRequestSchemaValidation;
                bool   validateReply              = Parameters.Instance.EnableASAServiceReplySchemaValidation;
                string messageContractSchemasPath = Parameters.Instance.TargetMessageContractSchemasPath;

                this.Description.Behaviors.Add(new ASASchemaValidationServiceBehavior(messageContractSchemasPath, validateRequest, validateReply));
            }
            catch (ASAException exASA)
            {
                IASALog Log = ASALogManager.GetLogger(typeof(ASAServiceHost));
                Log.Error("Couldn't add ASAFaultErrorHandler to the ASAServiceHost", exASA);
                throw new ApplicationException("Couldn't add ASAFaultErrorHandler to the ASAServiceHost:" + exASA.Message +
                                               " Error_code:" + exASA.ExceptionError_id + " Business Message:" + exASA.BusinessDescription);
            }
            catch (Exception ex)
            {
                IASALog Log = ASALogManager.GetLogger(typeof(ASAServiceHost));
                Log.Error("Couldn't add ASAFaultErrorHandler to the ASAServiceHost", ex);
                throw new ApplicationException("Couldn't add ASAFaultErrorHandler to the ASAServiceHost:" + ex.Message);
            }
        }
Exemplo n.º 11
0
        public GetLoanSelfReportedEntryResponse GetSelfReported(GetLoanSelfReportedEntryRequest getRequest)
        {
            _log.Info("InvokeSelfReportedService.GetSelfReported() starting ...");
            LoanManagementClient             client   = null;
            GetLoanSelfReportedEntryResponse response = null;


            try
            {
                client = new LoanManagementClient();
                ILoanManagement lm = (ILoanManagement)client;
                response = lm.GetLoanSelfReportedEntry(getRequest);
            }
            catch (TimeoutException timeout)
            {
                _log.Error("InvokeSelfReportedService.GetSelfReported() Timeout Exception:" + timeout.Message);
                ProxyHelper.HandleServiceException(client);
            }
            catch (CommunicationException comm)
            {
                _log.Error("InvokeSelfReportedService.GetSelfReported() Communication Exception:" + comm.Message);
                ProxyHelper.HandleServiceException(client);
            }
            catch (Exception e)
            {
                _log.Error("InvokeSelfReportedService.GetSelfReported() Exception:" + e.Message);
            }
            finally
            {
                if (client != null && client.State != CommunicationState.Closed)
                {
                    ProxyHelper.CloseChannel(client);
                }
            }


            _log.Info("InvokeSelfReportedService.GetSelfReported() ending ...");
            return(response);
        }
Exemplo n.º 12
0
        public GetAppToolResponse GetAppTool(GetAppToolRequest getRequest)
        {
            _log.Info("InvokeAppToolService.GetAppTool() starting ...");
            AppToolClient      client   = null;
            GetAppToolResponse response = null;

            try
            {
                client = new AppToolClient();
                IAppTool pm = (IAppTool)client;
                response = pm.GetAppTool(getRequest);
            }
            catch (TimeoutException timeout)
            {
                _log.Error("InvokeAppToolService.GetAppTool() Timeout Exception:" + timeout.Message);
                ProxyHelper.HandleServiceException(client);
            }
            catch (CommunicationException comm)
            {
                _log.Error("InvokeAppToolService.GetAppTool() Communication Exception:" + comm.Message);
                ProxyHelper.HandleServiceException(client);
            }
            catch (Exception e)
            {
                _log.Error("InvokeAppToolService.GetAppTool() Exception:" + e.Message);
            }
            finally
            {
                if (client != null && client.State != CommunicationState.Closed)
                {
                    ProxyHelper.CloseChannel(client);
                }
            }


            _log.Info("InvokeAppToolService.GetAppTool() ending ...");
            return(response);
        }
Exemplo n.º 13
0
        public ActionResult SSOService()
        {
            // Either an authn request has been received or login has just completed in response to a previous authn request.

            _log.Debug("SSO Service Begin");
            string partnerSP   = null;
            string myCurrentSP = SAMLIdentityProvider.GetPartnerPendingResponse();
            Dictionary <string, object> paramDictionary = new Dictionary <string, object> {
                { "optionalParam", Request.Params["optionalParam"] }
            };

            if (Request.Form.AllKeys.Contains("SAMLRequest") || (Request.QueryString.AllKeys.Contains("SAMLRequest") && (Request.QueryString.AllKeys.Contains("RelayState") || Request.QueryString.AllKeys.Contains("Signature"))))
            {
                // Receive the authn request from the service provider (SP-initiated SSO).
                _log.Debug("Calling ReceiveSSO");
                SAMLIdentityProvider.ReceiveSSO(Request, out partnerSP);
                myCurrentSP = SAMLIdentityProvider.GetPartnerPendingResponse();
                _log.Debug("Received SSO from " + partnerSP);
            }

            // If the user isn't logged in at the identity provider, force the user to login.
            if (!User.Identity.IsAuthenticated)
            {
                _log.Debug("Redirecting to login");
                FormsAuthentication.RedirectToLoginPage();
                return(new EmptyResult());
            }


            // The user is logged in at the identity provider.
            // Respond to the authn request by sending a SAML response containing a SAML assertion to the SP.
            // Use the configured or logged in user name as the user name to send to the service provider (SP).
            // Include some user attributes.
            string userName = WebConfigurationManager.AppSettings[AppSettings.SubjectName];
            IDictionary <string, string> attributes = new Dictionary <string, string>();

            if (string.IsNullOrEmpty(userName))
            {
                try
                {
                    string memberPath = UtilityMethods.ReadConfigValue("pathGetMember");
                    _log.Debug("Calling " + memberPath);
                    string          memberResponse = WebServiceRequester.MakeServiceCall(memberPath);
                    SiteMemberModel memberModel    = UtilityMethods.DeserializeResponse <SiteMemberModel>(memberResponse);
                    userName = memberModel.MembershipId.ToString();
                    bool getsAdditionalValues = true;

                    //determine which SP, and populate the respective member attributes
                    myCurrentSP = SAMLIdentityProvider.GetPartnerPendingResponse();
                    //Connection with remote Learner
                    if (myCurrentSP.Contains("oldmoney.remote-learner.net") || myCurrentSP.Contains("saltcourses.saltmoney.org"))
                    {
                        attributes = AddRemoteLearnerAttributes(attributes, memberModel);

                        //Setup (create/update) user in Courses
                        MoodleUser mu = new MoodleUser(memberModel);
                        mu.SetupUser();
                    }

                    if (myCurrentSP.Contains("sso.online.tableau.com"))
                    {
                        attributes = AddTableauAttributes(attributes, memberModel);
                    }

                    if (myCurrentSP.Contains("community.saltmoney.org"))
                    {
                        String optionalParam = (String)paramDictionary["optionalParam"];
                        attributes = AddJiveAttributes(attributes, memberModel, optionalParam);
                    }

                    _log.Debug("Calling AddSSOCoreAttributes");
                    attributes = AddSSOCoreAttributes(attributes, memberModel, myCurrentSP, getsAdditionalValues);
                    _log.Debug("Returned from  AddSSOCoreAttributes with " + attributes.Count() + " Attributes");
                }
                catch (Exception ex)
                {
                    _log.Error(ex);
                    throw ex;
                }
            }
            try {
                _log.Debug("Calling SendSSO for " + userName);
                SAMLIdentityProvider.SendSSO(Response, userName, attributes);
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                throw ex;
            }
            return(new EmptyResult());
        }
Exemplo n.º 14
0
        // Provide a fault. The Message fault parameter can be replaced, or set to
        // null to suppress reporting a fault.
        public void ProvideFault(Exception error, MessageVersion version, ref Message msg)
        {
            _mSELDao = (ISELDao)ContextHelper.GetContextObject("SELDAO");

            ASAException translatedException = new ASAException();

            //catch all, in case error comes into EHF without being translated
            if (error is ASAException)
            {
                translatedException = (ASAException)error;
            }
            else
            {
                ASAExceptionTranslator afterThrowingTranslator = new ASAExceptionTranslator();
                translatedException = afterThrowingTranslator.Translate(error);
            }

            string tidCorrelationID = ASATIDHelper.GetTIDCorrelationID();

            if (error != null && error is NoMatchingObjectException)
            {
                msg = BuildErrorMessage <ASAFaultDetail>(version, "Server", tidCorrelationID, translatedException.Error_FaultString, translatedException.Error_DetailMessage);
            }
            else if (error != null && error is ServiceRequestValidationException)
            {
                msg = BuildErrorMessage <ASAFaultDetail>(version, "Server", tidCorrelationID, translatedException.Error_FaultString + ": " + translatedException.Error_DetailMessage, translatedException.Error_DetailMessage);
            }
            else if (error != null && error is ServiceReplyValidationException)
            {
                msg = BuildErrorMessage <ASAFaultDetail>(version, "Server", tidCorrelationID, translatedException.Error_FaultString, translatedException.Error_DetailMessage);
            }
            else if (error != null && error is ASADemogBusinessException)
            {
                //QC 1690-1693 handle new exception types
                msg = BuildErrorMessage <ASADemogFaultDetail>(version, "Server", tidCorrelationID, translatedException.Error_FaultString + ": " + translatedException.Error_DetailMessage, translatedException.Error_DetailMessage);
            }
            else if (error != null && error is ASABusinessException)
            {
                //QC 1690-1693 handle new exception types
                msg = BuildErrorMessage <ASABusinessFaultDetail>(version, "Server", tidCorrelationID, translatedException.Error_FaultString + ": " + translatedException.Error_DetailMessage, translatedException.Error_DetailMessage);
            }
            else if (error != null && error is Exception)
            {
                switch (translatedException.ExceptionType)
                {
                case "ASADataAccessException":
                case "ASAUnknownException":
                case "ASA.ExcErrCodeUnavail":
                {
                    msg = BuildErrorMessage <ASAFaultDetail>(version, "Server", tidCorrelationID,
                                                             translatedException.BusinessDescription, translatedException.Original_Message);
                    break;
                }

                default:
                {
                    msg = BuildErrorMessage <ASAFaultDetail>(version, "Server", tidCorrelationID,
                                                             translatedException.Error_FaultString, translatedException.Error_DetailMessage);
                    break;
                }
                }
            }

            Log.Error(msg);

            #region add message to the LogException tables

            string payload = string.Empty;

            if (Payload.ContainsMessagePayLoad(tidCorrelationID))
            {
                payload = Payload.GetMessagePayLoad(tidCorrelationID);
            }

            //LogEvent logEventRec = new LogEvent();
            LogException logExceptionRec = new LogException();

            logExceptionRec.CreatedBy        = (ASATIDHelper.GetTIDUsername() != "") ? ASATIDHelper.GetTIDUsername() : "ASA_USER";
            logExceptionRec.CreatedDate      = DateTime.Now;
            logExceptionRec.Payload          = payload.ToString();
            logExceptionRec.ExceptionStack   = error.StackTrace;
            logExceptionRec.Correlationid    = new Guid(tidCorrelationID);
            logExceptionRec.ExceptionErrorid = translatedException.ExceptionError_id;

            long eventID;

            try
            {
                //_mSELDao.AddLogExceptionRecord(logExceptionRec, out eventID);
                Log.Error(payload);
                Log.Error(logExceptionRec);
            }

            catch (Exception ex)
            {
                //if there is an error logging the record to the DB, write payload to log file
                Log.Error(payload);
            }
            #endregion
        }