Alpha code for Secret Persistence Policy. In Progress.
This commit is contained in:
@@ -22,6 +22,8 @@
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
@@ -54,13 +56,91 @@ public class PersistencePol : CASAPol
|
||||
}
|
||||
}
|
||||
|
||||
public PersistencePol(string osName,string path, int time)
|
||||
public PersistencePol(string osName,string path, int time)
|
||||
{
|
||||
policyType = CASAPolType.PERSISTENCE_POL;
|
||||
os = osName;
|
||||
filePath = path;
|
||||
pollInterval = time;
|
||||
}
|
||||
|
||||
|
||||
public PersistencePol(string osName,string path, int time, Hashtable htPolicies)
|
||||
{
|
||||
policyType = CASAPolType.PERSISTENCE_POL;
|
||||
os = osName;
|
||||
filePath = path;
|
||||
pollInterval = time;
|
||||
htSecretPolicys = htPolicies;
|
||||
}
|
||||
|
||||
private Hashtable htSecretPolicys; // = new Hashtable();
|
||||
public void SetSecretPolicy(string sSecretID, string sPolicyAttribID, string sPolicyAttribValue, string sDefaultValue)
|
||||
{
|
||||
|
||||
if (htSecretPolicys == null)
|
||||
{
|
||||
htSecretPolicys = new Hashtable();
|
||||
}
|
||||
|
||||
// find policys for given secretID
|
||||
NameValueCollection nvc = (NameValueCollection)htSecretPolicys[sSecretID];
|
||||
if (nvc == null)
|
||||
{
|
||||
nvc = new NameValueCollection();
|
||||
htSecretPolicys.Add(sSecretID, nvc);
|
||||
}
|
||||
|
||||
if (sPolicyAttribValue.Equals(sDefaultValue))
|
||||
{
|
||||
nvc.Remove(sPolicyAttribID);
|
||||
}
|
||||
else
|
||||
{
|
||||
nvc.Set(sPolicyAttribID, sPolicyAttribValue);
|
||||
}
|
||||
}
|
||||
|
||||
public bool GetSecretPolicy(string sSecretID, string sPolicyAttribID, bool bDefaultValue)
|
||||
{
|
||||
string sReturn = GetSecretPolicy(sSecretID, sPolicyAttribID, bDefaultValue.ToString());
|
||||
return bool.Parse(sReturn);
|
||||
}
|
||||
|
||||
public string GetSecretPolicy(string sSecretID, string sPolicyAttribID, string sDefaultValue)
|
||||
{
|
||||
if (htSecretPolicys != null)
|
||||
{
|
||||
NameValueCollection nvc = (NameValueCollection)htSecretPolicys[sSecretID];
|
||||
if (nvc != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
return nvc.GetValues(sPolicyAttribID)[0];
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sDefaultValue;
|
||||
}
|
||||
|
||||
public ArrayList GetNonpersistentSecretIDs()
|
||||
{
|
||||
ArrayList al = new ArrayList();
|
||||
|
||||
//enumerate all secrets loaded
|
||||
IDictionaryEnumerator idEnum = htSecretPolicys.GetEnumerator();
|
||||
while (idEnum.MoveNext())
|
||||
{
|
||||
string sSecretID = (string)idEnum.Key;
|
||||
al.Add(sSecretID);
|
||||
}
|
||||
|
||||
return al;
|
||||
}
|
||||
|
||||
public override void DumpPol()
|
||||
{
|
||||
@@ -95,10 +175,40 @@ public class PersistencePol : CASAPol
|
||||
elem.InnerText = pollInterval.ToString();
|
||||
|
||||
persistPolElem.AppendChild(elem);
|
||||
|
||||
// write out policy for secrets
|
||||
// write out NameValueCollection
|
||||
XmlElement configElem = doc.CreateElement("SecretPolicies");
|
||||
persistPolElem.AppendChild(configElem);
|
||||
|
||||
IDictionaryEnumerator ienum = htSecretPolicys.GetEnumerator();
|
||||
while (ienum.MoveNext())
|
||||
{
|
||||
// get the collection for current SecretID
|
||||
string sCurrentID = ienum.Key.ToString();
|
||||
NameValueCollection nvc = (NameValueCollection)htSecretPolicys[sCurrentID];
|
||||
|
||||
// if no attributes exist, skip it
|
||||
if (nvc.Count == 0) continue;
|
||||
|
||||
// create a policy element
|
||||
XmlElement policyElement = doc.CreateElement("Secret");
|
||||
policyElement.SetAttribute("id", sCurrentID);
|
||||
|
||||
// add all attributes
|
||||
for (int i=0; i<nvc.Count; i++)
|
||||
{
|
||||
policyElement.SetAttribute(nvc.GetKey(i), nvc.GetValues(i)[0]);
|
||||
}
|
||||
|
||||
configElem.AppendChild(policyElement);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
//Console.WriteLine(e.ToString());
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
using System.IO;
|
||||
@@ -179,7 +181,49 @@ public class ICASAPol
|
||||
XmlNode pollIntervalNode = persistenceNode.SelectSingleNode(xpath);
|
||||
int pollInterval = Convert.ToInt32(pollIntervalNode.InnerText);
|
||||
|
||||
PersistencePol persistencePol = new PersistencePol(os,storeFileLocation, pollInterval);
|
||||
// load SecretPolices
|
||||
xpath = "//SecretPolicies";
|
||||
XmlNode policyNode = persistenceNode.SelectSingleNode(xpath);
|
||||
Hashtable htSecretPolicies = new Hashtable();
|
||||
if (policyNode != null)
|
||||
{
|
||||
XmlNodeList secretNodes = policyNode.ChildNodes;
|
||||
|
||||
IEnumerator ienum = secretNodes.GetEnumerator();
|
||||
while (ienum.MoveNext())
|
||||
{
|
||||
XmlNode node = (XmlNode)ienum.Current;
|
||||
|
||||
// get the id
|
||||
XmlAttributeCollection coll = node.Attributes;
|
||||
XmlNode idNode = coll.GetNamedItem("id");
|
||||
|
||||
|
||||
// get the rest of the attributes
|
||||
IEnumerator enumAttribs = coll.GetEnumerator();
|
||||
NameValueCollection nvc = new NameValueCollection();
|
||||
while (enumAttribs.MoveNext())
|
||||
{
|
||||
XmlAttribute attrib = (XmlAttribute)enumAttribs.Current;
|
||||
if (!attrib.Name.Equals("id"))
|
||||
{
|
||||
nvc.Add(attrib.Name, attrib.Value);
|
||||
}
|
||||
}
|
||||
|
||||
// add this one
|
||||
try
|
||||
{
|
||||
htSecretPolicies.Add(idNode.Value, nvc);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
//Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PersistencePol persistencePol = new PersistencePol(os,storeFileLocation, pollInterval, htSecretPolicies);
|
||||
return persistencePol;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user