Code example for SerializablePermission

0
 
        // custom security manager 
        SecurityManager sm = new SecurityManager() {
 
            final SerializablePermission forbidenPermission =
                new SerializablePermission("enableSubclassImplementation");
 
            public void checkPermission(Permission perm) {
                if (forbidenPermission.equals(perm)) {
                    throw new SecurityException();
                } 
            } 
        }; 
 
        SecurityManager oldSm = System.getSecurityManager();
        System.setSecurityManager(sm);
        try { 
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            // should not cause SecurityException 
            new ObjectOutputStream(out);
            // should not cause SecurityException