Example #1
0
        protected void EventsAfterIdentify(UserAfterIdentifyEventArgs e)
        {
            if (_configuration.HasValue)
            {
                if (PublicApi.Users.AccessingUser.Id == PublicApi.Users.Get(new UsersGetOptions()
                {
                    Username = "******"
                }).Id)
                {
                    //if (HttpContext.Current.Request.Url.LocalPath != "/splash")
                    string urlRequest = HttpContext.Current.Request.Url.LocalPath;

                    var pageContext = PublicApi.Url.ParsePageContext(HttpContext.Current.Request.Url.OriginalString);

                    if (pageContext != null && pageContext.PageName != _pageName && !CentralizedFileStorage.IsCentralizedFileUrl(urlRequest) && !(urlRequest.EndsWith(".js") || urlRequest.EndsWith(".axd") || urlRequest.EndsWith(".ashx") || urlRequest.IndexOf("socket.ashx") >= 0 || urlRequest.StartsWith("/resized-image/__size/")))
                    {
                        HttpCookie cookie = HttpContext.Current.Request.Cookies["Splash"];

                        if (cookie == null || cookie["hash"] != GetPasswordHash())
                        {
                            HttpContext.Current.Response.Redirect("/splash" + "?ReturnUrl=" + PublicApi.CoreUrls.Home(false), true);
                        }
                    }
                }
            }
        }
        protected void EventsAfterIdentify(UserAfterIdentifyEventArgs e)
        {
            if (_configuration.HasValue)
            {
                if (PublicApi.Users.AccessingUser.Id == PublicApi.Users.Get(new UsersGetOptions() {Username = "******"}).Id)
                {
                    //if (HttpContext.Current.Request.Url.LocalPath != "/splash")
                    string urlRequest = HttpContext.Current.Request.Url.LocalPath;

                    var pageContext = PublicApi.Url.ParsePageContext(HttpContext.Current.Request.Url.OriginalString);

                    if (pageContext != null && pageContext.PageName != _pageName && !CentralizedFileStorage.IsCentralizedFileUrl(urlRequest) && !(urlRequest.EndsWith(".js") || urlRequest.EndsWith(".axd") || urlRequest.EndsWith(".ashx") || urlRequest.IndexOf("socket.ashx") >= 0 || urlRequest.StartsWith("/resized-image/__size/")))
                    {
                        HttpCookie cookie = HttpContext.Current.Request.Cookies["Splash"];

                        if (cookie == null || cookie["hash"] != GetPasswordHash())
                        {
                            HttpContext.Current.Response.Redirect("/splash" + "?ReturnUrl=" + PublicApi.CoreUrls.Home(false), true);
                        }
                    }
                }
            }
        }
 void Events_AfterIdentify(UserAfterIdentifyEventArgs e)
 {
     UpdateLoginDate(e.ContentId);
 }
Example #4
0
        void Events_AfterIdentify(UserAfterIdentifyEventArgs e)
        {
            var context = HttpContext.Current;

            if (context == null)
            {
                return;
            }
            if (context.Request == null)
            {
                return;
            }
            if (!context.Request.IsAuthenticated)
            {
                return;
            }

            //filter some requests basic non UI requests
            if (context.Request.RawUrl.ToLower().StartsWith("/socket.ashx"))
            {
                return;
            }
            if (context.Request.RawUrl.ToLower().StartsWith("/webresource.axd"))
            {
                return;
            }
            if (context.Request.RawUrl.ToLower().StartsWith("/api.ashx"))
            {
                return;
            }
            if (context.Request.RawUrl.ToLower().StartsWith("/utility/"))
            {
                return;
            }
            if (context.Request.RawUrl.ToLower().StartsWith("/cfs-filesystemfile/"))
            {
                return;
            }
            if (context.Request.RawUrl.ToLower().StartsWith("/dynamic-style"))
            {
                return;
            }
            if (context.Request.RawUrl.ToLower().StartsWith("/favicon.ico"))
            {
                return;
            }
            if (context.Request.RawUrl.ToLower().EndsWith(".css"))
            {
                return;
            }

            //check to see if our Oauth ProcessLogin() cookie exists
            try
            {
                var afterAuthenticatedCookie = CookieHelper.GetCookie(clientType);
                if (afterAuthenticatedCookie == null)
                {
                    return;
                }

                var samlTokenData = SamlTokenData.GetTokenDataFromDatabase(afterAuthenticatedCookie.Value);
                if (samlTokenData == null)
                {
                    return;
                }

                if (!samlTokenData.IsExistingUser())
                {
                    return;
                }

                if (samlTokenData.UserId != e.Id.Value)
                {
                    return;                                      //check to see that the logged in user and ProcessLogin() user have the same ID;
                }
                if (Guid.TryParse(afterAuthenticatedCookie.Value, out var tokenKey))
                {
                    SamlTokenData.DeleteTokenDataFromDatabase(afterAuthenticatedCookie.Value);
                }

                CookieHelper.DeleteCookie(afterAuthenticatedCookie.Value);
                CookieHelper.DeleteCookie(afterAuthenticatedCookie.Name);

                //Get the API user and the last SAML token to keep things API friendly
                var apiUser = _usersApi.Get(new UsersGetOptions()
                {
                    Id = e.Id.Value
                });

                SamlEvents.Instance.OnAfterAuthenticate(apiUser, samlTokenData);
            }
            catch (Exception ex)
            {
                _eventLogApi.Write("SamlOAuthClient Error OnAfterAuthenticate: " + ex.Message + " : " + ex.StackTrace, new EventLogEntryWriteOptions()
                {
                    Category = "SAML", EventId = 1, EventType = "Error"
                });
            }
        }
 void Events_AfterIdentify(UserAfterIdentifyEventArgs e)
 {
     UpdateLoginDate(e.ContentId);
 }