Code example for CodeSource

0
 
    /** 
     * Tests proper policy evaluation for CodeSource parameters. 
     */ 
    public void testGetPermissions_CodeSource() throws Exception { 
        CodeSource cs = new CodeSource(null, (Certificate[])null);
        CodeSource cs2 = new CodeSource(new URL("http://a.b.c"),
            (Certificate[])null);
        Permission sp1 = new SecurityPermission("aaa");
        Permission sp2 = new SecurityPermission("bbb");
        Permission sp3 = new SecurityPermission("ccc");
        PolicyEntry pe1 = new PolicyEntry(cs, null, Arrays
            .asList(new Permission[] { sp1 }));
        PolicyEntry pe2 = new PolicyEntry(cs2, new HashSet(), Arrays
            .asList(new Permission[] { sp2 }));
        PolicyEntry pe3 = new PolicyEntry(cs, Arrays
            .asList(new Principal[] { new FakePrincipal("qqq") }), Arrays
            .asList(new Permission[] { sp3 }));
        PolicyEntry[] peArray = new PolicyEntry[] {
            pe1, pe2, pe3 };
        DefaultPolicy policy = new DefaultPolicy(new TestParser(peArray));