public void TestUserToDto()
        {
            User user = new User()
            {
                UserId = 1, UserName = "******", Password = "******", Version = 0
            };
            Role role = new Role()
            {
                RoleId = 1, RoleName = "FakeRoleName", Version = 0
            };

            user.Roles = new List <Role>()
            {
                role
            }.AsQueryable();
            Assert.AreEqual(true, user.IsValid);
            Assert.AreEqual(true, role.IsValid);

            UserDTO dto = SecurityAdapter.UserToDTO(user);

            Assert.AreEqual <int>(user.UserId, dto.Id);
            Assert.AreEqual <string>(user.UserName, dto.UserName);
            Assert.AreEqual <string>(user.Password, dto.Password);
            Assert.AreEqual(user.Version, dto.Version);
            Assert.AreEqual <int>(1, dto.Roles.Count());

            RoleDTO dtoRole = dto.Roles.First();

            Assert.AreEqual <int>(role.RoleId, dtoRole.Id);
            Assert.AreEqual <String>(role.RoleName, dtoRole.RoleName);
            Assert.AreEqual(role.Version, dtoRole.Version);
            Assert.AreEqual(true, dto.IsValid);
            Assert.AreEqual(true, dtoRole.IsValid);
        }
Пример #2
0
        public IQueryable <HsrOrderApp.BL.DomainModel.User> GetAllUsers()
        {
            var users = from u in this.db.UserSet.Include("Roles").AsEnumerable()
                        select SecurityAdapter.AdaptUser(u);

            return(users.AsQueryable());
        }
Пример #3
0
        public IQueryable <HsrOrderApp.BL.DomainModel.Role> GetAllRoles()
        {
            var roles = from r in this.db.RoleSet.Include("Users").AsEnumerable()
                        select SecurityAdapter.AdaptRole(r);

            return(roles.AsQueryable());
        }
        public IQueryable <HsrOrderApp.BL.DomainModel.User> GetAllUsers()
        {
            var users = from u in this.db.Users
                        select SecurityAdapter.AdaptUser(u);

            return(users);
        }
        public IQueryable <HsrOrderApp.BL.DomainModel.Role> GetAllRoles()
        {
            var roles = from r in this.db.Roles
                        select SecurityAdapter.AdaptRole(r);

            return(roles);
        }
Пример #6
0
        public GetRolesResponse GetRolesByCriteria(GetRolesRequest request)
        {
            GetRolesResponse          response = new GetRolesResponse();
            SecurityBusinessComponent bc       = DependencyInjectionHelper.GetSecurityBusinessComponent();

            IQueryable <Role> roles = bc.GetRolesByCriteria(request.SearchType, request.Rolename);

            response.Roles = SecurityAdapter.RolesToDTOs(roles);

            return(response);
        }
Пример #7
0
        public GetUserResponse GetUserById(GetUserRequest request)
        {
            GetUserResponse           response = new GetUserResponse();
            SecurityBusinessComponent bc       = DependencyInjectionHelper.GetSecurityBusinessComponent();

            User user = bc.GetUserById(request.Id);

            response.User = SecurityAdapter.UserToDTO(user);

            return(response);
        }
Пример #8
0
        public GetRoleResponse GetRoleById(GetRoleRequest request)
        {
            GetRoleResponse           response = new GetRoleResponse();
            SecurityBusinessComponent bc       = DependencyInjectionHelper.GetSecurityBusinessComponent();

            Role role = bc.GetRoleById(request.RoleId);

            response.Role = SecurityAdapter.RoleToDTO(role);

            return(response);
        }
Пример #9
0
        public GetUsersResponse GetUsersByCriteria(GetUsersRequest request)
        {
            GetUsersResponse          response = new GetUsersResponse();
            SecurityBusinessComponent bc       = DependencyInjectionHelper.GetSecurityBusinessComponent();

            IQueryable <User> users = bc.GetUsersByCriteria(request.SearchType, request.Username, request.Rolename);

            response.Users = SecurityAdapter.UsersToDtos(users);

            return(response);
        }
Пример #10
0
        public GetCurrentUserResponse GetCurrentUser(GetCurrentUserRequest request)
        {
            GetCurrentUserResponse    response = new GetCurrentUserResponse();
            SecurityBusinessComponent bc       = DependencyInjectionHelper.GetSecurityBusinessComponent();

            User user = bc.GetUserByName(Thread.CurrentPrincipal.Identity.Name);

            response.User = SecurityAdapter.UserToCurrentUserDTO(user);

            return(response);
        }
Пример #11
0
        public StoreUserResponse StoreUser(StoreUserRequest request)
        {
            StoreUserResponse         response = new StoreUserResponse();
            SecurityBusinessComponent bc       = DependencyInjectionHelper.GetSecurityBusinessComponent();

            User user = SecurityAdapter.DtoToUser(request.User);
            IEnumerable <ChangeItem> changeItems = SecurityAdapter.GetChangeItems(request.User);

            response.Id = bc.StoreUser(user, changeItems);

            return(response);
        }
        public void TestGetChangeItems()
        {
            UserDTO userDTO = new UserDTO();

            userDTO.MarkChildForInsertion(new RoleDTO {
                Id = 1, RoleName = "FakeRoleName", Version = 0
            });
            userDTO.MarkChildForUpdate(new RoleDTO {
                Id = 2, RoleName = "FakeRoleName", Version = 0
            });
            userDTO.MarkChildForDeletion(new RoleDTO {
                Id = 3, RoleName = "FakeRoleName", Version = 0
            });

            IEnumerable <ChangeItem> changeItems = SecurityAdapter.GetChangeItems(userDTO);

            Assert.AreEqual <int>(3, changeItems.Count());
        }
Пример #13
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            SecurityAdapter.Initialize();

            var catalog = new AggregateCatalog();

            catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(EIMSDataContext).Assembly));
            var container = new CompositionContainer(catalog);

            DependencyResolver.SetResolver(new MefDependencyResolver(container));                           // view controllers
            GlobalConfiguration.Configuration.DependencyResolver = new MefAPIDependencyResolver(container); // web api controllers
        }
        public HsrOrderApp.BL.DomainModel.User GetUserByUsername(string username)
        {
            try
            {
                var users = from u in this.db.Users
                            where u.Username == username
                            select SecurityAdapter.AdaptUser(u);

                return(users.First());
            }
            catch (ArgumentNullException ex)
            {
                if (ExceptionPolicy.HandleException(ex, "DA Policy"))
                {
                    throw;
                }
                return(new MissingUser());
            }
        }
Пример #15
0
        public HsrOrderApp.BL.DomainModel.User GetUserById(int id)
        {
            try
            {
                var users = from u in this.db.UserSet.Include("Roles").Include("Customer").AsEnumerable()
                            where u.UserId == id
                            select SecurityAdapter.AdaptUser(u);

                return(users.First());
            }
            catch (ArgumentNullException ex)
            {
                if (ExceptionPolicy.HandleException(ex, "DA Policy"))
                {
                    throw;
                }
                return(new MissingUser());
            }
        }
        public HsrOrderApp.BL.DomainModel.Role GetRoleById(int roleId)
        {
            try
            {
                var roles = from r in this.db.Roles
                            where r.RoleId == roleId
                            select SecurityAdapter.AdaptRole(r);

                return(roles.First());
            }
            catch (ArgumentNullException ex)
            {
                if (ExceptionPolicy.HandleException(ex, "DA Policy"))
                {
                    throw;
                }
                return(new MissingRole());
            }
        }
Пример #17
0
        public HsrOrderApp.BL.DomainModel.Role GetRoleById(int id)
        {
            try
            {
                var roles = from u in this.db.RoleSet.Include("Users").AsEnumerable()
                            where u.RoleId == id
                            select SecurityAdapter.AdaptRole(u);

                return(roles.First());
            }
            catch (ArgumentNullException ex)
            {
                if (ExceptionPolicy.HandleException(ex, "DA Policy"))
                {
                    throw;
                }
                return(new MissingRole());
            }
        }
Пример #18
0
        public HsrOrderApp.BL.DomainModel.User GetUserByUsername(string username)
        {
            try
            {
                var users = from u in this.db.UserSet.Include("Roles").AsEnumerable()
                            where String.Equals(u.Username, username, StringComparison.OrdinalIgnoreCase)
                            select SecurityAdapter.AdaptUser(u);



                return(users.First());
            }
            catch (ArgumentNullException ex)
            {
                if (ExceptionPolicy.HandleException(ex, "DA Policy"))
                {
                    throw;
                }
                return(new MissingUser());
            }
        }
        public void TestDtoToUser()
        {
            RoleDTO roleDTO = new RoleDTO()
            {
                Id = 1, RoleName = "FakeName", Version = 0
            };
            UserDTO dto = new UserDTO()
            {
                Id = 1, UserName = "******", Password = "******", Version = 1
            };

            dto.Roles.Add(roleDTO);
            Assert.AreEqual(true, dto.IsValid);
            Assert.AreEqual(true, roleDTO.IsValid);

            User user = SecurityAdapter.DtoToUser(dto);

            Assert.AreEqual <int>(dto.Id, user.UserId);
            Assert.AreEqual <string>(dto.UserName, user.UserName);
            Assert.AreEqual <string>(dto.Password, user.Password);
            Assert.AreEqual(dto.Version, user.Version);
            Assert.AreEqual(true, user.IsValid);
        }
        public void TestUsersToDtos()
        {
            User user = new User()
            {
                UserId = 1, UserName = "******", Password = "******", Version = 0
            };

            Assert.AreEqual(true, user.IsValid);

            IQueryable <User> users = new List <User>()
            {
                user
            }.AsQueryable();
            IList <UserListDTO> userDtos = SecurityAdapter.UsersToDtos(users);

            Assert.AreEqual <int>(1, userDtos.Count());

            UserListDTO dto = userDtos.First();

            Assert.AreEqual <int>(user.UserId, dto.Id);
            Assert.AreEqual <string>(user.UserName, dto.UserName);
            //Assert.AreEqual<string>(user.Customer.ToString(), dto.CustomerName);
            Assert.AreEqual(true, dto.IsValid);
        }
        public ActionResult Login(string username, string password)
        {
            var v = "NA";

            try
            {
                var securityMode = ConfigurationManager.AppSettings["SecurityMode"].ToString().ToUpper();

                if (securityMode == ("UP"))
                {
                    if (userValidation(username, password))
                    {
                        appLog.InfoFormat("uservalidation for user: {0} is passed", username);
                        //if (userReportAppValidation(username))
                        if (Convert.ToBoolean(System.Web.HttpContext.Current.Session["session_isreportuser"]) == true)
                        {
                            appLog.InfoFormat("the user: {0} is a report user", username);
                            if (userMISValidation(username))
                            {
                                appLog.InfoFormat("userMISValidation(username) method is passed");

                                SessionVariablesMethod(username);

                                appLog.InfoFormat("SessionVariablesMethod(username) method is passed");

                                var urlBuilder = new UrlHelper(Request.RequestContext);
                                var url        = urlBuilder.Action("Index", "Home");
                                //return Json(new { status = "success", redirectUrl = url, JsonRequestBehavior.AllowGet });
                                appLog.InfoFormat("{0}{1}{2}", "user: "******" successfully logged on");

                                return(Json(new { v = "success", redirectUrl = url, JsonRequestBehavior.AllowGet }));
                            }
                            else //if (!userMISValidation(username))
                            {
                                appLog.InfoFormat("{0}{1}{2}", "user: "******" is not mapped to UserMIS on Pi360 app");

                                return(Json(new { v = "notusermis", JsonRequestBehavior.AllowGet }));
                            }
                        }
                        else //if (!userReportAppValidation(username))
                        {
                            appLog.InfoFormat("{0}{1}{2}", "user: "******" is not a report user.");

                            return(Json(new { v = "notreportuser", JsonRequestBehavior.AllowGet }));
                        }
                    }

                    else //if (!userValidation(username, password))
                    {
                        SecurityAdapter securityobj = new SecurityAdapter();
                        if (!securityobj.userSetUpValidation(username))
                        {
                            appLog.InfoFormat("{0}{1}{2}", "user: "******" is not set up on Pi360 app.");

                            return(Json(new { v = "notOnPi360", JsonRequestBehavior.AllowGet }));
                        }
                        else
                        {
                            appLog.InfoFormat("{0}{1}{2}", "user: "******" failed logged in");
                            //return Json(app, JsonRequestBehavior.AllowGet);
                            return(Json(new { v = "fail", JsonRequestBehavior.AllowGet }));
                        }
                    }
                } // end of 1st if

                //------------ for Active Directory Authentication ----------------------------
                else
                {
                    if (_SecurityAdapter.Login(username, password))
                    {
                        appLog.InfoFormat("_SecurityAdapter.Login(username, password) method is passed for user: {0}", username);
                        //if (userReportAppValidation(username))
                        if (Convert.ToBoolean(System.Web.HttpContext.Current.Session["session_isreportuser"]) == true)
                        {
                            appLog.InfoFormat("the user: {0} is a report user", username);
                            if (userMISValidation(username))
                            {
                                appLog.InfoFormat("userMISValidation(username) method is passed");

                                SessionVariablesMethod(username);

                                appLog.InfoFormat("SessionVariablesMethod(username) method is passed");

                                var urlBuilder = new UrlHelper(Request.RequestContext);
                                var url        = urlBuilder.Action("Index", "Home");

                                //return Json(new { status = "success", redirectUrl = url, JsonRequestBehavior.AllowGet });
                                appLog.InfoFormat("{0}{1}{2}", "user: "******" successfully logged on");

                                return(Json(new { v = "success", redirectUrl = url, JsonRequestBehavior.AllowGet }));
                                //return RedirectToAction("Index", "Home");
                            }
                            else //if (!userMISValidation(username))
                            {
                                appLog.InfoFormat("{0}{1}{2}", "user: "******" is not mapped to UserMIS on Pi360 app");

                                return(Json(new { v = "notusermis", JsonRequestBehavior.AllowGet }));
                            }
                        }
                        else //if (!userReportAppValidation(username))
                        {
                            appLog.InfoFormat("{0}{1}{2}", "user: "******" is not a report user.");

                            return(Json(new { v = "notreportuser", JsonRequestBehavior.AllowGet }));
                        }
                    }
                    else //if (!_SecurityAdapter.Login(username, password))
                    {
                        //SecurityAdapter securityobj = new SecurityAdapter();
                        if (!securityobj.userSetUpValidation(username))
                        {
                            appLog.InfoFormat("{0}{1}{2}", "user: "******" is not set up on Pi360 app.");

                            return(Json(new { v = "notOnPi360", JsonRequestBehavior.AllowGet }));
                        }
                        else
                        {
                            appLog.InfoFormat("{0}{1}{2}", "user: "******" failed logged in");
                            //return Json(app, JsonRequestBehavior.AllowGet);
                            return(Json(new { v = "fail", JsonRequestBehavior.AllowGet }));
                        }
                    }
                } //end of else
            }     //end of try


            catch (Exception ex)
            {
                //Service1.job1Log.Info(string.Format("{0}{1}{2}", rowAffected, " ", "rows affected."));
                appLog.InfoFormat("{0}{1}", "Message exception: ", ex.Message);
                appLog.InfoFormat("{0}{1}", "InnerException exception: ", ex.InnerException.Message);
                //appLog.InfoFormat("{0}{1}", "Stack Trace: ", ex.StackTrace);
            }

            //finally
            //{
            //    Dispose(true);
            //}

            return(View());
        }
        public static SecurityConfiguration build(SecurityAdapter identifierProvider, ConfigurationService configurationService)
        {
            JsonObject bundleData = configurationService.getBundle(SimpleSecurityAdapter.BUNDLE_NAME);

            SecurityConfiguration answer = null;

            if (null != bundleData)
            {
                if (bundleData.Contains("identifier"))
                {
                    answer = new SecurityConfiguration(bundleData, configurationService);
                    return answer;
                }
            }

            String identifer = identifierProvider.getIdentifier();
            log.debug(identifer, "identifer");

            answer = new SecurityConfiguration(identifer, configurationService);
            answer.save(); // ensure we persist the newly created 'identifer'

            return answer;
        }