Inheritance: IFormsAuthenticationService
Ejemplo n.º 1
0
        protected override void Initialize(RequestContext requestContext)
        {
            if (FormsService == null) { FormsService = new FormsAuthenticationService(); }
            if (MembershipService == null) { MembershipService = new AccountMembershipService(); }

            base.Initialize(requestContext);
        }
Ejemplo n.º 2
0
        public EmailChanger(AccountConfiguration config, IAccountContext context, AccountRepository repo, PasswordService passwordService, FormsAuthenticationService formsAuthService)
        {
            if (config == null) throw new ArgumentNullException("config");
             if (context == null) throw new ArgumentNullException("context");

             this.config = config;
             this.context = context;
             this.repo = new AccountRepositoryWrapper(config.RequireDependency(repo));
             this.passServ = config.RequireDependency(passwordService);
             this.formsAuthService = config.RequireDependency(formsAuthService);
        }
Ejemplo n.º 3
0
        protected override void Initialize(RequestContext requestContext)
        {
            if (AuthenticationService == null)
            {
                AuthenticationService = new FormsAuthenticationService();
            }
            if (AccountService == null)
            {
                AccountService = new AccountService();
            }

            base.Initialize(requestContext);
        }
Ejemplo n.º 4
0
        protected override void Initialize(RequestContext requestContext)
        {
            if (FormsService == null)
            {
                FormsService = new FormsAuthenticationService();
            }
            if (OpenId == null)
            {
                OpenId = new OpenIdRelyingParty();
            }

            base.Initialize(requestContext);
        }
Ejemplo n.º 5
0
        protected override void Initialize(RequestContext requestContext)
        {
            if (FormsService == null)
            {
                FormsService = new FormsAuthenticationService();
            }
            if (MembershipService == null)
            {
                MembershipService = new AccountMembershipService();
            }

            base.Initialize(requestContext);
        }
Ejemplo n.º 6
0
        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            //repository = new UserRepository();
            if (FormsService == null)
            {
                FormsService = new FormsAuthenticationService();
            }
            if (MembershipService == null)
            {
                MembershipService = new AccountMembershipService();
            }

            base.Initialize(requestContext);
        }
 public new virtual void SetUp()
 {
     base.SetUp();
     try
     {
         FormsAuthenticationService.GetLoggedInOrganisationId().Returns(OrganisationId);
         ApplicationServiceAgent.GetByOrganisation(OrganisationId).Returns(new List <Application>());
         ApplicationService.Update(ApplicationIdNotPartOfLoggedInOrganisation, NewName, true);
     }
     catch (ApplicationNotPartOfOrganisationException ex)
     {
         _exception = ex;
     }
 }
 public new virtual void SetUp()
 {
     base.SetUp();
     FormsAuthenticationService.GetLoggedInOrganisationId().Returns(InvalidOrganisationId);
     OrganisationsServiceAgent.Get(InvalidOrganisationId)
     .Returns(x => { throw new ItemNotFoundException(); });
     try
     {
         OrganisationService.Get();
     }
     catch (OrganisationIdNotValidException ex)
     {
         _exception = ex;
     }
 }
Ejemplo n.º 9
0
        protected override void Initialize(RequestContext requestContext)
        {
            if (FormsService == null)
            {
                FormsService = new FormsAuthenticationService();
            }
            if (MembershipService == null)
            {
                //MembershipService = new AccountMembershipService();
                FelBookDBEntities db = new FelBookDBEntities();
                MembershipService = new FelbookAccountMembershipService(db);
            }

            base.Initialize(requestContext);
        }
Ejemplo n.º 10
0
        public YnWebRight GetYnWebRight()
        {
            YnWebRight ynWebRight = new YnWebRight();
            //string mi = System.Web.HttpContext.Request["mi"];
            //System.Web.HttpContext.Current.Server.UrlEncode(ynWebAccMenuTree.ynWebModule.parameter);
            string mi = System.Web.HttpContext.Current.Request["mi"];

            YnFrame.Dal.Entities.YnUser ynUser = FormsAuthenticationService.GetInstance().GetTicketUserData();
            //ynUser = YnFrame.Services.YnUserService.GetInstance().Get(ynUser.userId);
            if (ynUser != null && mi != null)
            {
                ynWebRight = GetYnWebRight(ynUser.userId, mi);
            }
            return(ynWebRight);
        }
Ejemplo n.º 11
0
        protected override void Initialize(RequestContext requestContext)
        {
            if (FormsService == null)
            {
                FormsService = new FormsAuthenticationService();
            }
            if (MembershipService == null)
            {
                MembershipService = new AccountMembershipService();
            }

            context = BataBaseContext.DataBase;
            Set     = context.Publisher;

            base.Initialize(requestContext);
        }
Ejemplo n.º 12
0
        private static IAuthenticationService AuthenticationService()
        {
            string applicationName = "sops";

            IPersistenceConfigurer persistenceConfigurer =
                MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("DefaultConnection"));

            IAuthenticationService service = new FormsAuthenticationService(applicationName, new BCryptStrategy(), new ConsoleLogger(), persistenceConfigurer, c =>
            {
                var u = new SchemaUpdate(c);
                u.Execute(true, true);
            });

            service.Configure();

            return(service);
        }
Ejemplo n.º 13
0
        public void SessionStorageIsSetFromForms()
        {
            securityWebService.AddExistingSession("User");
            string    session = securityWebService.Sessions[0].SessionId;
            string    message;
            AmplaUser user = amplaUserService.SessionLogin(session, out message);

            Assert.That(user, Is.Not.Null);
            FormsAuthenticationService.StoreUserTicket(user, false);

            context.Response.Redirect("http://localhost/Production");

            Assert.That(AmplaSessionStorage.GetAmplaSession(), Is.Empty);
            new AlignSessionWithFormsAuthentication(context.Request, AmplaSessionStorage, FormsAuthenticationService).Execute();

            Assert.That(AmplaSessionStorage.GetAmplaSession(), Is.EqualTo(session));
        }
 public new virtual void SetUp()
 {
     base.SetUp();
     FormsAuthenticationService.GetLoggedInOrganisationId().Returns(OrganisationId);
     _applicationFromServiceAgentForGet = new Application {
         Id = ApplicationId
     };
     ApplicationServiceAgent.GetByOrganisation(OrganisationId)
     .Returns(new List <Application> {
         _applicationFromServiceAgentForGet
     });
     ApplicationServiceAgent.Get(ApplicationId).Returns(_applicationFromServiceAgentForGet);
     _applicationFromServiceAgentForGet.Name = NewName;
     ApplicationServiceAgent.Put(_applicationFromServiceAgentForGet)
     .Returns(_applicationFromServiceAgentForGet);
     _result = ApplicationService.Update(ApplicationId, NewName, Active);
 }
Ejemplo n.º 15
0
        /// <summary>
        /// 执行操作(调用方法特性后由框架调用)
        /// </summary>
        /// <param name="filterContext">过滤上下文</param>
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            //方法名称
            var actionName = filterContext.ActionDescriptor.ActionName;
            //控制器
            var controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;

            Dictionary <String, String> parmsObj = new Dictionary <String, String>();

            foreach (var item in parameterNameList.Split(',', '|'))
            {
                var valueProviderResult = filterContext.Controller.ValueProvider.GetValue(item);

                if (valueProviderResult != null && !parmsObj.ContainsKey(item))
                {
                    parmsObj.Add(item, valueProviderResult.AttemptedValue);
                }
            }

            var ticketUser = FormsAuthenticationService.GetAuthenticatedUser();

            try
            {
                String responseDataStr = JsonConvert.SerializeObject(filterContext.Result);
                if (responseDataStr == null)
                {
                    responseDataStr = String.Empty;
                }

                DataAccessBLL.Insert(new UserOperationLog
                {
                    UserID          = ticketUser?.UserID ?? 0,
                    UserAccount     = ticketUser == null ? "未知用户" : ticketUser.UserAccount,
                    OperationMothod = $"{controllerName}.{actionName}",
                    OperationName   = operationExplain,
                    OperationData   = JsonConvert.SerializeObject(parmsObj),
                    ReturnData      = responseDataStr,
                    Crdate          = DateTime.Now
                });
            }
            catch (Exception ex)
            {
                // 记录错误日志
            }
        }
Ejemplo n.º 16
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var action   = RouteData.Values["action"].ToString();
                var userName = RouteData.Values["userName"].ToString();

                if (SecurityContext.IsAuthenticated && (action == "signin" || action == "register"))
                {
                    Response.RedirectToRoute("Default", null);
                    return;
                }

                switch (action)
                {
                case "signin":
                    this.pageActionType.Value      = "signin";
                    this.signInButtons.Visible     = true;
                    this.username.Text             = userName;
                    this.rememberMeWrapper.Visible = true;
                    break;

                case "register":
                    this.pageActionType.Value    = "register";
                    this.registerButtons.Visible = true;
                    this.username.Attributes.Add("autocomplete", "off");
                    this.passwordReWrapper.Visible = true;
                    break;

                case "signout":
                    using (var formsAuthService = new FormsAuthenticationService(Context))
                    {
                        formsAuthService.SignOut();
                    }
                    Response.RedirectToRoute("Default", null);
                    break;

                default:
                    Response.RedirectToRoute("NotFound", null);
                    break;
                }

                DataBind();
            }
        }
 public new virtual void SetUp()
 {
     base.SetUp();
     try
     {
         FormsAuthenticationService.GetLoggedInOrganisationId().Returns(OrganisationId);
         ApplicationServiceAgent.GetByOrganisation(OrganisationId).Returns(new List <Application> {
             new Application {
                 Id = ApplicationIdNotPartOfOrganisation + "xxx"
             }
         });
         ApplicationService.GetById(ApplicationIdNotPartOfOrganisation);
     }
     catch (ApplicationNotPartOfOrganisationException ex)
     {
         _exception = ex;
     }
 }
Ejemplo n.º 18
0
        public void AccMenu()
        {
            List <YnWebAccMenu> listYnWebAccMenu = null;

            try
            {
                YnUser ynUser = FormsAuthenticationService.GetInstance().GetTicketUserData();
                //ynUser = YnFrame.Services.YnUserService.GetInstance().Get(ynUser.userId);
                if (ynUser != null)
                {
                    listYnWebAccMenu = YnPermission.GetInstance().GetYnWebAccMenuList(ynUser);
                }
            }
            catch (Exception ex)
            {
                //throw ex;
            }
        }
Ejemplo n.º 19
0
        protected void signInButton_Click(object sender, EventArgs e)
        {
            if (pageActionType.Value == "signin")
            {
                try
                {
                    var user = UserService.Get(x => x.UserName == this.username.Text);
                    if (user != null && HashPasswordService.ArePasswordsMatching(this.password.Text, user.Password))
                    {
                        using (var formsAuthService = new FormsAuthenticationService(Context))
                        {
                            string returnUrl;

                            formsAuthService.SignIn(user.UserName, rememberMe.Checked, user.Id.ToString(), out returnUrl);

                            if (!File.Exists(user.ProfileImage64Url) || !File.Exists(user.ProfileImage64Url) || !File.Exists(user.ProfileImage128Url))
                            {
                                UserService.SetProfilePicture(user, Image.FromFile(Server.MapPath("~/Content/images/default_profile.jpg")));
                                UserService.CommitChanges();
                            }

                            Response.Redirect(returnUrl);
                        }
                    }
                }
                catch (Exception exception)
                {
                    //handle exception
                    this.message.InnerText = GenericErrorMessage;
                    this.message.Visible   = true;
                }

                if (!SecurityContext.IsAuthenticated)
                {
                    this.message.InnerText = "Utilizatorul sau parola sunt gresite!";
                    this.message.Visible   = true;
                    this.password.Text     = string.Empty;
                }
            }
            else
            {
                Response.RedirectToRoute("Auth", new { action = "signin" });
            }
        }
Ejemplo n.º 20
0
        public void DisabledSessionStorageDoesntThrow()
        {
            context = context.WithSessionsDisabled();
            Assert.That(context.Session.Enabled, Is.False);

            securityWebService.AddExistingSession("User");
            string    session = securityWebService.Sessions[0].SessionId;
            string    message;
            AmplaUser user = amplaUserService.SessionLogin(session, out message);

            Assert.That(user, Is.Not.Null);
            FormsAuthenticationService.StoreUserTicket(user, false);

            context.Response.Redirect("http://localhost/Production");

            new AlignSessionWithFormsAuthentication(context.Request, AmplaSessionStorage, FormsAuthenticationService).Execute();

            Assert.That(AmplaSessionStorage.GetAmplaSession(), Is.Empty);
        }
Ejemplo n.º 21
0
        public ActionResult OpenIdConfirm(RegisterOpenId openId)
        {
            UsersModels user = new UsersModels();

            user.CreateNewUser(openId.ClaimedOpenId, openId.FriendlyOpenId, openId.Email);

            FormsAuthenticationService formAuth = new FormsAuthenticationService();

            formAuth.SignIn(openId.ClaimedOpenId, false);

            if (!string.IsNullOrEmpty(openId.ReturnUrl))
            {
                return(Redirect(openId.ReturnUrl));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Ejemplo n.º 22
0
        public ActionResult LogOn(LogonViewModel model)
        {
            if (ModelState.IsValid)
            {
                IValidationState validationState = memberService.ValidatePassword(model.MemberName, model.Password);

                if (!validationState.IsValid)
                {
                    ModelState.MergeError(validationState);
                }
                else
                {
                    FormsAuthenticationService.SignIn(model.MemberName, model.RememberMe);
                    return(RedirectToAction("Index", "Home"));
                }
            }

            return(View(model));
        }
Ejemplo n.º 23
0
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            base.OnAuthorization(filterContext);

            if (filterContext.RequestContext.HttpContext.Request.IsAuthenticated)
            {
                IFormsAuthenticationService FormsService = new FormsAuthenticationService();
                SessionHelper session = new SessionHelper(filterContext.HttpContext);

                if (session.SessionEndTime == null)
                {
                    session.SessionEndTime = DateTime.Now;
                }
                else if (DateTime.Now - session.SessionEndTime > TimeSpan.FromMinutes(1))
                {
                    FormsService.SignOut();
                    filterContext.Result = new RedirectToRouteResult(new System.Web.Routing.RouteValueDictionary(new { controller = "Account", action = "Logon" }));
                }
            }
        }
        /// <summary>


        //public static HttpControllerContext GetShimHttpControllerContext(string apiUri, string actionName, string controllerName)
        //{
        //    HttpConfiguration configuration = new HttpConfiguration();
        //    HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, "http://localhost/api/" + apiUri);
        //    IHttpRoute route = configuration.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}");
        //    HttpRouteData routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", controllerName }, { "action", actionName } });

        //    return new HttpControllerContext(configuration, routeData, requestMessage);
        //}

        /// <summary>
        /// Gets a shim account controller context, used for tests. Must be encapsulated in
        /// using (ShimsContext.Create())
        /// </summary>
        /// <param name="controller">
        /// Account controller to be shimmed.
        /// </param>
        /// <param name="actionName">
        /// The action Name.
        /// </param>
        /// <param name="useCookie">
        /// Set cookie if required.
        /// </param>
        protected void GetShimAccountControllerContext(AccountController controller, string actionName, bool useCookie = true)
        {
            HttpContext     shimHttpContext     = GetShimHttpContext(useCookie);
            HttpContextBase shimHttpContextBase = new HttpContextWrapper(shimHttpContext);
            ControllerBase  baseStub            = new DyntaxaBaseController();

            FormsAuthenticationService formsAuthenticationServiceMock = new FormsAuthenticationService();//new ShimFormsAuthenticationService() { };

            controller.FormsService = formsAuthenticationServiceMock;
            var requestContext = new RequestContext(shimHttpContextBase, new RouteData());

            controller.Url = new UrlHelper(requestContext);

            var routeData = new RouteData();

            routeData.Values["controller"] = "Account";
            routeData.Values["action"]     = actionName;

            controller.ControllerContext = new ControllerContext(shimHttpContextBase, routeData, baseStub);
        }
Ejemplo n.º 25
0
        public ActionResult Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                Guid             memberId;
                IValidationState memberValidationState = memberService.CreateMember(model.MemberName, model.Password, out memberId);
                userService.CreateUser(new Models.User()
                {
                    Id = memberId, UserName = model.MemberName
                });
                if (!memberValidationState.IsValid)
                {
                    ModelState.MergeError(memberValidationState);
                }
                else
                {
                    FormsAuthenticationService.SignIn(model.MemberName, false);
                    return(RedirectToAction("Index", "Home"));
                }
            }

            return(View(model));
        }
Ejemplo n.º 26
0
        public User UpdateUserAccount(UpdateUserInput updateUserInput, int userId)
        {
            var user = _userRepo.Find(userId);

            user.FirstName   = updateUserInput.FirstName;
            user.LastName    = updateUserInput.LastName;
            user.Email       = updateUserInput.Email;
            user.IATA        = updateUserInput.IATA;
            user.Affiliation = updateUserInput.Affiliation;
            var address = user.Address ?? new Address();

            address.FirstName = user.FirstName;
            address.LastName  = user.LastName;
            address.Phone     = updateUserInput.Phone;
            address.City      = updateUserInput.City;
            address.CountryId = 226;// TODO: hardcoded country for now
            user.Address      = address;

            _userRepo.Update(user);
            FormsAuthenticationService service = new FormsAuthenticationService(this);

            service.SetAuthenticated(user, false);
            return(user);
        }
Ejemplo n.º 27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="requestContext"></param>
        protected override void Initialize(RequestContext requestContext)
        {
            if (taskService == null)
            {
                taskService = new TaskService();
            }

            if (MembershipService == null)
            {
                MembershipService = new MembershipService();
            }

            if (AuthenticationService == null)
            {
                AuthenticationService = new FormsAuthenticationService();
            }

            if (db == null)
            {
                db = new PortalDBContext();
            }

            base.Initialize(requestContext);
        }
Ejemplo n.º 28
0
        protected override void Execute(System.Web.Routing.RequestContext requestContext)
        {
            Session = new SessionHelper(requestContext.HttpContext);

            if (!requestContext.HttpContext.Request.Url.AbsoluteUri.ToLower().Contains("service"))
            {
                if (requestContext.HttpContext.Request.IsAuthenticated)
                {
                    IFormsAuthenticationService FormsService = new FormsAuthenticationService();

                    if (DateTime.Now - Session.SessionEndTime > TimeSpan.FromMinutes(20))
                    {
                        FormsService.SignOut();
                        requestContext.HttpContext.Response.Redirect(requestContext.HttpContext.Request.Url.AbsoluteUri, true);
                    }
                    else
                    {
                        Session.SessionEndTime = DateTime.Now;
                    }
                }
            }

            base.Execute(requestContext);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Initializes data that might not be available when the constructor is called.
        /// </summary>
        /// <param name="requestContext">The HTTP context and route data.</param>
        protected override void Initialize(RequestContext requestContext)
        {
            base.Initialize(requestContext);

             this.repo = this.Configuration.RequireDependency(this.repo);
             this.passServ = this.Configuration.RequireDependency(this.passServ);
             this.formsAuthService = this.Configuration.RequireDependency(this.formsAuthService);
        }
Ejemplo n.º 30
0
 static FormsAuthenticationService()
 {
     _theService = new FormsAuthenticationService();
 }
        protected override void Initialize(RequestContext requestContext)
        {
            if (FormsService == null) { FormsService = new FormsAuthenticationService(); }
            if (MembershipService == null) { MembershipService = new AccountMembershipService(); }

            base.Initialize(requestContext);
            string str = "now making changes for bug branch iss53";
            str = "this is a master branch change for iss53 though ******************************************";
            str = "an additional change for bug iss53";
        }
Ejemplo n.º 32
0
 public ActionResult LogOff()
 {
     FormsAuthenticationService.SignOut();
     return(RedirectToAction("Index", "Home"));
 }
Ejemplo n.º 33
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AuthenticationController"/> class, 
 /// with the provided <paramref name="repo"/>, <paramref name="passwordService"/> and <paramref name="formsAuthService"/>.
 /// </summary>
 /// <param name="repo">The account repository.</param>
 /// <param name="passwordService">The password service.</param>
 /// <param name="formsAuthService">The forms authentication service.</param>
 public AuthenticationController(AccountRepository repo, PasswordService passwordService, FormsAuthenticationService formsAuthService)
     : this(repo, passwordService)
 {
     this.formsAuthService = formsAuthService;
 }
Ejemplo n.º 34
0
        /// <summary>
        /// 在过程请求授权时调用
        /// </summary>
        /// <param name="filterContext">过滤上下文</param>
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            base.OnAuthorization(filterContext);

            var user = FormsAuthenticationService.GetAuthenticatedUser();

            if (user == null)
            {
                return;
            }

            String action     = filterContext.ActionDescriptor.ActionName;
            String controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;

            // 需要获取管理员账号,思路为1.管理员账号和名字相同不允许修改2.初始化获取管理员账号然后来做对比
            if (user.UserAccount.ToLower() != "admin")
            {
                //所有菜单
                var menusDic = MenuProvider.GetMenuDic();
                //当前访问的菜单
                var menusList = new List <MenuItem>();

                //登录用户都可以访问该页面
                if (controller == "Login" && action == "Index")
                {
                    return;
                }

                // 根据控制器筛选
                foreach (var item in menusDic)
                {
                    if (item.Value.Controller == controller)
                    {
                        menusList.Add(item.Value);
                    }
                }

                // 为零就是没找到与控制器相匹配的菜单
                if (menusList.Count == 0)
                {
                    filterContext.Result = new ContentResult()
                    {
                        Content = "此账号没有该权限"
                    };

                    // 需要写入日志
                }
                else
                {
                    // 获取用户的菜单
                    var menuPerList = user.MenuId.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    // 判断用户的菜单是否包含访问的菜单 ,如果不包含则提示无权限
                    if (menusList.Where(p => !menuPerList.Contains(p.ID)).ToList().Count > 0)
                    {
                        filterContext.Result = new ContentResult()
                        {
                            Content = "此账号没有该权限."
                        };
                        // 需要写入日志

                        return;
                    }
                }
            }
        }
Ejemplo n.º 35
0
 public AccountController()
 {
     FormsService = new FormsAuthenticationService();
 }
Ejemplo n.º 36
0
        protected override void Initialize(RequestContext requestContext)
        {
            if (FormsService == null) { FormsService = new FormsAuthenticationService(); }
            if (OpenId == null) {  OpenId = new OpenIdRelyingParty(); }

            base.Initialize(requestContext);
        }