### Question:
ComposableSecurityManagerPolicy extends java.security.Policy { @Override public boolean implies(ProtectionDomain protectionDomain, Permission permission) { if (privileged.get() == Boolean.TRUE) { return true; } if ("setSecurityManager".equals(permission.getName()) || "setPolicy".equals(permission.getName())) { return false; } try { privileged.set(Boolean.TRUE); return enforce(permission); } finally { privileged.set(Boolean.FALSE); } } ComposableSecurityManagerPolicy(SecurityManager originalManager,
      java.security.Policy originalPolicy); @Override boolean implies(ProtectionDomain protectionDomain, Permission permission); @Override PermissionCollection getPermissions(ProtectionDomain domain); @Override PermissionCollection getPermissions(CodeSource domain); static void setDefaultPolicy(io.takari.builder.enforcer.Policy policy); static void registerContextPolicy(Object key, io.takari.builder.enforcer.Policy policy); static io.takari.builder.enforcer.Policy unregisterContextPolicy(Object key); static io.takari.builder.enforcer.Policy getContextPolicy(Object key); static ComposableSecurityManagerPolicy setSystemSecurityManager(); static ComposableSecurityManagerPolicy removeSystemSecurityManager(); static final PermissionCollection allPermissions; }### Answer:
@Test public void testSystemProperties() throws Exception { Policy policy = new EmptyPolicy() { @Override public void checkPropertyPermission(String action, String name) { throw new SecurityException(); } }; ComposableSecurityManagerPolicy testee = newPolicy(policy); try { testee.implies(this.getClass().getProtectionDomain(), new PropertyPermission("*", "read")); fail(); } catch (SecurityException expected) { } try { testee.implies(this.getClass().getProtectionDomain(), new PropertyPermission("*", "read")); fail(); } catch (SecurityException expected) { } }
@Test(expected = SecurityException.class) public void testNetworkAccess() throws Exception { Policy policy = new EmptyPolicy() { @Override public void checkSocketPermission() { throw new SecurityException(); } }; ComposableSecurityManagerPolicy testee = newPolicy(policy); testee.implies(this.getClass().getProtectionDomain(), new SocketPermission("localhost", "connect")); }
@Test public void testComposition() throws Exception { Policy policy1 = new EmptyPolicy() { @Override public void checkRead(String file) { if ("1".equals(file)) { throw new SecurityException(); } } }; Policy policy2 = new EmptyPolicy() { @Override public void checkRead(String file) { if ("2".equals(file)) { throw new SecurityException(); } } }; ComposableSecurityManagerPolicy testee = newPolicy(policy1, policy2); try { testee.implies(this.getClass().getProtectionDomain(), new FilePermission("1", "read")); fail(); } catch (SecurityException expected) { } try { testee.implies(this.getClass().getProtectionDomain(), new FilePermission("2", "read")); fail(); } catch (SecurityException expected) { } try { testee.implies(this.getClass().getProtectionDomain(), new FilePermission("3", "read")); } catch (SecurityException expected) { fail(); } }