Search in sources :

Example 21 with IdmScriptDto

use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.

the class IdentitySyncTest method testSynchronizationCache.

@Test
public void testSynchronizationCache() {
    SysSystemDto system = initData();
    SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
    IdmRoleDto defaultRole = helper.createRole();
    // Set default role to sync configuration
    config.setDefaultRole(defaultRole.getId());
    config = (SysSyncIdentityConfigDto) syncConfigService.save(config);
    this.getBean().deleteAllResourceData();
    String testLastName = "test-last-name-same-" + System.currentTimeMillis();
    String testFirstName = "test-first-name";
    String userOne = "test-1-" + System.currentTimeMillis();
    this.getBean().setTestData(userOne, testFirstName, testLastName);
    String userTwo = "test-2-" + System.currentTimeMillis();
    this.getBean().setTestData(userTwo, testFirstName, testLastName);
    SysSystemMappingFilter mappingFilter = new SysSystemMappingFilter();
    mappingFilter.setEntityType(SystemEntityType.IDENTITY);
    mappingFilter.setSystemId(system.getId());
    mappingFilter.setOperationType(SystemOperationType.SYNCHRONIZATION);
    List<SysSystemMappingDto> mappings = systemMappingService.find(mappingFilter, null).getContent();
    Assert.assertEquals(1, mappings.size());
    SysSystemMappingDto defaultMapping = mappings.get(0);
    SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter();
    attributeMappingFilter.setSystemMappingId(defaultMapping.getId());
    List<SysSystemAttributeMappingDto> attributes = schemaAttributeMappingService.find(attributeMappingFilter, null).getContent();
    SysSystemAttributeMappingDto firstNameAttribute = attributes.stream().filter(attribute -> {
        return attribute.getIdmPropertyName().equals(IdmIdentity_.firstName.getName());
    }).findFirst().orElse(null);
    Assert.assertNotNull(firstNameAttribute);
    StringBuilder scriptGenerateUuid = new StringBuilder();
    scriptGenerateUuid.append("import java.util.UUID;");
    scriptGenerateUuid.append(System.lineSeparator());
    scriptGenerateUuid.append("return UUID.randomUUID();");
    String scriptName = "generateUuid";
    IdmScriptDto scriptUuid = new IdmScriptDto();
    scriptUuid.setCategory(IdmScriptCategory.TRANSFORM_FROM);
    scriptUuid.setCode(scriptName);
    scriptUuid.setName(scriptName);
    scriptUuid.setScript(scriptGenerateUuid.toString());
    scriptUuid = scriptService.save(scriptUuid);
    IdmScriptAuthorityDto scriptAuth = new IdmScriptAuthorityDto();
    scriptAuth.setClassName("java.util.UUID");
    scriptAuth.setType(ScriptAuthorityType.CLASS_NAME);
    scriptAuth.setScript(scriptUuid.getId());
    scriptAuth = scriptAuthrotityService.save(scriptAuth);
    // we must call script
    StringBuilder transformationScript = new StringBuilder();
    transformationScript.append("return scriptEvaluator.evaluate(");
    transformationScript.append(System.lineSeparator());
    transformationScript.append("scriptEvaluator.newBuilder()");
    transformationScript.append(System.lineSeparator());
    transformationScript.append(".setScriptCode('" + scriptName + "')");
    transformationScript.append(System.lineSeparator());
    transformationScript.append(".build());");
    transformationScript.append(System.lineSeparator());
    firstNameAttribute.setTransformFromResourceScript(transformationScript.toString());
    firstNameAttribute.setCached(true);
    firstNameAttribute = schemaAttributeMappingService.save(firstNameAttribute);
    synchornizationService.setSynchronizationConfigId(config.getId());
    synchornizationService.process();
    SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 2, OperationResultType.WARNING);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    IdmIdentityFilter filter = new IdmIdentityFilter();
    filter.setLastName(testLastName);
    List<IdmIdentityDto> identities = identityService.find(filter, null).getContent();
    assertEquals(2, identities.size());
    // 
    IdmIdentityDto identityOne = identities.get(0);
    IdmIdentityDto identityTwo = identities.get(1);
    // 
    assertNotEquals(identityOne.getFirstName(), identityTwo.getFirstName());
}
Also used : SysSyncIdentityConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) IdmScriptAuthorityDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSystemMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter) IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) DefaultSynchronizationServiceTest(eu.bcvsolutions.idm.acc.service.impl.DefaultSynchronizationServiceTest)

Example 22 with IdmScriptDto

use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.

the class IdmScriptController method redeploy.

@ResponseBody
@RequestMapping(value = "/{backendId}/redeploy", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.SCRIPT_READ + "')")
@ApiOperation(value = "Redeploy script", nickname = "redeployScript", response = IdmScriptDto.class, tags = { IdmScriptController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.SCRIPT_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.SCRIPT_READ, description = "") }) }, notes = "Redeploy script. Redeployed will be only scripts, that has pattern in resource." + " Before save newly loaded DO will be backup the old script into backup directory.")
public ResponseEntity<?> redeploy(@ApiParam(value = "Script's uuid identifier or code.", required = true) @PathVariable @NotNull String backendId) {
    IdmScriptDto script = service.get(backendId);
    if (script == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, backendId);
    }
    script = service.redeploy(script);
    return new ResponseEntity<>(toResource(script), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) 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 23 with IdmScriptDto

use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmScriptServiceIntegrationTest method deleteScriptRedeploy.

@Test
public void deleteScriptRedeploy() {
    IdmScriptDto script1 = scriptService.getByCode(TEST_SCRIPT_CODE_1);
    IdmScriptDto script2 = scriptService.getByCode(TEST_SCRIPT_CODE_2);
    assertNotNull(script1);
    assertNotNull(script2);
    scriptService.delete(script1);
    scriptService.delete(script2);
    script1 = scriptService.getByCode(TEST_SCRIPT_CODE_1);
    script2 = scriptService.getByCode(TEST_SCRIPT_CODE_2);
    assertNull(script1);
    assertNull(script2);
    scriptService.init();
    script1 = scriptService.getByCode(TEST_SCRIPT_CODE_1);
    script2 = scriptService.getByCode(TEST_SCRIPT_CODE_2);
    assertNotNull(script1);
    assertNotNull(script2);
}
Also used : IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 24 with IdmScriptDto

use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmScriptServiceIntegrationTest method backupMissingFolderExistEntity.

@Test
public void backupMissingFolderExistEntity() {
    configurationService.setValue(Recoverable.BACKUP_FOLDER_CONFIG, null);
    IdmScriptDto script1 = scriptService.getByCode(TEST_SCRIPT_CODE_1);
    assertNotNull(script1);
    try {
        scriptService.backup(script1);
        fail();
    } catch (ResultCodeException e) {
        ResultCodeException resultCode = (ResultCodeException) e;
        assertEquals(resultCode.getError().getError().getStatusEnum(), CoreResultCode.BACKUP_FOLDER_NOT_FOUND.name());
    }
}
Also used : IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 25 with IdmScriptDto

use of eu.bcvsolutions.idm.core.api.dto.IdmScriptDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmScriptServiceIntegrationTest method initTest.

@Test
public void initTest() {
    IdmScriptDto script1 = scriptService.getByCode(TEST_SCRIPT_CODE_1);
    IdmScriptDto script2 = scriptService.getByCode(TEST_SCRIPT_CODE_2);
    assertNotNull(script1);
    assertNotNull(script2);
    assertEquals(TEST_SCRIPT_CODE_1, script1.getCode());
    assertEquals(TEST_SCRIPT_CODE_2, script2.getCode());
    IdmScriptAuthorityFilter filter = new IdmScriptAuthorityFilter();
    filter.setScriptId(script1.getId());
    List<IdmScriptAuthorityDto> authorities = scriptAuthorityService.find(filter, null).getContent();
    assertEquals(4, authorities.size());
    filter.setScriptId(script2.getId());
    authorities = scriptAuthorityService.find(filter, null).getContent();
    assertEquals(0, authorities.size());
}
Also used : IdmScriptAuthorityDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto) IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) IdmScriptAuthorityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmScriptAuthorityFilter) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmScriptDto (eu.bcvsolutions.idm.core.api.dto.IdmScriptDto)39 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)34 Test (org.junit.Test)34 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)8 IdmScriptAuthorityDto (eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto)5 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)5 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)3 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)3 IdmRole (eu.bcvsolutions.idm.core.model.entity.IdmRole)3 HashMap (java.util.HashMap)3 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)2 IdmIdentityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter)2 IdmScriptAuthorityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmScriptAuthorityFilter)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ResponseEntity (org.springframework.http.ResponseEntity)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 SysSyncIdentityConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto)1 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)1