private IdentityResult AddRemoteLearnerAttributes(IdentityResult result, SiteMemberModel memberModel) { //ReportingID int reportingIdCount = memberModel.Organizations.Count(org => !string.IsNullOrEmpty(org.ReportingId)); if (reportingIdCount == 1) { var reportingId = memberModel.Organizations.First(org => !string.IsNullOrEmpty(org.ReportingId)).ReportingId; result.AddAttribute("ReportingID", reportingId); } else if (reportingIdCount > 1) { result.AddAttribute("ReportingID", "******"); //passing placeholder value to moodle to mean user has multiple reporting ids } //Courses var courses = memberModel.OrganizationProducts.Where(p => p.ProductTypeID == 1).ToList(); if (courses.Count > 0) { foreach (var course in courses) { //E.g. ("Budgeting", "1"); result.AddAttribute(course.ProductName, course.IsOrgProductActive ? "1" : "0"); } } return(result); }
private IdentityResult AddSSOCoreAttributes(IdentityResult result, SiteMemberModel memberModel, string partnerName, bool getsAdditionalValues) { //Add core attributes result.Identity = memberModel.PrimaryEmailKey; result.AddAttribute("FirstName", memberModel.FirstName); result.AddAttribute("LastName", memberModel.LastName); result.AddAttribute("Email", memberModel.PrimaryEmailKey); result.AddAttribute("PartnerName", partnerName); if (getsAdditionalValues) { string oeCode = "000000", branchCode = "00", oeAndBranch, organizationName = "", organizationLogoName = "", isMemberBenefit = "false"; //determine where a single org info is required to be provided MemberOrganizationModel determinedOrg = new MemberOrganizationModel(); //Connection with remote Learner 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") { //pick determined org based on determined org id if (memberModel.OrganizationIdForCourses != null) { determinedOrg = memberModel.Organizations.Find(o => o.OrganizationId.ToString() == memberModel.OrganizationIdForCourses); } else if (memberModel.Organizations.Count() == 1) //no org determined and there's a single org { determinedOrg = memberModel.Organizations[0]; } } else { //pick the first org for Jive. Internships won't get in here since it sets getsAdditionalValues = false; determinedOrg = memberModel.Organizations[0]; } if (determinedOrg.OECode != null) { oeCode = determinedOrg.OECode; } if (determinedOrg.BranchCode != null) { branchCode = determinedOrg.BranchCode; } oeAndBranch = oeCode + branchCode; organizationName = determinedOrg.OrganizationName; organizationLogoName = determinedOrg.OrganizationLogoName; isMemberBenefit = (!string.IsNullOrWhiteSpace(determinedOrg.OrganizationLogoName) && !determinedOrg.OrganizationLogoName.Equals("nologo", StringComparison.OrdinalIgnoreCase)).ToString(); result.AddAttribute("OECode", oeCode); result.AddAttribute("OEBranch", oeAndBranch); result.AddAttribute("SchoolName", organizationName); result.AddAttribute("SchoolLogoName", organizationLogoName); result.AddAttribute("IsMemberBenefit", isMemberBenefit); //as far as business this is not used/set in courses, may need to confer with oleg though result.AddAttribute("MembershipId", memberModel.MembershipId); } return(result); }
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); }
private IdentityResult AddJiveAttributes(IdentityResult result, SiteMemberModel memberModel, string optionalParam) { //populating isAmbassodor flag string isSchoolAmbassador = "False", enrollmentStatus = "", loanStatus = ""; bool isASAEmployee = false; foreach (var item in memberModel.Roles) { if (item != null && item.IsMemberRoleActive) { if (item.RoleName == "School Ambassador") { isSchoolAmbassador = "True"; } else if (item.RoleName == "ASA Employee") { isASAEmployee = true; } } } if (isASAEmployee) { result.AddAttribute("UserGroup", "SALT Employee"); } else { result.AddAttribute("UserGroup", "SALT Member"); } if (!string.IsNullOrEmpty(memberModel.EnrollmentStatus)) { Dictionary <string, string> enrollmentDict = new Dictionary <string, string>() { { "F", "I'm enrolled full time" }, { "H", "I'm enrolled half time" }, { "L", "I'm enrolled less than half time" }, { "G", "I'm already graduated" }, { "W", "I left before graduating" }, { "X", "I haven't gone to college" } }; enrollmentStatus = enrollmentDict[memberModel.EnrollmentStatus]; } if (memberModel.ProfileQAndAs.Count > 0) { foreach (var qa in memberModel.ProfileQAndAs) { if (qa.QuestionName == "Student Loan Repayment Status") { loanStatus = qa.AnsName; break; } } } if (!String.IsNullOrEmpty(optionalParam)) { result.AddAttribute("CampaignID", optionalParam); } if (string.IsNullOrEmpty(memberModel.CommunityDisplayName)) { memberModel.CommunityDisplayName = ConfigurationManager.AppSettings["CommunityDefaultUserName"].ToString(); } result.AddAttribute("IsSchoolAmbassador", isSchoolAmbassador); result.AddAttribute("CommunityDisplayName", memberModel.CommunityDisplayName); result.AddAttribute("IsCommunityActive", memberModel.IsCommunityActive.ToString()); result.AddAttribute("YearOfBirth", memberModel.YearOfBirth.ToString()); result.AddAttribute("GraduationYear", memberModel.Organizations[0].ExpectedGraduationYear.ToString()); //this needs an answer from business on the rules. result.AddAttribute("EnrollmentStatus", enrollmentStatus); result.AddAttribute("LoanStatus", loanStatus); return(result); }
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()); }
private IDictionary <string, string> AddRemoteLearnerAttributes(IDictionary <string, string> attributes, SiteMemberModel memberModel) { //ReportingID int reportingIdCount = memberModel.Organizations.Count(org => !string.IsNullOrEmpty(org.ReportingId)); if (reportingIdCount == 1) { var reportingId = memberModel.Organizations.First(org => !string.IsNullOrEmpty(org.ReportingId)).ReportingId; attributes.Add("ReportingID", reportingId); } else if (reportingIdCount > 1) { attributes.Add("ReportingID", "******"); //passing placeholder value to moodle to mean user has multiple reporting ids } //Courses var courses = memberModel.OrganizationProducts.Where(p => p.ProductTypeID == 1).GroupBy(n => n.ProductName).Select(y => y.FirstOrDefault()); if (courses.Count() > 0) { foreach (var course in courses) { //E.g. ("Budgeting", "1"); attributes.Add(course.ProductName, course.IsOrgProductActive ? "1" : "0"); } } return(attributes); }
private IDictionary <string, string> AddTableauAttributes(IDictionary <string, string> attributes, SiteMemberModel memberModel) { return(attributes); }