private void Authenticate() { string password = Request.QueryString["p"]; string isPersistentString = Request.QueryString["cp"]; string loginName = this.LoginName; bool isPersistent = true; if (isPersistentString != null) { if (!Boolean.TryParse(isPersistentString, out isPersistent)) { isPersistent = false; } } Guid organizationId = this.OrganizationId; Guid instanceId = this.InstanceId; bool isCustomUrlEnabled = FrameworkConfiguration.Current.WebApplication.CustomUrl.Enabled; if (isCustomUrlEnabled) { if (organizationId == Guid.Empty) { string host = Request.Url.Host; if (!CustomUrlProvider.IsDefaultVanityUrl(host)) { CustomUrlProvider.ParseHost(host, ref organizationId, ref instanceId); } } else if (!GoogleProvider.IsGoogleProviderRequest(Request)) { this.VerifyVanityUrl(organizationId, instanceId); } } if (!(string.IsNullOrEmpty(loginName) || string.IsNullOrEmpty(password) || (organizationId == Guid.Empty))) { if (!isCustomUrlEnabled) { LoginProvider loginProvider = new LoginProvider(); loginProvider.SignOut(true, false); } try { LoginProvider.Current.Authenticate(loginName, Support.Decrypt(password), false, isPersistent, organizationId, instanceId); this.RedirectAfterLogOn(); } catch (AuthenticationException ex) { ShowErrorMessage(ex.Message); } } else { if (GoogleProvider.IsGoogleProviderRequest(Request)) { try { string accessToken = GoogleProvider.ProcessAuthorization(this.Context, ref organizationId, ref instanceId); string firstName = null; string lastName = null; GoogleProvider.GetUserProfile(accessToken, out loginName, out firstName, out lastName); } catch (AuthenticationException ex) { ShowErrorMessage(ex.Message); } if (!string.IsNullOrEmpty(loginName)) { m_EmailToLink = loginName; string message = null; try { string domain = GoogleProvider.GetDomain(Request); if (!string.IsNullOrEmpty(domain)) { EmailSuffixProvider.ParseEmailSuffixName(domain, ref organizationId, ref instanceId); } if (LoginProvider.Current.Authenticate(loginName, null, false, true, organizationId, instanceId)) { this.RedirectAfterLogOn(); } } catch (AuthenticationException ex) { message = ex.Message; } if (!string.IsNullOrEmpty(message)) { if (LoginProvider.Current.GetLogin(loginName) == null) { message = string.Format(CultureInfo.InvariantCulture, Resources.UserContext_ErrorMessage_YourAccountIsNotFound, loginName); } } if (!string.IsNullOrEmpty(message)) { this.ShowErrorMessage(message); this.EnableCustomHandling = false; } } } } }
private void CheckSignupUser() { if ((this.OrganizationId == Guid.Empty) || (this.InstanceId == Guid.Empty)) { Guid orgId = Guid.Empty; Guid insId = Guid.Empty; if (FrameworkConfiguration.Current.WebApplication.CustomUrl.Enabled && m_Organization == null) { if (!CustomUrlProvider.IsDefaultVanityUrl(Request.Url.Host)) { CustomUrlProvider.ParseHost(Request.Url.Host, ref orgId, ref insId); } } this.OrganizationId = orgId; this.InstanceId = insId; if ((this.OrganizationId == Guid.Empty) || (this.InstanceId == Guid.Empty)) { return; } } Organization organization = OrganizationProvider.GetOrganization(this.OrganizationId); if (organization != null) { if (organization.Deleted) { ShowErrorMessage(Resources.LogOnControl_OrganizationIsDeleted); return; } else if (!organization.Active) { ShowErrorMessage(Resources.LogOnControl_OrganizationIsInactive); return; } } else { ShowErrorMessage(Resources.LogOnControl_OrganizationIsNotFound); return; } Instance instance = InstanceProvider.GetInstance(this.InstanceId, this.OrganizationId); if (instance == null) { return; } if (!instance.Active) { ShowErrorMessage(Resources.LogOnControl_InstanceIsInactive); return; } this.OrganizationId = instance.OrganizationId; m_Organization = organization; m_Instance = instance; if (!instance.EnableSignupUser) { return; } Guid groupId = GroupProvider.GetGroupIdOfLowestRoleInInstance(instance.OrganizationId, instance.InstanceId); if (groupId != Guid.Empty) { m_MainContainerHeight = 300; SignupUserTable.Visible = true; } else { SignupUserButton.CommandArgument = string.Empty; } }
/// <summary> /// Occurs when the request state (for example, session state) that is associated with the current request has been obtained. /// </summary> /// <param name="sender">The sourceRow of the event.</param> /// <param name="e">An EventArgs that contains the event data.</param> protected virtual void Application_PostAcquireRequestState(object sender, EventArgs e) { HttpContext http = HttpContext.Current; if (http == null) { return; } if (http.Session == null) { return; } UserContext user = null; Micajah.Common.Bll.Action action = null; CustomUrlElement customUrlSettings = FrameworkConfiguration.Current.WebApplication.CustomUrl; string host = http.Request.Url.Host; bool isDefaultPartialCustomUrl = false; if (customUrlSettings.Enabled) { isDefaultPartialCustomUrl = CustomUrlProvider.IsDefaultVanityUrl(host); } if (!isDefaultPartialCustomUrl) { if (http.Session.IsNewSession) { user = UserContext.Current; if (user != null) { LoginProvider.Current.UpdateSession(user.UserId, http.Session.SessionID); } } if (!http.SkipAuthorization) { if (user == null) { user = UserContext.Current; } if (user == null) { action = ActionProvider.FindAction(CustomUrlProvider.CreateApplicationAbsoluteUrl(Request.Url.PathAndQuery)); if (action != null) { if (action.AuthenticationRequired) { LoginProvider.Current.SignOut(true, Request.Url.PathAndQuery); } } } else if (!customUrlSettings.Enabled) { if (!LoginProvider.Current.ValidateSession(user.UserId, http.Session.SessionID)) { LoginProvider.Current.SignOut(true, true, true); } } } } if (!customUrlSettings.Enabled) { return; } if (!((http.User != null) && (http.User.Identity != null) && http.User.Identity.IsAuthenticated)) { return; } string redirectUrl = string.Empty; Guid organizationId = Guid.Empty; Guid instanceId = Guid.Empty; if (http.Session.IsNewSession || (string.Compare(host, UserContext.VanityUrl, StringComparison.OrdinalIgnoreCase) != 0)) { if (isDefaultPartialCustomUrl) { return; } string vanityUrl = null; bool setAuthCookie = true; CustomUrlProvider.ParseHost(host, ref organizationId, ref instanceId); if (organizationId == Guid.Empty) { Guid userId = Guid.Empty; LoginProvider.ParseUserIdentityName(out userId, out organizationId, out instanceId); if (userId != Guid.Empty) { setAuthCookie = false; vanityUrl = CustomUrlProvider.GetVanityUrl(organizationId, instanceId); } } else { vanityUrl = host; UserContext.VanityUrl = host; } if (string.IsNullOrEmpty(vanityUrl)) { if (!isDefaultPartialCustomUrl) { http.Session.Abandon(); // Important fix of the issue with the same SessionID for all the child domains. redirectUrl = CustomUrlProvider.CreateApplicationUri(http.Request.Url.PathAndQuery); } } else { if (string.Compare(host, vanityUrl, StringComparison.OrdinalIgnoreCase) == 0) { if (user == null) { user = UserContext.Current; } if (user != null) { try { if (user.OrganizationId != organizationId) { user.SelectOrganization(organizationId, setAuthCookie, null, null); user.SelectInstance(instanceId, setAuthCookie, null); } else if (user.InstanceId != instanceId) { user.SelectInstance(instanceId, setAuthCookie, null); } } catch (AuthenticationException) { redirectUrl = LoginProvider.Current.GetLoginUrl(null, null, Guid.Empty, Guid.Empty, null, CustomUrlProvider.CreateApplicationUri(host, null)); } } } if (string.IsNullOrEmpty(redirectUrl)) { if (string.Compare(host, customUrlSettings.PartialCustomUrlRootAddressesFirst, StringComparison.OrdinalIgnoreCase) == 0) { http.Session.Abandon(); // Important fix of the issue with the same SessionID for all the child domains. } redirectUrl = CustomUrlProvider.CreateApplicationUri(vanityUrl, http.Request.Url.PathAndQuery); } } } else { if (user == null) { user = UserContext.Current; } if (user != null) { CustomUrlProvider.ParseHost(host, ref organizationId, ref instanceId); if (user.OrganizationId != Guid.Empty) { if (user.OrganizationId != organizationId) { redirectUrl = LoginProvider.Current.GetLoginUrl(null, null, organizationId, instanceId, null); } else { if (instanceId == Guid.Empty) { if (user.InstanceId != Guid.Empty) { try { user.SelectOrganization(organizationId, true, null, null); } catch (AuthenticationException) { redirectUrl = LoginProvider.Current.GetLoginUrl(null, null, organizationId, Guid.Empty, null); } } } else if (user.InstanceId != instanceId) { redirectUrl = LoginProvider.Current.GetLoginUrl(null, null, organizationId, instanceId, null); } } } else if (organizationId != Guid.Empty) { redirectUrl = LoginProvider.Current.GetLoginUrl(Guid.Empty, organizationId); } } } if (!string.IsNullOrEmpty(redirectUrl)) { if ((redirectUrl.IndexOf(http.Request.Url.ToString(), StringComparison.OrdinalIgnoreCase) == -1) && (http.Request.Url.ToString().IndexOf(redirectUrl, StringComparison.OrdinalIgnoreCase) == -1)) { http.Response.Redirect(redirectUrl); } } }