Search in sources :

Example 26 with IdmExportImportDto

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmExportImportDto(eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractExportBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractExportBulkActionTest) Test(org.junit.Test)

Example 27 with IdmExportImportDto

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());
}
Also used : IdmExportImportDto(eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncConfigDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractExportBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractExportBulkActionTest) Test(org.junit.Test)

Example 28 with IdmExportImportDto

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);
    }
}
Also used : IdmExportImportDto(eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto) InputStream(java.io.InputStream) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmExportImportService(eu.bcvsolutions.idm.core.api.service.IdmExportImportService) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IOException(java.io.IOException) InputStreamResource(org.springframework.core.io.InputStreamResource) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 29 with IdmExportImportDto

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()));
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmExportImportDto(eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto) IdmRoleCatalogueRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCatalogueRoleDto) IdmRoleCatalogueDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCatalogueDto) AbstractExportBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractExportBulkActionTest) Test(org.junit.Test)

Example 30 with IdmExportImportDto

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmExportImportDto(eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto) IdmIncompatibleRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIncompatibleRoleDto) AbstractExportBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractExportBulkActionTest) Test(org.junit.Test)

Aggregations

IdmExportImportDto (eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto)31 AbstractExportBulkActionTest (eu.bcvsolutions.idm.test.api.AbstractExportBulkActionTest)18 Test (org.junit.Test)18 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)14 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)8 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)7 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)5 SysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncConfigDto)4 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)4 IdmAttachmentDto (eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto)4 SysProvisioningBreakConfigDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakConfigDto)3 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)3 Path (java.nio.file.Path)3 Transactional (org.springframework.transaction.annotation.Transactional)3 SysProvisioningBreakRecipientDto (eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakRecipientDto)2 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)2 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)2 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)2 ImportContext (eu.bcvsolutions.idm.core.api.dto.ImportContext)2 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)2