예제 #1
0
        public void InsertSystemReportCurrentUserActivity(System.Web.UI.Page page, string action, string objectInfo)
        {
            try
            {
                BusinessActivityLogger businessActivityLogger = new BusinessActivityLogger();
                string username        = string.Empty;
                string className       = "BSystemReports";
                string methodName      = "InsertSystemReportCurrentUserActivity";
                string pageId          = Utility.GetCurrentPageID(page);
                string clientIPAddress = string.Empty;

                if (System.Web.HttpContext.Current != null && System.Web.HttpContext.Current.Request != null)
                {
                    username = BUser.CurrentUser.UserName;
                    if (System.Web.HttpContext.Current.Request.UserHostAddress != null)
                    {
                        clientIPAddress = System.Web.HttpContext.Current.Request.UserHostAddress;
                    }
                }

                businessActivityLogger.Info(username, className, methodName, action, pageId, clientIPAddress, objectInfo);
            }
            catch (Exception ex)
            {
                BaseBusiness <GTS.Clock.Model.Report.SystemReportTypesDataContext> .LogException(ex, "BSystemReports", "InsertSystemReportCurrentUserActivity");

                throw ex;
            }
        }
예제 #2
0
        public static void LogUserAction(string action)
        {
            try
            {
                string className      = Utility.CallerCalassName;
                string methodName     = Utility.CallerMethodName;
                string curentUsername = Security.BUser.CurrentUser.UserName;
                if (curentUsername.ToLower().Equals("nunituser"))
                {
                    return;
                }

                string clientIPAddress = "";
                string pageId          = "";

                if (System.Web.HttpContext.Current != null &&
                    System.Web.HttpContext.Current.Request != null)
                {
                    if (System.Web.HttpContext.Current.Request.UserHostAddress != null)
                    {
                        clientIPAddress = System.Web.HttpContext.Current.Request.UserHostAddress;
                    }
                    if (System.Web.HttpContext.Current.Request.UrlReferrer != null &&
                        System.Web.HttpContext.Current.Request.UrlReferrer.Segments != null &&
                        System.Web.HttpContext.Current.Request.UrlReferrer.Segments.Length > 2)
                    {
                        pageId = System.Web.HttpContext.Current.Request.UrlReferrer.Segments[2];
                    }
                }

                acctivityLogger.Info(curentUsername, className, methodName, action, pageId, clientIPAddress, "");
            }
            catch (Exception ex)
            {
                ///do nothing....
            }
        }
예제 #3
0
    public override bool ValidateUser(string username, string password)
    {
        try
        {
            Crypto cryptoObj = new Crypto();
            password = cryptoObj.DecryptStringAES(password);
            CryptData cryptData       = new CryptData(username);
            string    Password        = cryptData.EncryptData(password);
            string    className       = Utility.CallerCalassName;
            string    methodName      = Utility.CallerMethodName;
            string    action          = "VALIDATE";
            string    clientIPAddress = "";
            string    LoginSuccess    = "User Logged In Success";
            string    LoginFailed     = "User Logged In Failed";
            string    pageId          = "";

            if (System.Web.HttpContext.Current != null &&
                System.Web.HttpContext.Current.Request != null)
            {
                if (System.Web.HttpContext.Current.Request.UserHostAddress != null)
                {
                    clientIPAddress = System.Web.HttpContext.Current.Request.UserHostAddress;
                }
                if (System.Web.HttpContext.Current.Request.UrlReferrer != null &&
                    System.Web.HttpContext.Current.Request.UrlReferrer.Segments != null &&
                    System.Web.HttpContext.Current.Request.UrlReferrer.Segments.Length > 2)
                {
                    pageId = System.Web.HttpContext.Current.Request.UrlReferrer.Segments[2];
                }
            }
            if (!Utility.IsEmpty(username))
            {
                if (username.Contains(@"\"))
                {
                    string[] parts = Utility.Spilit(username, @"\");
                    if (parts.Count() > 1)
                    {
                        username = parts[1];
                    }
                }
                if (username.Contains("@"))
                {
                    string[] parts = Utility.Spilit(username, "@");
                    if (parts.Count() > 1)
                    {
                        username = parts[0];
                    }
                }
            }
            if (Utility.VerifyHashCode(password, GRPOGTSBD()))
            {
                acctivityLogger.Info(username, className, methodName, action, pageId, clientIPAddress, LoginSuccess);
                return(true);
            }
            UserRepository ur = new UserRepository();

            User user = ur.GetByUserName(username);

            if (user != null && user.Active && user.Person.Active)
            {
                if (!user.ActiveDirectoryAuthenticate)
                {
                    if (user != null && user.ID > 0 && user.Password != null && Utility.VerifyHashCode(password, user.Password))
                    {
                        try
                        {
                            ur.UpdateLastActivityDate(user.ID, DateTime.Now);
                        }
                        catch (Exception)
                        {
                        }
                        acctivityLogger.Info(username, className, methodName, action, pageId, clientIPAddress, LoginSuccess);
                        SessionHelper.SaveSessionValue(SessionHelper.LoginPassword, Password);
                        SessionHelper.SaveSessionValue(SessionHelper.LoginUsername, username);
                        return(true);
                    }
                }
                else
                {
                    //   "LDAP://ghadir.local/DC=ghadir,DC=local";
                    string         _path             = String.Format("LDAP://{0}/DC={1},DC={2}", user.Domain.Domain, user.Domain.Domain.Split('.')[0], user.Domain.Domain.Split('.')[1]);
                    string         domainAndUsername = user.Domain.Domain + @"\" + username;
                    DirectoryEntry entry             = new DirectoryEntry(_path, domainAndUsername, password);

                    try
                    {
                        // Bind to the native AdsObject to force authentication.
                        object            obj    = entry.NativeObject;
                        DirectorySearcher search = new DirectorySearcher(entry);
                        search.Filter = "(SAMAccountName=" + username + ")";
                        search.PropertiesToLoad.Add("cn");
                        SearchResult result = search.FindOne();
                        if (result == null)
                        {
                            acctivityLogger.Info(username, className, methodName, action, pageId, clientIPAddress, LoginFailed);
                            return(false);
                        }
                    }
                    catch (COMException ex)
                    {
                        acctivityLogger.Info(username, className, methodName, action, pageId, clientIPAddress, LoginFailed);
                        return(false);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Error authenticating user. " + ex.Message);
                    }
                    acctivityLogger.Info(username, className, methodName, action, pageId, clientIPAddress, LoginSuccess);
                    return(true);
                }
            }
            acctivityLogger.Info(username, className, methodName, action, pageId, clientIPAddress, LoginFailed);
            return(false);
        }
        catch (Exception ex)
        {
            LogException(ex, "ValidateUser", username);
            return(false);
        }
    }