Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the Principal class.
        /// </summary>
        /// <param name="userSecurityContext">The user security context.</param>
        public Principal(UserSecurityContext userSecurityContext)
        {
            if (userSecurityContext == null)
            {
                throw new ArgumentNullException("userSecurityContext");
            }

            this.identity = userSecurityContext.User;
            this.userRightAssignments = (UserRightAssignment[])userSecurityContext.RightAssignments.ToArray().Clone();
        }
        public void Login(string username, string password, string redirectUrl, int loginAttempts)
        {
            if(new AuthenticationSvc().IsValidUser(username, password))
            {
                ApplicationSecurityContext applicationSecurityContext = this.HttpContext.Application["securityContext"] as ApplicationSecurityContext;
                log.Debug(username);
                UserSecurityContext userSecurityContext = new UserSecurityContext(username, applicationSecurityContext);
                this.Context.Session["userSecurityContext"] = userSecurityContext;
                this.Context.Session["userSecurityPrincipal"] = new Principal(userSecurityContext);

                if(string.IsNullOrEmpty(redirectUrl))
                    redirectUrl = "/";

                this.RedirectToUrl(redirectUrl);
            }

            PropertyBag["loginAttempts"] = loginAttempts + 1;
        }