use of eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto in project CzechIdMng by bcvsolutions.
the class SystemExportBulkActionIntegrationTest method testExportAndImportRoleSystemAdvancedPairing.
@Test
public void testExportAndImportRoleSystemAdvancedPairing() {
SysSystemDto system = createSystem();
IdmRoleDto originalRoleOne = getHelper().createRole();
IdmRoleDto originalRoleTwo = getHelper().createRole();
// Set default mapping to provisioning (for easy creation of role-system)
List<SysSystemMappingDto> mappings = findMappings(system);
Assert.assertEquals(1, mappings.size());
SysSystemMappingDto originalMapping = mappings.get(0);
originalMapping.setOperationType(SystemOperationType.PROVISIONING);
originalMapping = systemMappingService.save(originalMapping);
helper.createRoleSystem(originalRoleOne, system);
helper.createRoleSystem(originalRoleTwo, system);
// Make export, upload, delete system and import
IdmExportImportDto importBatch = executeExportAndImport(system, SystemExportBulkAction.NAME);
system = systemService.get(system.getId());
Assert.assertNotNull(system);
List<SysRoleSystemDto> roleSystems = findRoleSystems(system);
Assert.assertEquals(2, roleSystems.size());
// Delete original role and create new with same code.
roleService.delete(originalRoleOne);
IdmRoleDto newRoleOne = getHelper().createRole(originalRoleOne.getCode());
// Delete original roleTwo, for check optional relations feature (is set for
// role-system).
roleService.delete(originalRoleTwo);
// Execute import (check advanced pairing)
importBatch = importManager.executeImport(importBatch, false);
Assert.assertNotNull(importBatch);
Assert.assertEquals(ExportImportType.IMPORT, importBatch.getType());
Assert.assertEquals(OperationState.EXECUTED, importBatch.getResult().getState());
roleSystems = findRoleSystems(system);
Assert.assertEquals(1, roleSystems.size());
Assert.assertEquals(newRoleOne.getId(), roleSystems.get(0).getRole());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto in project CzechIdMng by bcvsolutions.
the class SystemExportBulkActionIntegrationTest method testExportAndImportNewSyncExcludedToken.
@Test
public void testExportAndImportNewSyncExcludedToken() {
SysSystemDto system = createSystem();
List<SysSystemMappingDto> mappings = findMappings(system);
Assert.assertEquals(1, mappings.size());
SysSystemMappingDto originalMapping = mappings.get(0);
List<SysSystemAttributeMappingDto> originalAttributes = findAttributeMappings(system);
SysSystemAttributeMappingDto originalAttribute = originalAttributes.get(0);
SysSyncConfigDto originalSync = new SysSyncConfigDto();
originalSync.setSystemMapping(originalMapping.getId());
originalSync.setName(getHelper().createName());
originalSync.setCorrelationAttribute(originalAttribute.getId());
originalSync.setToken(helper.createName());
originalSync = (SysSyncConfigDto) synchronizationConfigService.save(originalSync);
// Make export, upload, delete system and import
IdmExportImportDto importBatch = executeExportAndImport(system, SystemExportBulkAction.NAME);
system = systemService.get(system.getId());
Assert.assertNotNull(system);
systemService.delete(system);
system = systemService.get(system.getId());
Assert.assertNull(system);
// Execute import (check excluded token)
importBatch = importManager.executeImport(importBatch, false);
Assert.assertNotNull(importBatch);
Assert.assertEquals(ExportImportType.IMPORT, importBatch.getType());
Assert.assertEquals(OperationState.EXECUTED, importBatch.getResult().getState());
SysSyncConfigDto currentSync = (SysSyncConfigDto) synchronizationConfigService.get(originalSync.getId());
// Token was excluded. Value in current sync was not changed.
Assert.assertEquals(null, currentSync.getToken());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto in project CzechIdMng by bcvsolutions.
the class IdmExportImportController method download.
@ResponseBody
@RequestMapping(value = "/{backendId}/download", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.EXPORTIMPORT_READ + "')")
@ApiOperation(value = "Download export", nickname = "downloadExport", tags = { IdmExportImportController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.EXPORTIMPORT_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.EXPORTIMPORT_READ, description = "") }) })
public ResponseEntity<InputStreamResource> download(@ApiParam(value = "Batch's uuid identifier.", required = true) @PathVariable @NotNull String backendId) {
//
IdmExportImportDto batch = getDto(backendId);
if (batch == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
}
try {
// Batch read rights check was performed above (getDto).
InputStream is = ((IdmExportImportService) getService()).download(batch);
//
// Generate name of ZIP from batch name.
String zipName = batch.getExecutorName();
if (Strings.isNotEmpty(batch.getName())) {
String spinaledName = SpinalCase.format(batch.getName());
if (spinaledName.length() > 30) {
spinaledName = spinaledName.substring(0, 29);
}
zipName = MessageFormat.format("{0}.{1}", spinaledName, ExportManager.EXTENSION_ZIP);
}
return ResponseEntity.ok().contentLength(is.available()).contentType(MediaType.APPLICATION_OCTET_STREAM).header(HttpHeaders.CONTENT_DISPOSITION, String.format("attachment; filename=\"%s\"", zipName)).body(new InputStreamResource(is));
} catch (Exception ex) {
throw new ResultCodeException(CoreResultCode.INTERNAL_SERVER_ERROR, ex);
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto in project CzechIdMng by bcvsolutions.
the class RoleExportBulkActionIntegrationTest method testExportAndImportRoleCatalogue.
@Test
public void testExportAndImportRoleCatalogue() {
IdmRoleDto role = createRole();
IdmRoleCatalogueDto parentCatalogue = this.getHelper().createRoleCatalogue();
IdmRoleCatalogueDto catalogue = this.getHelper().createRoleCatalogue(getHelper().createName(), parentCatalogue.getId());
IdmRoleCatalogueDto notUseCatalogue = this.getHelper().createRoleCatalogue();
IdmRoleCatalogueRoleDto roleCatalogueRole = this.getHelper().createRoleCatalogueRole(role, catalogue);
// Make export, upload and import
IdmExportImportDto importBatch = executeExportAndImport(role, RoleExportBulkAction.NAME, ImmutableMap.of(EXECUTE_BEFORE_DTO_DELETE, this::deleteAllSubroles));
role = roleService.get(role.getId());
Assert.assertNotNull(role);
List<IdmRoleCatalogueRoleDto> roleCatalogues = this.findCatalogue(role);
Assert.assertEquals(1, roleCatalogues.size());
Assert.assertEquals(roleCatalogueRole.getId(), roleCatalogues.get(0).getId());
// Delete all catalogues (catalogue and parentCatalogue should be created again)
roleCatalogueService.delete(catalogue);
roleCatalogueService.delete(parentCatalogue);
roleCatalogueService.delete(notUseCatalogue);
IdmRoleCatalogueDto catalogueTwo = this.getHelper().createRoleCatalogue();
this.getHelper().createRoleCatalogueRole(role, catalogueTwo);
roleCatalogues = this.findCatalogue(role);
Assert.assertEquals(1, roleCatalogues.size());
// Execute import (check authoritative mode)
importBatch = importManager.executeImport(importBatch, false);
Assert.assertNotNull(importBatch);
Assert.assertEquals(ExportImportType.IMPORT, importBatch.getType());
Assert.assertEquals(OperationState.EXECUTED, importBatch.getResult().getState());
// Second policy had to be deleted!
roleCatalogues = this.findCatalogue(role);
Assert.assertEquals(1, roleCatalogues.size());
Assert.assertEquals(roleCatalogueRole.getId(), roleCatalogues.get(0).getId());
// Catalogue with parent had to be created.
Assert.assertNotNull(roleCatalogueService.get(catalogue.getId()));
Assert.assertNotNull(roleCatalogueService.get(parentCatalogue.getId()));
// Not using catalogue was not created.
Assert.assertNull(roleCatalogueService.get(notUseCatalogue.getId()));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto in project CzechIdMng by bcvsolutions.
the class RoleExportBulkActionIntegrationTest method testExportAndImportRoleIncompatibilities.
@Test
public void testExportAndImportRoleIncompatibilities() {
IdmRoleDto role = createRole();
IdmRoleDto incompatibileRoleOne = this.getHelper().createRole();
IdmRoleDto incompatibileRoleTwo = this.getHelper().createRole();
IdmIncompatibleRoleDto incompatibleRoleOne = this.getHelper().createIncompatibleRole(role, incompatibileRoleOne);
// Make export, upload and import
IdmExportImportDto importBatch = executeExportAndImport(role, RoleExportBulkAction.NAME, ImmutableMap.of(EXECUTE_BEFORE_DTO_DELETE, this::deleteAllSubroles));
role = roleService.get(role.getId());
Assert.assertNotNull(role);
List<IdmIncompatibleRoleDto> incompatibilites = this.findIncompatibilites(role);
Assert.assertEquals(1, incompatibilites.size());
Assert.assertEquals(incompatibleRoleOne.getId(), incompatibilites.get(0).getId());
this.getHelper().createIncompatibleRole(role, incompatibileRoleTwo);
incompatibilites = this.findIncompatibilites(role);
Assert.assertEquals(2, incompatibilites.size());
// Execute import (check authoritative mode)
importBatch = importManager.executeImport(importBatch, false);
Assert.assertNotNull(importBatch);
Assert.assertEquals(ExportImportType.IMPORT, importBatch.getType());
Assert.assertEquals(OperationState.EXECUTED, importBatch.getResult().getState());
// Second incompatibility had to be deleted!
incompatibilites = this.findIncompatibilites(role);
Assert.assertEquals(1, incompatibilites.size());
Assert.assertEquals(incompatibleRoleOne.getId(), incompatibilites.get(0).getId());
}
Aggregations