| | |
| | | import static org.testng.Assert.assertFalse; |
| | | import static org.testng.Assert.assertNotNull; |
| | | import static org.testng.Assert.assertTrue; |
| | | import static org.testng.Assert.fail; |
| | | |
| | | import java.io.BufferedWriter; |
| | | import java.io.File; |
| | | import java.io.FileWriter; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.UUID; |
| | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * This class provides a set of test cases for the Directory Server JMX |
| | | * privilege subsystem. |
| | |
| | | /** |
| | | * Check that simple connection to the JMX service are |
| | | * accepted only if JMX_READ privilege is set. |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test(enabled = true) |
| | | public void simpleConnectJmxPrivilege() throws Exception |
| | |
| | | opendsConnector = new OpendsJmxConnector("localhost", jmxPort, env); |
| | | opendsConnector.connect(); |
| | | opendsConnector.close() ; |
| | | assertTrue(false, "User \"cn=Unprivileged JMX Root,cn=Root "+ |
| | | fail("User \"cn=Unprivileged JMX Root,cn=Root "+ |
| | | "DNs,cn=config\" doesn't have JMX_READ privilege but he's able " + |
| | | "to connect, which is not the correct behavior"); |
| | | } |
| | |
| | | Message message = ERR_JMX_INSUFFICIENT_PRIVILEGES.get(); |
| | | assertEquals(message.toString(), e.getMessage()); |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | assertTrue(false, "Unexpected exception - error message: " |
| | | + e.getMessage()); |
| | | } |
| | | |
| | | // Add JMX_READ privilege |
| | | InternalClientConnection rootConnection = |
| | |
| | | opendsConnector = new OpendsJmxConnector("localhost", jmxPort, env); |
| | | opendsConnector.connect(); |
| | | opendsConnector.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 " + |
| | | fail("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>(); |
| | |
| | | opendsConnector = new OpendsJmxConnector("localhost", jmxPort, env); |
| | | opendsConnector.connect(); |
| | | opendsConnector.close() ; |
| | | assertTrue(false, "User \"cn=Unprivileged JMX Root,cn=Root "+ |
| | | fail("User \"cn=Unprivileged JMX Root,cn=Root "+ |
| | | "DNs,cn=config\" doesn't have JMX_READ privilege but he's able " + |
| | | "to connect, which is not the correct behavior"); |
| | | } |
| | |
| | | Message message = ERR_JMX_INSUFFICIENT_PRIVILEGES.get(); |
| | | assertEquals(message.toString(), e.getMessage()); |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | assertTrue(false, "Unexpected exception - error message: " |
| | | + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | if (task == null) |
| | | { |
| | | throw new AssertionError("There is no such task " + |
| | | taskEntryDN.toString()); |
| | | } |
| | | |
| | | assertNotNull(task, "There is no such task " + taskEntryDN.toString()); |
| | | if (! TaskState.isDone(task.getTaskState())) |
| | | { |
| | | long stopWaitingTime = System.currentTimeMillis() + 20000L; |
| | |
| | | } |
| | | } |
| | | |
| | | if (! TaskState.isDone(task.getTaskState())) |
| | | { |
| | | throw new AssertionError("Task " + taskEntryDN.toString() + |
| | | " did not complete in a timely manner."); |
| | | } |
| | | assertTrue(TaskState.isDone(task.getTaskState()), |
| | | "Task " + taskEntryDN.toString() |
| | | + " did not complete in a timely manner."); |
| | | |
| | | return task; |
| | | } |