Code example for Permissions

0
 
        // test case: check assigned principals 
        URL url = new URL("file://foo.txt");
 
        CodeSource source = new CodeSource(url, (Certificate[]) null);
        PermissionCollection permissions = new Permissions();
        ClassLoader classLoader = new URLClassLoader(new URL[] { url });
 
        Principal p = new Principal() {
            public String getName() {
                return "p"; 
            } 
        }; 
        Principal[] principals = new Principal[] { p };
 
        ProtectionDomain domain = new ProtectionDomain(source, permissions,
                classLoader, principals);
 
        pd = combiner.combine(new ProtectionDomain[] { domain }, null);
 
        assertSame("CodeSource", source, pd[0].getCodeSource());
        assertSame("PermissionCollection", permissions, pd[0]
                .getPermissions());
        assertSame("ClassLoader", classLoader, pd[0].getClassLoader());
 
        assertEquals("Size", 1, pd[0].getPrincipals().length);
        assertSame("Principal", principal, (pd[0].getPrincipals())[0]);