Search in sources :

Example 1 with IdmScriptAuthorityDto

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

the class DefaultIdmScriptService method authorityTypeToDto.

/**
 * Generate list of authorities from {@ IdmScriptType}
 *
 * @param type
 * @return
 */
private List<IdmScriptAuthorityDto> authorityTypeToDto(IdmScriptType type, IdmScriptDto scriptDto) {
    List<IdmScriptAuthorityDto> authorities = new ArrayList<>();
    if (type.getAllowClasses() != null && type.getAllowClasses().getAllowClasses() != null) {
        for (IdmScriptAllowClassType allowClass : type.getAllowClasses().getAllowClasses()) {
            try {
                Class.forName(allowClass.getClassName());
            } catch (ClassNotFoundException e) {
                LOG.error("Class [{}] isn't reachable, for script [{}] skip add this authority", allowClass.getClassName(), type.getCode(), e);
                continue;
            }
            IdmScriptAuthorityDto authDto = new IdmScriptAuthorityDto();
            authDto.setType(ScriptAuthorityType.CLASS_NAME);
            authDto.setClassName(allowClass.getClassName());
            authDto.setScript(scriptDto.getId());
            authorities.add(authDto);
        }
    }
    // 
    if (type.getServices() != null && type.getServices().getServices() != null) {
        for (IdmScriptServiceType service : type.getServices().getServices()) {
            if (scriptAuthorityService.isServiceReachable(service.getName(), service.getClassName())) {
                IdmScriptAuthorityDto authDto = new IdmScriptAuthorityDto();
                authDto.setType(ScriptAuthorityType.SERVICE);
                authDto.setClassName(service.getClassName());
                authDto.setService(service.getName());
                authDto.setScript(scriptDto.getId());
                authorities.add(authDto);
            } else {
                LOG.error("Service [{}] [{}] isn't reachable, for script [{}] skip add this authority", service.getName(), service.getClassName(), type.getCode());
                continue;
            }
        }
    }
    // 
    return authorities;
}
Also used : IdmScriptAllowClassType(eu.bcvsolutions.idm.core.model.jaxb.IdmScriptAllowClassType) IdmScriptAuthorityDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto) IdmScriptServiceType(eu.bcvsolutions.idm.core.model.jaxb.IdmScriptServiceType) ArrayList(java.util.ArrayList)

Example 2 with IdmScriptAuthorityDto

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

the class ScriptEvaluatorTest method testRemoveScriptWithAuthentization.

@Test
public void testRemoveScriptWithAuthentization() {
    IdmScriptDto script = new IdmScriptDto();
    script.setCategory(IdmScriptCategory.DEFAULT);
    script.setCode("script_code_" + System.currentTimeMillis());
    script.setName("script_name_" + System.currentTimeMillis());
    // 
    script = scriptService.saveInternal(script);
    IdmScriptAuthorityDto auth = createAuthority(script.getId(), ScriptAuthorityType.CLASS_NAME, List.class.getName(), null);
    IdmScriptAuthorityDto auth2 = createAuthority(script.getId(), ScriptAuthorityType.CLASS_NAME, ArrayList.class.getName(), null);
    // 
    scriptService.deleteInternal(script);
    // 
    assertNull(scriptAuthorityService.get(auth.getId()));
    assertNull(scriptAuthorityService.get(auth2.getId()));
}
Also used : IdmScriptAuthorityDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto) IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 3 with IdmScriptAuthorityDto

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

the class ScriptEvaluatorTest method createAuthority.

/**
 * Method create and save {@link IdmScriptAuthority} for script id fiven in paramete
 * @param scriptId
 * @param type
 * @param className
 * @param service
 * @return
 */
private IdmScriptAuthorityDto createAuthority(UUID scriptId, ScriptAuthorityType type, String className, String service) {
    IdmScriptAuthorityDto auth = new IdmScriptAuthorityDto();
    auth.setClassName(className);
    auth.setType(type);
    auth.setScript(scriptId);
    if (type == ScriptAuthorityType.SERVICE) {
        auth.setService(service);
    }
    return scriptAuthorityService.saveInternal(auth);
}
Also used : IdmScriptAuthorityDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto)

Example 4 with IdmScriptAuthorityDto

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

the class DefaultIdmScriptServiceIntegrationTest method removeAuthRedeploy.

@Test
public void removeAuthRedeploy() {
    configurationService.setValue(Recoverable.BACKUP_FOLDER_CONFIG, TEST_BACKUP_FOLDER);
    IdmScriptDto script1 = scriptService.getByCode(TEST_SCRIPT_CODE_1);
    assertNotNull(script1);
    IdmScriptAuthorityFilter filter = new IdmScriptAuthorityFilter();
    filter.setScriptId(script1.getId());
    List<IdmScriptAuthorityDto> authorities = scriptAuthorityService.find(filter, null).getContent();
    assertEquals(4, authorities.size());
    scriptAuthorityService.deleteAllByScript(script1.getId());
    authorities = scriptAuthorityService.find(filter, null).getContent();
    assertEquals(0, authorities.size());
    scriptService.redeploy(script1);
    authorities = scriptAuthorityService.find(filter, null).getContent();
    assertEquals(4, 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)

Example 5 with IdmScriptAuthorityDto

use of eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto 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)

Aggregations

IdmScriptAuthorityDto (eu.bcvsolutions.idm.core.api.dto.IdmScriptAuthorityDto)10 IdmScriptDto (eu.bcvsolutions.idm.core.api.dto.IdmScriptDto)5 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 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 IdmScriptAllowClassType (eu.bcvsolutions.idm.core.model.jaxb.IdmScriptAllowClassType)2 IdmScriptServiceType (eu.bcvsolutions.idm.core.model.jaxb.IdmScriptServiceType)2 SysSyncIdentityConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto)1 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)1 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)1 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)1 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)1 SysSystemAttributeMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter)1 SysSystemMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter)1 DefaultSynchronizationServiceTest (eu.bcvsolutions.idm.acc.service.impl.DefaultSynchronizationServiceTest)1 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1