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); }
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()); }