Code example for ProtectionDomain

0
                System.arraycopy(b, 0, union, a.length, b.length);
                return union;
            } 
        }; 
 
        ProtectionDomain protectionDomain = new ProtectionDomain(null, new Permissions());
        AccessControlContext accessControlContext = new AccessControlContext(
                new AccessControlContext(new ProtectionDomain[] { protectionDomain }), union);
 
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
            public Void run() {
                // in this block we lack our requested permission 
                assertSame(union, AccessController.getContext().getDomainCombiner());
                assertPermission(false, permission);
 
                AccessController.doPrivileged(new PrivilegedAction<Void>() {
                    public Void run() {
                        // nest doPrivileged to get it back. 
                        assertNull(AccessController.getContext().getDomainCombiner());
                        assertPermission(true, permission);
                        return null;