policy.setSeparateClientServerPermissions(true);
Map clientEnv = createClientEnvironment();
clientEnv.put(JMXConnector.CREDENTIALS, new String[]{"test", "test"});
policy.addClientPermission(new SocketPermission("localhost:" + url.getPort(), "connect"));
policy.addServerPermission(new JMXPrincipal("test"), new AuthPermission("doAsPrivileged"));
policy.addServerPermission(new JMXPrincipal("test"), new SocketPermission("localhost:" + url.getPort(), "listen"));
policy.addServerPermission(new JMXPrincipal("test"), new SocketPermission("*:1024-" + url.getPort(), "accept"));
cntor = JMXConnectorFactory.connect(cntorServer.getAddress(), clientEnv);
addPermission(new MBeanTrustPermission("*"));
policy.addServerPermission(new JMXPrincipal("delegate"), new MBeanPermission("*", "instantiate, registerMBean, getAttribute"));
policy.addServerPermission(new JMXPrincipal("test"), new SubjectDelegationPermission(JMXPrincipal.class.getName() + ".delegate"));
Set delegates = new HashSet();
delegates.add(new JMXPrincipal("delegate"));
Subject delegate = new Subject(true, delegates, Collections.EMPTY_SET, Collections.EMPTY_SET);
MBeanServerConnection cntion = cntor.getMBeanServerConnection(delegate);
ObjectName name = ObjectName.getInstance(":name=subject");
cntion.createMBean(SubjectCheck.class.getName(), name, null);
policy.addServerPermission(new JMXPrincipal("delegate"), new AuthPermission("getSubject"));
Subject subject = (Subject)cntion.getAttribute(name, "Subject");
Set principals = subject.getPrincipals();
assertNotNull(principals);
assertEquals(principals.size(), 1);