Esempio n. 1
0
        public TestsSecurityLayer()
        {
            Task Delegate(HttpContext httpContext) => Task.FromResult(0);

            _layer   = new SecurityLayer(Delegate);
            _context = new DefaultHttpContext();
        }
        protected override void Seed(ComplainDBContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.
            context.Logins.Add(new Login {
                Email = "*****@*****.**", Password = SecurityLayer.GetMd5Hash("test").ToUpper(), IsActive = true, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now
            });
        }
Esempio n. 3
0
 private string ReplaceSecurityLayerParameters(string xml, SecurityLayer securityLayer)
 {
     if (securityLayer.OldName != securityLayer.Name)
     {
         xml = xml.Replace("<Name>" + securityLayer.OldName + "</Name>", "<Name>" + securityLayer.Name + "</Name>");
     }
     if (securityLayer.OldLabel != securityLayer.Label)
     {
         xml = xml.Replace("<Label>" + securityLayer.OldLabel + "</Label>", "<Label>" + securityLayer.Label + "</Label>");
     }
     if (securityLayer.OldDescription != securityLayer.Description)
     {
         xml = xml.Replace("<Description>" + securityLayer.OldDescription + "</Description>", "<Description>" + securityLayer.Description + "</Description>");
     }
     return(xml);
 }
        public ActionResult Login(LoginViewModel loginViewModel, string returnUrl)
        {
            logger.Debug(string.Format("Login [Email={0}, Password={1}]", loginViewModel.Email, loginViewModel.Password));
            if (ModelState.IsValid)
            {
                try
                {
                    string password = SecurityLayer.GetMd5Hash(loginViewModel.Password).ToUpper();
                    var    user     = loginService.GetLogin(loginViewModel.Email, password);

                    logger.Debug(string.Format("Login RESPONSE [{0}]", JsonConvert.SerializeObject(user)));

                    if (user != null)
                    {
                        Session["LoginId"] = user.LoginId;
                        Session["Email"]   = user.Email;
                        //return RedirectToLocal(returnUrl);
                        return(RedirectToAction("Index", "Complain"));
                    }
                    else
                    {
                        ViewBag.Message = "Wrong email or password";
                        return(View());
                    }
                }
                catch (Exception ex)
                {
                    ViewBag.Message = "Something went wrong,Please check your internet connection";
                    logger.Error(ex);
                    return(View());
                }
            }
            else
            {
                return(View());
            }
        }
Esempio n. 5
0
        private void ExportSecurityXMLFiles(string inputFilePath, string outputFolderPath)
        {
            List <SecurityLayer> securityLayerList = (List <SecurityLayer>)dgvSecurityLayers.DataSource;
            string rootFolderPath = outputFolderPath + @"\D365FOCustomizedSecurity";
            string roleFolderPath = rootFolderPath + @"\AxSecurityRole";
            string dutyFolderPath = rootFolderPath + @"\AxSecurityDuty";
            string privFolderPath = rootFolderPath + @"\AxSecurityPrivilege";

            Directory.CreateDirectory(rootFolderPath);
            Directory.CreateDirectory(roleFolderPath);
            Directory.CreateDirectory(dutyFolderPath);
            Directory.CreateDirectory(privFolderPath);

            XmlDocument xDoc = new XmlDocument();

            xDoc.Load(inputFilePath);
            XmlNodeList roles = xDoc.GetElementsByTagName("AxSecurityRole");

            foreach (XmlNode role in roles)
            {
                string roleName = role["Name"]?.InnerText;
                if (roleName != null)
                {
                    SecurityLayer roleSecurityLayer = securityLayerList.FirstOrDefault(sl => sl.OldName == roleName && sl.Type == "Role");
                    if (roleSecurityLayer != null)
                    {
                        string fileName = roleFolderPath + @"\" + roleSecurityLayer.Name + @".xml";
                        string xml      = ReplaceSecurityLayerParameters(role.OuterXml, roleSecurityLayer);
                        File.WriteAllText(fileName, xml);
                    }
                }
            }
            XmlNodeList duties = xDoc.GetElementsByTagName("AxSecurityDuty");

            foreach (XmlNode duty in duties)
            {
                string dutyName = duty["Name"]?.InnerText;

                if (dutyName != null)
                {
                    SecurityLayer dutySecurityLayer = securityLayerList.FirstOrDefault(sl => sl.OldName == dutyName && sl.Type == "Duty");
                    if (dutySecurityLayer != null)
                    {
                        string fileName = dutyFolderPath + @"\" + dutySecurityLayer.Name + @".xml";
                        string xml      = ReplaceSecurityLayerParameters(duty.OuterXml, dutySecurityLayer);
                        File.WriteAllText(fileName, xml);
                    }
                }
            }
            XmlNodeList privileges = xDoc.GetElementsByTagName("AxSecurityPrivilege");

            foreach (XmlNode privilege in privileges)
            {
                string privilegeName = privilege["Name"]?.InnerText;

                if (privilegeName != null)
                {
                    SecurityLayer privSecurityLayer = securityLayerList.FirstOrDefault(sl => sl.OldName == privilegeName && sl.Type == "Privilege");
                    if (privSecurityLayer != null)
                    {
                        string fileName = privFolderPath + @"\" + privSecurityLayer.Name + @".xml";
                        string xml      = ReplaceSecurityLayerParameters(privilege.OuterXml, privSecurityLayer);
                        File.WriteAllText(fileName, xml);
                    }
                }
            }
        }
Esempio n. 6
0
        private List <SecurityLayer> ParseInputXML(string inputFilePath)
        {
            List <SecurityLayer> securityLayerList = new List <SecurityLayer>();
            XmlDocument          xDoc = new XmlDocument();

            xDoc.Load(inputFilePath);
            XmlNodeList roles = xDoc.GetElementsByTagName("AxSecurityRole");

            foreach (XmlNode role in roles)
            {
                string roleName = role["Name"]?.InnerText;
                if (roleName != null)
                {
                    SecurityLayer sl = new SecurityLayer
                    {
                        OldName        = roleName,
                        Name           = roleName,
                        OldLabel       = role["Label"]?.InnerText ?? "",
                        Label          = role["Label"]?.InnerText ?? "",
                        OldDescription = role["Description"]?.InnerText ?? "",
                        Description    = role["Description"]?.InnerText ?? "",
                        Type           = "Role"
                    };
                    securityLayerList.Add(sl);
                }
            }

            XmlNodeList duties = xDoc.GetElementsByTagName("AxSecurityDuty");

            foreach (XmlNode duty in duties)
            {
                string dutyName = duty["Name"]?.InnerText;
                if (dutyName != null)
                {
                    SecurityLayer sl = new SecurityLayer
                    {
                        OldName        = dutyName,
                        Name           = dutyName,
                        OldLabel       = duty["Label"]?.InnerText ?? "",
                        Label          = duty["Label"]?.InnerText ?? "",
                        OldDescription = duty["Description"]?.InnerText ?? "",
                        Description    = duty["Description"]?.InnerText ?? "",
                        Type           = "Duty"
                    };
                    securityLayerList.Add(sl);
                }
            }

            XmlNodeList privileges = xDoc.GetElementsByTagName("AxSecurityPrivilege");

            foreach (XmlNode privilege in privileges)
            {
                string privilegeName = privilege["Name"]?.InnerText;
                if (privilegeName != null)
                {
                    SecurityLayer sl = new SecurityLayer
                    {
                        OldName        = privilegeName,
                        Name           = privilegeName,
                        OldLabel       = privilege["Label"]?.InnerText ?? "",
                        Label          = privilege["Label"]?.InnerText ?? "",
                        OldDescription = privilege["Description"]?.InnerText ?? "",
                        Description    = privilege["Description"]?.InnerText ?? "",
                        Type           = "Privilege"
                    };
                    securityLayerList.Add(sl);
                }
            }
            return(securityLayerList);
        }