Пример #1
0
        private static PolicyDocument CreatePolicyDocument(PolicyDocumentEntity entity)
        {
            var policyDocument = new PolicyDocument();

            policyDocument.AddStatements(entity.Statements);
            return(policyDocument);
        }
Пример #2
0
        static public string TestPolicy(PolicyDocumentEntity policyDoc, QueryEntity cie)
        {
            xmlGenerate gen     = new xmlGenerate();
            string      request = gen.generate(cie);
            string      policy  = gen.generate(policyDoc);

            string res = string.Empty;

            try
            {
#if REMOTE_SERVICE
                policyService.TestPolicy policyService = new PolicyBuilder.policyService.TestPolicy();
                res = policyService.Test(policy, request);
#else
                policyShimLib.TestPolicyClass tpc = new policyShimLib.TestPolicyClass();
                res = tpc.Test(policy, request);
#endif
            }
            catch (Exception ex)
            {
                res = "!!service down!! - try refresh " + ex.Message;
            }

            return(res);
        }
Пример #3
0
        public ActionResult Import(baseData vData, FormCollection collection)
        {
            if (Request.Files.Count > 0)
            {
                // Save the uploaded file.
                string path       = string.Format("~/imports/{0}.xml", Path.GetRandomFileName());
                string mappedPath = Server.MapPath(path);

                Request.Files[0].SaveAs(mappedPath);

                try
                {
                    string title = Path.GetFileName(Request.Files[0].FileName);
                    if (Path.GetExtension(title) == ".xml" || Path.GetExtension(title) == ".conf")
                    {
                        title = Path.GetFileNameWithoutExtension(title);
                    }

                    PolicyDocumentEntity pde = importFile(vData, title, mappedPath);

                    return(RedirectToAction("EditPolicyDoc", "policy", new { id = pde.Id }));
                }
                catch (Exception ex)
                {
                    TempData["error"] = ex.Message;
                }
            }
            else
            {
                TempData["message"] = "select a file to upload";
            }

            return(RedirectToAction("Index", "policy"));
        }
        /// <summary>Creates a new, empty PolicyDocumentEntity object.</summary>
        /// <returns>A new, empty PolicyDocumentEntity object.</returns>
        public override IEntity Create()
        {
            IEntity toReturn = new PolicyDocumentEntity();

            // __LLBLGENPRO_USER_CODE_REGION_START CreateNewPolicyDocument
            // __LLBLGENPRO_USER_CODE_REGION_END
            return(toReturn);
        }
        public string GetDocumentXML(int docId)
        {
            string xml = string.Empty;

            PolicyDocumentEntity pde = new PolicyDocumentEntity(docId);
            xmlGenerate gen = new xmlGenerate();
            xml = gen.generate(pde);

            return xml;
        }
Пример #6
0
        static private void DeletePolicyDoc(PolicyDocumentEntity pde)
        {
            PolicyLinkEntity policyLink = pde.PolicyLink;

            pde.Delete();

            if (!policyLink.IsNew)
            {
                DeletePolicyLink(policyLink);
            }
        }
Пример #7
0
        public string GetDocumentXML(int docId)
        {
            string xml = string.Empty;

            PolicyDocumentEntity pde = new PolicyDocumentEntity(docId);
            xmlGenerate          gen = new xmlGenerate();

            xml = gen.generate(pde);

            return(xml);
        }
Пример #8
0
        public string generate(PolicyDocumentEntity doc)
        {
            StringBuilder sb = new StringBuilder();

            if (doc.PolicyLinkId.HasValue)
            {
                sb.Append("<?xml version=\"1.0\" encoding=\"us-ascii\"?>");
                generate(sb, doc.PolicyLink);
            }

            return(sb.ToString());
        }
Пример #9
0
        private PolicyDocumentEntity importFile(baseData vData, string title, string filepath)
        {
            AttributeCollection acoll = new AttributeCollection();

            acoll.GetMulti(AttributeFields.Name == "Literal");
            if (acoll.Count == 0)
            {
                throw new Exception("can't find literal attribute");
            }
            m_literalAttribute = acoll[0];

            XmlDocument doc = new XmlDocument();

            doc.Load(filepath);

            PolicyDocumentEntity pde = new PolicyDocumentEntity();

            pde.LibraryId = vData.Library.Id;
            pde.Name      = title;

            PolicyLinkEntity ple = new PolicyLinkEntity();

            ple.Policy           = new PolicyEntity();
            ple.Policy.LibraryId = pde.LibraryId;
            pde.PolicyLink       = ple;

            XmlNode policySet = doc.SelectSingleNode("policy-set");

            if (policySet != null)
            {
                loadPolicySet(1, title, ple, policySet);
            }
            else
            {
                XmlNode policy = doc.SelectSingleNode("policy");
                loadPolicy(1, title, ple, policy);
            }

            pde.Save(true);

            return(pde);
        }
Пример #10
0
        public static string TestPolicy(PolicyDocumentEntity policyDoc, QueryEntity cie)
        {
            xmlGenerate gen = new xmlGenerate();
            string request = gen.generate(cie);
            string policy = gen.generate(policyDoc);

            string res = string.Empty;
            try
            {
            #if REMOTE_SERVICE
                policyService.TestPolicy policyService = new PolicyBuilder.policyService.TestPolicy();
                res = policyService.Test(policy, request);
            #else
                policyShimLib.TestPolicyClass tpc = new policyShimLib.TestPolicyClass();
                res = tpc.Test(policy, request);
            #endif
            }
            catch (Exception ex)
            {
                res = "!!service down!! - try refresh " + ex.Message;
            }

            return res;
        }
        private PolicyDocumentEntity importFile(baseData vData,string title, string filepath)
        {
            AttributeCollection acoll = new AttributeCollection();
            acoll.GetMulti(AttributeFields.Name == "Literal");
            if (acoll.Count == 0)
                throw new Exception("can't find literal attribute");
            m_literalAttribute = acoll[0];

            XmlDocument doc = new XmlDocument();
            doc.Load(filepath);

            PolicyDocumentEntity pde = new PolicyDocumentEntity();
            pde.LibraryId = vData.Library.Id;
            pde.Name = title;

            PolicyLinkEntity ple = new PolicyLinkEntity();
            ple.Policy = new PolicyEntity();
            ple.Policy.LibraryId = pde.LibraryId;
            pde.PolicyLink = ple;

            XmlNode policySet = doc.SelectSingleNode("policy-set");
            if (policySet != null)
                loadPolicySet(1,title,ple,policySet);
            else
            {
                XmlNode policy = doc.SelectSingleNode("policy");
                loadPolicy(1,title,ple,policy);
            }

            pde.Save(true);

            return pde;
        }
        private static void DeletePolicyDoc(PolicyDocumentEntity pde)
        {
            PolicyLinkEntity policyLink = pde.PolicyLink;
            pde.Delete();

            if (!policyLink.IsNew)
                DeletePolicyLink(policyLink);
        }
Пример #13
0
        /// <summary>Creates a new, empty PolicyDocumentEntity object.</summary>
        /// <returns>A new, empty PolicyDocumentEntity object.</returns>
        public override IEntity Create()
        {
            IEntity toReturn = new PolicyDocumentEntity();

            // __LLBLGENPRO_USER_CODE_REGION_START CreateNewPolicyDocument
            // __LLBLGENPRO_USER_CODE_REGION_END
            return toReturn;
        }