Exemplo n.º 1
0
    // Summarize the attributes of the specified PolicyStatement on the
    // console window.
    private static void summarizePolicyStatment(
        PolicyStatement policyStatement)
    {
        // Retrieve the class path for policyStatement.
        //<Snippet11>
        string policyStatementClass = policyStatement.ToString();
        //</Snippet11>

        //<Snippet12>
        int hashCode = policyStatement.GetHashCode();
        //</Snippet12>

        string attributeString = "";

        // Retrieve the string representation of the PolicyStatement
        // attributes.
        //<Snippet13>
        if (policyStatement.AttributeString != null)
        {
            attributeString = policyStatement.AttributeString;
        }
        //</Snippet13>

        // Write a summary to the console window.
        Console.WriteLine("\n*** " + policyStatementClass + " summary ***");
        Console.Write("This PolicyStatement has been created with hash ");
        Console.Write("code(" + hashCode + ") ");

        Console.Write("and contains the following attributes: ");
        Console.WriteLine(attributeString);
    }
Exemplo n.º 2
0
    // Retrieve the resolved policy based on Evidence from the executing
    // assembly found in the specified code group.
    private static string ResolveEvidence(CodeGroup fileCodeGroup)
    {
        string policyString = "";

        // Resolve the policy based on evidence in the executing assembly.
        Assembly assembly          = typeof(Members).Assembly;
        Evidence executingEvidence = assembly.Evidence;

        PolicyStatement policy = fileCodeGroup.Resolve(executingEvidence);

        if (policy != null)
        {
            policyString = policy.ToString();
        }

        return(policyString);
    }
Exemplo n.º 3
0
    // If a class attribute is not found in the specified PolicyStatement,
    // add a child XML element with an added class attribute.
    private static void addXmlMember(ref PolicyStatement policyStatement)
    {
        SecurityElement xmlElement = policyStatement.ToXml();

        if (xmlElement.Attribute("class") == null)
        {
            SecurityElement newElement =
                new SecurityElement("PolicyStatement");
            newElement.AddAttribute("class", policyStatement.ToString());
            newElement.AddAttribute("version", "1.1");

            newElement.AddChild(new SecurityElement("PermissionSet"));

            policyStatement.FromXml(newElement);

            Console.Write("Added the class attribute and modified its ");
            Console.WriteLine("version number.\n" + newElement.ToString());
        }
    }
Exemplo n.º 4
0
    // Retrieve the resolved policy based on executing evidence found
    // in the specified code group.
    private static string ResolveEvidence(CodeGroup codeGroup)
    {
        string policyString = "None";

        // Resolve the policy based on the executing assembly's evidence.
        //<Snippet19>
        Assembly assembly          = typeof(Members).Assembly;
        Evidence executingEvidence = assembly.Evidence;

        PolicyStatement policy = codeGroup.Resolve(executingEvidence);

        //</Snippet19>

        if (policy != null)
        {
            policyString = policy.ToString();
        }

        return(policyString);
    }