| | |
| | | import java.io.FileWriter; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.UUID; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | |
| | | import org.opends.server.backends.task.TaskState; |
| | | import org.opends.server.controls.ProxiedAuthV1Control; |
| | | import org.opends.server.controls.ProxiedAuthV2Control; |
| | | import org.opends.server.core.AddOperation; |
| | | import org.opends.server.core.AddOperationBasis; |
| | | import org.opends.server.core.CompareOperation; |
| | | import org.opends.server.core.CompareOperationBasis; |
| | | import org.opends.server.core.DeleteOperation; |
| | | import org.opends.server.core.DeleteOperationBasis; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.core.ModifyDNOperation; |
| | | import org.opends.server.core.ModifyDNOperationBasis; |
| | | import org.opends.server.core.ModifyOperation; |
| | | import org.opends.server.core.ModifyOperationBasis; |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests to ensure that compare operations in the server configuration |
| | | * properly respect the JMX_READ privilege. |
| | | * |
| | | * @param conn The client connection to use to perform the compare |
| | | * operation. |
| | | * @param hasPrivilege Indicates whether the authenticated user is expected |
| | | * to have the JMX_READ privilege and therefore the |
| | | * compare should succeed. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test(dataProvider = "testdata") |
| | | public void testConfigReadCompare(JmxClientConnection conn, |
| | | boolean hasPrivilege) |
| | | throws Exception |
| | | { |
| | | assertEquals(conn.hasPrivilege(Privilege.JMX_READ, null), hasPrivilege); |
| | | |
| | | ByteString asn1 = ByteString.valueOf("cn=config"); |
| | | ByteString value = ByteString.valueOf("config"); |
| | | CompareOperation compareOperation = |
| | | conn.processCompare(asn1, |
| | | "cn", |
| | | value); |
| | | if (hasPrivilege) |
| | | { |
| | | assertEquals(compareOperation.getResultCode(), ResultCode.COMPARE_TRUE); |
| | | } |
| | | else |
| | | { |
| | | assertEquals(compareOperation.getResultCode(), |
| | | ResultCode.INSUFFICIENT_ACCESS_RIGHTS); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests to ensure that add and delete operations in the server configuration |
| | | * properly respect the CONFIG_WRITE privilege. |
| | | * |
| | | * @param conn The client connection to use to perform the |
| | | * operations. |
| | | * @param hasPrivilege Indicates whether the authenticated user is expected |
| | | * to have the CONFIG_WRITE privilege and therefore the |
| | | * operations should succeed. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test(dataProvider = "testdata") |
| | | public void testConfigWriteAddAndDelete(JmxClientConnection conn, |
| | | boolean hasPrivilege) |
| | | throws Exception |
| | | { |
| | | assertEquals(conn.hasPrivilege(Privilege.JMX_WRITE, null), hasPrivilege); |
| | | |
| | | Entry entry = TestCaseUtils.makeEntry( |
| | | "dn: cn=Test Root,cn=Root DNs,cn=config", |
| | | "objectClass: top", |
| | | "objectClass: person", |
| | | "objectClass: organizationalPerson", |
| | | "objectClass: inetOrgPerson", |
| | | "objectClass: ds-cfg-root-dn-user", |
| | | "cn: Test Root", |
| | | "givenName: Test", |
| | | "sn: Root", |
| | | "userPassword: password"); |
| | | |
| | | AddOperation addOperation = |
| | | conn.processAdd(entry.getName(), entry.getObjectClasses(), |
| | | entry.getUserAttributes(), |
| | | entry.getOperationalAttributes()); |
| | | if (hasPrivilege) |
| | | { |
| | | assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | DeleteOperation deleteOperation = conn.processDelete(entry.getName()); |
| | | assertEquals(deleteOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | else |
| | | { |
| | | assertEquals(addOperation.getResultCode(), |
| | | ResultCode.INSUFFICIENT_ACCESS_RIGHTS); |
| | | |
| | | DeleteOperation deleteOperation = |
| | | conn.processDelete( |
| | | DN.valueOf("cn=Telex Number,cn=Syntaxes,cn=config")); |
| | | assertEquals(deleteOperation.getResultCode(), |
| | | ResultCode.INSUFFICIENT_ACCESS_RIGHTS); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests to ensure that modify operations in the server configuration |
| | | * properly respect the CONFIG_WRITE privilege. |
| | | * |
| | | * @param conn The client connection to use to perform the modify |
| | | * operation. |
| | | * @param hasPrivilege Indicates whether the authenticated user is expected |
| | | * to have the CONFIG_WRITE privilege and therefore the |
| | | * modify should succeed. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test(dataProvider = "testdata") |
| | | public void testConfigWriteModify(JmxClientConnection conn, |
| | | boolean hasPrivilege) |
| | | throws Exception |
| | | { |
| | | assertEquals(conn.hasPrivilege(Privilege.JMX_WRITE, null), hasPrivilege); |
| | | |
| | | ArrayList<Modification> mods = new ArrayList<Modification>(); |
| | | |
| | | mods.add(new Modification(ModificationType.REPLACE, |
| | | Attributes.create("ds-cfg-size-limit", "2000"))); |
| | | |
| | | ModifyOperation modifyOperation = |
| | | conn.processModify(DN.valueOf("cn=config"), mods); |
| | | if (hasPrivilege) |
| | | { |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | mods.clear(); |
| | | mods.add(new Modification(ModificationType.REPLACE, |
| | | Attributes.create("ds-cfg-size-limit", "1000"))); |
| | | |
| | | modifyOperation = conn.processModify(DN.valueOf("cn=config"), mods); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | else |
| | | { |
| | | assertEquals(modifyOperation.getResultCode(), |
| | | ResultCode.INSUFFICIENT_ACCESS_RIGHTS); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests to ensure that modify DN operations in the server configuration |
| | | * properly respect the CONFIG_WRITE privilege. |
| | | * |
| | | * @param conn The client connection to use to perform the modify DN |
| | | * operation. |
| | | * @param hasPrivilege Indicates whether the authenticated user is expected |
| | | * to have the CONFIG_WRITE privilege and therefore the |
| | | * modify DN should succeed (or at least get past the |
| | | * privilege check, only to fail because we don't |
| | | * support modify DN in the server configuration). |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test(dataProvider = "testdata") |
| | | public void testConfigWriteModifyDN(JmxClientConnection conn, |
| | | boolean hasPrivilege) |
| | | throws Exception |
| | | { |
| | | assertEquals(conn.hasPrivilege(Privilege.JMX_WRITE, null), hasPrivilege); |
| | | |
| | | ModifyDNOperation modifyDNOperation = |
| | | conn.processModifyDN(DN.valueOf("cn=Work Queue,cn=config"), |
| | | RDN.decode("cn=New RDN for Work Queue"), true, |
| | | null); |
| | | if (hasPrivilege) |
| | | { |
| | | // We don't support modify DN operations in the server configuration, but |
| | | // at least we need to make sure we're getting past the privilege check. |
| | | assertEquals(modifyDNOperation.getResultCode(), |
| | | ResultCode.UNWILLING_TO_PERFORM); |
| | | } |
| | | else |
| | | { |
| | | assertEquals(modifyDNOperation.getResultCode(), |
| | | ResultCode.INSUFFICIENT_ACCESS_RIGHTS); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Tests to ensure that attempts to update the schema with a modify operation |
| | | * will properly respect the UPDATE_SCHEMA privilege. |
| | | * |
| | | * @param conn The client connection to use to perform the schema |
| | | * update. |
| | | * @param hasPrivilege Indicates whether the authenticated user is expected |
| | | * to have the UPDATE_SCHEMA privilege and therefore |
| | | * the schema update should succeed. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test(dataProvider = "testdata") |
| | | public void testUpdateSchemaModify(JmxClientConnection conn, |
| | | boolean hasPrivilege) |
| | | throws Exception |
| | | { |
| | | assertEquals(conn.hasPrivilege(Privilege.JMX_WRITE, null), |
| | | hasPrivilege); |
| | | |
| | | String attrDefinition = |
| | | "( testupdateschemaat-oid NAME 'testUpdateSchemaAT' " + |
| | | "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE " + |
| | | "X-ORIGIN 'PrivilegeTestCase' )"; |
| | | |
| | | ArrayList<Modification> mods = new ArrayList<Modification>(); |
| | | |
| | | mods.add(new Modification(ModificationType.ADD, |
| | | Attributes.create("attributetypes", attrDefinition))); |
| | | |
| | | ModifyOperation modifyOperation = |
| | | conn.processModify(DN.valueOf("cn=schema"), mods); |
| | | if (hasPrivilege) |
| | | { |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | mods.clear(); |
| | | mods.add(new Modification(ModificationType.DELETE, |
| | | Attributes.create("attributetypes", attrDefinition))); |
| | | |
| | | modifyOperation = conn.processModify(DN.valueOf("cn=schema"), mods); |
| | | assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS); |
| | | } |
| | | else |
| | | { |
| | | assertEquals(modifyOperation.getResultCode(), |
| | | ResultCode.INSUFFICIENT_ACCESS_RIGHTS); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests to ensure that attempts to update the schema with an add schema file |
| | | * task will properly respect the UPDATE_SCHEMA privilege. |
| | |
| | | } |
| | | writer.close(); |
| | | |
| | | Entry taskEntry = TestCaseUtils.makeEntry( |
| | | "dn: ds-task-id=" + UUID.randomUUID() + ",cn=Scheduled Tasks,cn=Tasks", |
| | | "objectClass: top", |
| | | "objectClass: ds-task", |
| | | "objectClass: ds-task-add-schema-file", |
| | | "ds-task-class-name: org.opends.server.tasks.AddSchemaFileTask", |
| | | "ds-task-schema-file-name: 05-" + identifier + ".ldif"); |
| | | |
| | | AddOperation addOperation = |
| | | conn.processAdd(taskEntry.getName(), taskEntry.getObjectClasses(), |
| | | taskEntry.getUserAttributes(), |
| | | taskEntry.getOperationalAttributes()); |
| | | |
| | | if (hasPrivilege) |
| | | { |
| | | assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | Task task = getCompletedTask(taskEntry.getName()); |
| | | assertNotNull(task); |
| | | assertTrue(TaskState.isSuccessful(task.getTaskState())); |
| | | } |
| | | else |
| | | { |
| | | assertEquals(addOperation.getResultCode(), |
| | | ResultCode.INSUFFICIENT_ACCESS_RIGHTS); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests to ensure that attempts to backup the Directory Server backends |
| | | * will properly respect the BACKEND_BACKUP privilege. |
| | | * |
| | | * @param conn The client connection to use to perform the backup. |
| | | * @param hasPrivilege Indicates whether the authenticated user is expected |
| | | * to have the BACKEND_BACKUP privilege and therefore |
| | | * the backup should succeed. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test(dataProvider = "testdata", groups = { "slow" }) |
| | | public void testBackupBackend(JmxClientConnection conn, |
| | | boolean hasPrivilege) |
| | | throws Exception |
| | | { |
| | | // We have to sleep here because the backup ID that gets generated will be |
| | | // based on a timestamp and we don't want two in the same second. |
| | | Thread.sleep(1100); |
| | | |
| | | assertEquals(conn.hasPrivilege(Privilege.JMX_READ, null), |
| | | hasPrivilege); |
| | | |
| | | Entry taskEntry = TestCaseUtils.makeEntry( |
| | | "dn: ds-task-id=" + UUID.randomUUID() + ",cn=Scheduled Tasks,cn=Tasks", |
| | | "objectclass: top", |
| | | "objectclass: ds-task", |
| | | "objectclass: ds-task-backup", |
| | | "ds-task-class-name: org.opends.server.tasks.BackupTask", |
| | | "ds-backup-directory-path: bak", |
| | | "ds-task-backup-all: TRUE"); |
| | | |
| | | AddOperation addOperation = |
| | | conn.processAdd(taskEntry.getName(), taskEntry.getObjectClasses(), |
| | | taskEntry.getUserAttributes(), |
| | | taskEntry.getOperationalAttributes()); |
| | | |
| | | if (hasPrivilege) |
| | | { |
| | | assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | Task task = getCompletedTask(taskEntry.getName()); |
| | | assertNotNull(task); |
| | | assertTrue(TaskState.isSuccessful(task.getTaskState())); |
| | | } |
| | | else |
| | | { |
| | | assertEquals(addOperation.getResultCode(), |
| | | ResultCode.INSUFFICIENT_ACCESS_RIGHTS); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests to ensure that attempts to restore the Directory Server backends |
| | | * will properly respect the BACKEND_RESTORE privilege. |
| | | * |
| | | * @param conn The client connection to use to perform the restore. |
| | | * @param hasPrivilege Indicates whether the authenticated user is expected |
| | | * to have the BACKEND_RESTORE privilege and therefore |
| | | * the restore should succeed. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test(enabled = false, dataProvider = "testdata", groups = { "slow" }, |
| | | dependsOnMethods = { "testBackupBackend" }) |
| | | public void testRestoreBackend(JmxClientConnection conn, |
| | | boolean hasPrivilege) |
| | | throws Exception |
| | | { |
| | | assertEquals(conn.hasPrivilege(Privilege.JMX_WRITE, null), |
| | | hasPrivilege); |
| | | |
| | | Entry taskEntry = TestCaseUtils.makeEntry( |
| | | "dn: ds-task-id=" + UUID.randomUUID() + ",cn=Scheduled Tasks,cn=Tasks", |
| | | "objectclass: top", |
| | | "objectclass: ds-task", |
| | | "objectclass: ds-task-restore", |
| | | "ds-task-class-name: org.opends.server.tasks.RestoreTask", |
| | | "ds-backup-directory-path: bak" + File.separator + "userRoot"); |
| | | |
| | | AddOperation addOperation = |
| | | conn.processAdd(taskEntry.getName(), taskEntry.getObjectClasses(), |
| | | taskEntry.getUserAttributes(), |
| | | taskEntry.getOperationalAttributes()); |
| | | |
| | | if (hasPrivilege) |
| | | { |
| | | assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | Task task = getCompletedTask(taskEntry.getName()); |
| | | assertNotNull(task); |
| | | assertTrue(TaskState.isSuccessful(task.getTaskState())); |
| | | } |
| | | else |
| | | { |
| | | assertEquals(addOperation.getResultCode(), |
| | | ResultCode.INSUFFICIENT_ACCESS_RIGHTS); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests to ensure that attempts to export the contents of a Directory Server |
| | | * backend will properly respect the LDIF_EXPORT privilege. |
| | | * |
| | | * @param conn The client connection to use to perform the export. |
| | | * @param hasPrivilege Indicates whether the authenticated user is expected |
| | | * to have the LDIF_EXPORT privilege and therefore |
| | | * the export should succeed. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test(dataProvider = "testdata", groups = { "slow" }) |
| | | public void testLDIFExport(JmxClientConnection conn, |
| | | boolean hasPrivilege) |
| | | throws Exception |
| | | { |
| | | assertEquals(conn.hasPrivilege(Privilege.JMX_READ, null), hasPrivilege); |
| | | |
| | | File tempFile = File.createTempFile("export-", ".ldif"); |
| | | String tempFilePath = tempFile.getAbsolutePath(); |
| | | tempFile.delete(); |
| | | |
| | | Entry taskEntry = TestCaseUtils.makeEntry( |
| | | "dn: ds-task-id=" + UUID.randomUUID() + ",cn=Scheduled Tasks,cn=Tasks", |
| | | "objectclass: top", |
| | | "objectclass: ds-task", |
| | | "objectclass: ds-task-export", |
| | | "ds-task-class-name: org.opends.server.tasks.ExportTask", |
| | | "ds-task-export-backend-id: userRoot", |
| | | "ds-task-export-ldif-file: " + tempFilePath); |
| | | |
| | | AddOperation addOperation = |
| | | conn.processAdd(taskEntry.getName(), taskEntry.getObjectClasses(), |
| | | taskEntry.getUserAttributes(), |
| | | taskEntry.getOperationalAttributes()); |
| | | |
| | | if (hasPrivilege) |
| | | { |
| | | assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | Task task = getCompletedTask(taskEntry.getName()); |
| | | assertNotNull(task); |
| | | assertTrue(TaskState.isSuccessful(task.getTaskState())); |
| | | |
| | | tempFile.delete(); |
| | | } |
| | | else |
| | | { |
| | | assertEquals(addOperation.getResultCode(), |
| | | ResultCode.INSUFFICIENT_ACCESS_RIGHTS); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests to ensure that attempts to import into a Directory Server backend |
| | | * will properly respect the LDIF_IMPORT privilege. |
| | | * |
| | | * @param conn The client connection to use to perform the import. |
| | | * @param hasPrivilege Indicates whether the authenticated user is expected |
| | | * to have the LDIF_IMPORT privilege and therefore |
| | | * the import should succeed. |
| | | * |
| | | * @throws Exception If an unexpected problem occurs. |
| | | */ |
| | | @Test(dataProvider = "testdata", groups = { "slow" }) |
| | | public void testLDIFImport(JmxClientConnection conn, |
| | | boolean hasPrivilege) |
| | | throws Exception |
| | | { |
| | | assertEquals(conn.hasPrivilege(Privilege.JMX_WRITE, null), hasPrivilege); |
| | | |
| | | String path = TestCaseUtils.createTempFile( |
| | | "dn: dc=example,dc=com", |
| | | "objectClass: top", |
| | | "objectClass: domain", |
| | | "dc: example"); |
| | | |
| | | Entry taskEntry = TestCaseUtils.makeEntry( |
| | | "dn: ds-task-id=" + UUID.randomUUID() + ",cn=Scheduled Tasks,cn=Tasks", |
| | | "objectclass: top", |
| | | "objectclass: ds-task", |
| | | "objectclass: ds-task-import", |
| | | "ds-task-class-name: org.opends.server.tasks.ImportTask", |
| | | "ds-task-import-backend-id: userRoot", |
| | | "ds-task-import-ldif-file: " + path); |
| | | |
| | | AddOperation addOperation = |
| | | conn.processAdd(taskEntry.getName(), taskEntry.getObjectClasses(), |
| | | taskEntry.getUserAttributes(), |
| | | taskEntry.getOperationalAttributes()); |
| | | |
| | | if (hasPrivilege) |
| | | { |
| | | assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | Task task = getCompletedTask(taskEntry.getName()); |
| | | assertNotNull(task); |
| | | assertTrue(TaskState.isSuccessful(task.getTaskState())); |
| | | } |
| | | else |
| | | { |
| | | assertEquals(addOperation.getResultCode(), |
| | | ResultCode.INSUFFICIENT_ACCESS_RIGHTS); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Test to ensure that attempts to rebuild indexes will property respect |
| | | * the LDIF_IMPORT privilege. |
| | | * |
| | | * @param conn The client connection to use to perform the rebuild. |
| | | * @param hasPrivilege Indicates weather the authenticated user is |
| | | * expected to have the INDEX_REBUILD privilege |
| | | * and therefore the rebuild should succeed. |
| | | * @throws Exception if an unexpected problem occurs. |
| | | */ |
| | | @Test(dataProvider = "testdata", groups = { "slow" }) |
| | | public void testRebuildIndex(JmxClientConnection conn, |
| | | boolean hasPrivilege) |
| | | throws Exception |
| | | { |
| | | assertEquals(conn.hasPrivilege(Privilege.JMX_WRITE, null), hasPrivilege); |
| | | |
| | | Entry taskEntry = TestCaseUtils.makeEntry( |
| | | "dn: ds-task-id=" + UUID.randomUUID() + ",cn=Scheduled Tasks,cn=Tasks", |
| | | "objectclass: top", |
| | | "objectclass: ds-task", |
| | | "objectclass: ds-task-rebuild", |
| | | "ds-task-class-name: org.opends.server.tasks.RebuildTask", |
| | | "ds-task-rebuild-base-dn: dc=example,dc=com", |
| | | "ds-task-rebuild-index: cn"); |
| | | |
| | | AddOperation addOperation = |
| | | conn.processAdd(taskEntry.getName(), taskEntry.getObjectClasses(), |
| | | taskEntry.getUserAttributes(), |
| | | taskEntry.getOperationalAttributes()); |
| | | |
| | | if (hasPrivilege) |
| | | { |
| | | assertEquals(addOperation.getResultCode(), ResultCode.SUCCESS); |
| | | |
| | | Task task = getCompletedTask(taskEntry.getName()); |
| | | assertNotNull(task); |
| | | assertTrue(TaskState.isSuccessful(task.getTaskState())); |
| | | } |
| | | else |
| | | { |
| | | assertEquals(addOperation.getResultCode(), |
| | | ResultCode.INSUFFICIENT_ACCESS_RIGHTS); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Tests to ensure that the use of the Directory Server will properly respect |