InternalClientConnection rootConnection =
InternalClientConnection.getRootConnection();
ArrayList<Modification> mods = new ArrayList<Modification>();
mods.add(new Modification(ModificationType.ADD, Attributes.create(
"ds-privilege-name", "jmx-read")));
ModifyOperation modifyOperation =
rootConnection.processModify(DN.decode(user), mods);
assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS);
// Try connection withoutJMX_READ privilege
// Expected result: success
try
{
nasutekdsConnector = new OpendsJmxConnector("localhost", jmxPort, env);
nasutekdsConnector.connect();
nasutekdsConnector.close() ;
assertTrue(true, "User \"cn=Unprivileged JMX Root,cn=Root "+
"DNs,cn=config\" has JMX_READ privilege and he's able " +
"to connect, which is the correct behavior.");
}
catch (SecurityException e)
{
assertTrue(false, "User \"cn=Unprivileged JMX Root,cn=Root " +
"DNs,cn=config\" has JMX_READ privilege and he's NOT able " +
"to connect, which is NOT the correct behavior.");
}
catch (IOException e)
{
assertTrue(false, "Unexpected exception - error message: "
+ e.getMessage());
}
// remove JMX_READ privilege
mods = new ArrayList<Modification>();
mods.add(new Modification(ModificationType.DELETE,
Attributes.create("ds-privilege-name", "jmx-read")));
modifyOperation =
rootConnection.processModify(DN.decode(user), mods);
assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS);
// Try connection withoutJMX_READ privilege
// Expected result: failed
try
{