Package org.apache.harmony.security

Examples of org.apache.harmony.security.PolicyEntry


    /**
     * Tests constructor and accessors of PolicyEntry
     */
    public void testCtor() {
        PolicyEntry pe = new PolicyEntry(null, null, null);
        assertTrue(pe.isVoid());
        assertNull(pe.getPermissions());

        pe = new PolicyEntry(new CodeSource(null, (Certificate[])null),
            new ArrayList(), new ArrayList());
        assertTrue(pe.isVoid());
        assertNull(pe.getPermissions());

        Collection perms = Arrays.asList(new Permission[] {
            new SecurityPermission("dsfg"), new AllPermission() });
        pe = new PolicyEntry(null, null, perms);
        assertFalse(pe.isVoid());
        assertEquals(perms, new ArrayList(pe.getPermissions()));
    }
View Full Code Here


     */
    public void testImpliesCodeSource() throws Exception {
        CodeSource cs1 = new CodeSource(null, (Certificate[])null);
        CodeSource cs2 = new CodeSource(new URL("file://*"),
            (Certificate[])null);
        PolicyEntry pe = new PolicyEntry(null, null, null);

        assertTrue(pe.impliesCodeSource(null));
        assertTrue(pe.impliesCodeSource(cs1));
        assertTrue(pe.impliesCodeSource(cs2));

        pe = new PolicyEntry(cs2, null, null);
        assertFalse(pe.impliesCodeSource(null));
        assertFalse(pe.impliesCodeSource(cs1));
        assertTrue(pe.impliesCodeSource(cs2));
        assertTrue(pe.impliesCodeSource(new CodeSource(new URL("file://-"),
            (Certificate[])null)));
    }
View Full Code Here

    /**
     * Null or empty set of Principals of PolicyEntry implies any Principals;
     * otherwise tested set must contain all Principals of PolicyEntry.
     */
    public void testImpliesPrincipals() {
        PolicyEntry pe = new PolicyEntry(null, null, null);
        Principal[] pp1 = new Principal[] {};
        Principal[] pp2 = new Principal[] { new UnresolvedPrincipal("a.b.c",
            "XXX") };
        Principal[] pp3 = new Principal[] {
            new UnresolvedPrincipal("a.b.c", "YYY"),
            new UnresolvedPrincipal("a.b.c", "XXX"),
            new UnresolvedPrincipal("e.f.g", "ZZZ") };

        assertTrue(pe.impliesPrincipals(null));
        assertTrue(pe.impliesPrincipals(pp1));

        pe = new PolicyEntry(null, new HashSet(), null);
        assertTrue(pe.impliesPrincipals(pp3));

        pe = new PolicyEntry(null, Arrays.asList(pp2), null);
        assertFalse(pe.impliesPrincipals(null));
        assertFalse(pe.impliesPrincipals(pp1));
        assertTrue(pe.impliesPrincipals(pp3));
    }
View Full Code Here

        Collection<PolicyEntry> result = new HashSet<PolicyEntry>();
        for (Iterator<GrantEntry> iter = grantEntries.iterator(); iter.hasNext();) {
            DefaultPolicyScanner.GrantEntry ge = iter
                    .next();
            try {
                PolicyEntry pe = resolveGrant(ge, ks, system, resolve);
                if (!pe.isVoid()) {
                    result.add(pe);
                }
            }
            catch (Exception e) {
                // TODO: log warning
View Full Code Here

                catch (Exception e) {
                    // TODO: log warning
                }
            }
        }
        return new PolicyEntry(new CodeSource(codebase, signers), principals,
                permissions);
    }
View Full Code Here

        Collection<PolicyEntry> result = new HashSet<PolicyEntry>();
        for (Iterator<GrantEntry> iter = grantEntries.iterator(); iter.hasNext();) {
            DefaultPolicyScanner.GrantEntry ge = iter
                    .next();
            try {
                PolicyEntry pe = resolveGrant(ge, ks, system, resolve);
                if (!pe.isVoid()) {
                    result.add(pe);
                }
            }
            catch (Exception e) {
                // TODO: log warning
View Full Code Here

                catch (Exception e) {
                    // TODO: log warning
                }
            }
        }
        return new PolicyEntry(new CodeSource(codebase, signers), principals,
                permissions);
    }
View Full Code Here

    /**
     * Tests that policy is really resetted on refresh().
     */
    public void testRefresh() {
        Permission sp = new SecurityPermission("sdf");
        PolicyEntry[] pe = new PolicyEntry[] { new PolicyEntry(null, null,
            Arrays.asList(new Permission[] { sp })) };
        TestParser tp = new TestParser(pe);
        DefaultPolicy policy = new DefaultPolicy(tp);
        CodeSource cs = new CodeSource(null, (Certificate[])null);
        assertTrue(policy.getPermissions(cs).implies(sp));
View Full Code Here

        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));
View Full Code Here

            (Certificate[])null);
        ProtectionDomain pd1 = new ProtectionDomain(cs, null);
        ProtectionDomain pd2 = new ProtectionDomain(cs2, pcZ, null,
            new Principal[] { new FakePrincipal("qqq") });

        PolicyEntry pe1 = new PolicyEntry(cs, null, Arrays
            .asList(new Permission[] { sp1 }));
        PolicyEntry pe2 = new PolicyEntry(cs2, Arrays
            .asList(new Principal[] { new UnresolvedPrincipal(
                UnresolvedPrincipal.WILDCARD, UnresolvedPrincipal.WILDCARD) }),
            Arrays.asList(new Permission[] { sp2 }));
        PolicyEntry pe3 = new PolicyEntry(cs, Arrays
            .asList(new Principal[] { new UnresolvedPrincipal(
                FakePrincipal.class.getName(), "qqq") }), Arrays
            .asList(new Permission[] { sp3 }));
        PolicyEntry pe4 = new PolicyEntry(cs2, Arrays
            .asList(new Principal[] { new UnresolvedPrincipal(
                FakePrincipal.class.getName(), "ttt") }), Arrays
            .asList(new Permission[] { sp4 }));
        PolicyEntry[] peArray = new PolicyEntry[] {
            pe1, pe2, pe3, pe4 };
View Full Code Here

TOP

Related Classes of org.apache.harmony.security.PolicyEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.