Search in sources :

Example 11 with SysSystemFilter

use of eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter in project CzechIdMng by bcvsolutions.

the class VsSystemGeneratorTaskExecutorIntegrationTest method generate10Sys10Role1User.

@Test
public void generate10Sys10Role1User() {
    final String TEST_PREFIX = "testPrefix2";
    VsSystemGeneratorTaskExecutor taskExecutor = new VsSystemGeneratorTaskExecutor();
    AutowireHelper.autowire(taskExecutor);
    Map<String, Object> properties = new HashMap<>();
    properties.put(VsSystemGeneratorTaskExecutor.IDNENTITY_COUNT, 1);
    properties.put(VsSystemGeneratorTaskExecutor.ROLE_COUNT, 10);
    properties.put(VsSystemGeneratorTaskExecutor.SYSTEM_COUNT, 10);
    properties.put(VsSystemGeneratorTaskExecutor.ITEM_PREFIX_KEY, TEST_PREFIX);
    taskExecutor.init(properties);
    longRunningTaskManager.execute(taskExecutor);
    // expected number of identities was created
    IdmIdentityFilter identityFilt = new IdmIdentityFilter();
    identityFilt.setText(TEST_PREFIX);
    List<IdmIdentityDto> identities = identityService.find(identityFilt, null).getContent();
    Assert.assertEquals(1, identities.size());
    // expected number of roles was created
    IdmRoleFilter roleFilt = new IdmRoleFilter();
    roleFilt.setText(TEST_PREFIX);
    List<IdmRoleDto> roles = roleService.find(roleFilt, null).getContent();
    Set<UUID> roleIds = roles.stream().map(IdmRoleDto::getId).collect(Collectors.toSet());
    Assert.assertEquals(10, roles.size());
    // expected number of systems was created
    SysSystemFilter systemFilt = new SysSystemFilter();
    systemFilt.setText(TEST_PREFIX);
    List<SysSystemDto> systems = systemService.find(systemFilt, null).getContent();
    Set<UUID> sysIds = systems.stream().map(SysSystemDto::getId).collect(Collectors.toSet());
    Assert.assertEquals(10, systems.size());
    // systems are connected with roles
    Set<UUID> sysIdForRoles = new HashSet<UUID>();
    SysRoleSystemFilter roleSystemFilt = new SysRoleSystemFilter();
    for (IdmRoleDto role : roles) {
        roleSystemFilt.setRoleId(role.getId());
        List<SysRoleSystemDto> roleSystems = roleSystemService.find(roleSystemFilt, null).getContent();
        Assert.assertEquals(1, roleSystems.size());
        sysIdForRoles.add(roleSystems.get(0).getSystem());
    }
    Assert.assertTrue(Objects.equals(sysIds, sysIdForRoles));
    // roles are connected with identities
    Set<UUID> roleIdForIdentity = identityRoleService.findAllByIdentity(identities.get(0).getId()).stream().map(IdmIdentityRoleDto::getRole).collect(Collectors.toSet());
    Assert.assertTrue(Objects.equals(roleIdForIdentity, roleIds));
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter) HashMap(java.util.HashMap) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysRoleSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemFilter) IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) HashSet(java.util.HashSet) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 12 with SysSystemFilter

use of eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter in project CzechIdMng by bcvsolutions.

the class VsSystemGeneratorTaskExecutorIntegrationTest method generate10Sys1Role1User.

@Test
public void generate10Sys1Role1User() {
    final String TEST_PREFIX = "testPrefix1";
    VsSystemGeneratorTaskExecutor taskExecutor = new VsSystemGeneratorTaskExecutor();
    AutowireHelper.autowire(taskExecutor);
    Map<String, Object> properties = new HashMap<>();
    properties.put(VsSystemGeneratorTaskExecutor.IDNENTITY_COUNT, 1);
    properties.put(VsSystemGeneratorTaskExecutor.ROLE_COUNT, 1);
    properties.put(VsSystemGeneratorTaskExecutor.SYSTEM_COUNT, 10);
    properties.put(VsSystemGeneratorTaskExecutor.ITEM_PREFIX_KEY, TEST_PREFIX);
    taskExecutor.init(properties);
    longRunningTaskManager.execute(taskExecutor);
    // expected number of identities was created
    IdmIdentityFilter identityFilt = new IdmIdentityFilter();
    identityFilt.setText(TEST_PREFIX);
    List<IdmIdentityDto> identities = identityService.find(identityFilt, null).getContent();
    Assert.assertEquals(1, identities.size());
    // expected number of roles was created
    IdmRoleFilter roleFilt = new IdmRoleFilter();
    roleFilt.setText(TEST_PREFIX);
    List<IdmRoleDto> roles = roleService.find(roleFilt, null).getContent();
    Set<UUID> roleIds = roles.stream().map(IdmRoleDto::getId).collect(Collectors.toSet());
    Assert.assertEquals(1, roles.size());
    // expected number of systems was created
    SysSystemFilter systemFilt = new SysSystemFilter();
    systemFilt.setText(TEST_PREFIX);
    List<SysSystemDto> systems = systemService.find(systemFilt, null).getContent();
    Set<UUID> sysIds = systems.stream().map(SysSystemDto::getId).collect(Collectors.toSet());
    Assert.assertEquals(10, systems.size());
    // systems are connected with roles
    SysRoleSystemFilter roleSystemFilt = new SysRoleSystemFilter();
    roleSystemFilt.setRoleId(roles.get(0).getId());
    List<SysRoleSystemDto> roleSystems = roleSystemService.find(roleSystemFilt, null).getContent();
    Set<UUID> sysIdForRoles = roleSystems.stream().map(SysRoleSystemDto::getSystem).collect(Collectors.toSet());
    Assert.assertTrue(Objects.equals(sysIds, sysIdForRoles));
    // roles are connected with identities
    Set<UUID> roleIdForIdentity = identityRoleService.findAllByIdentity(identities.get(0).getId()).stream().map(IdmIdentityRoleDto::getRole).collect(Collectors.toSet());
    Assert.assertTrue(Objects.equals(roleIdForIdentity, roleIds));
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter) HashMap(java.util.HashMap) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysRoleSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemFilter) IdmRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 13 with SysSystemFilter

use of eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter in project CzechIdMng by bcvsolutions.

the class PasswordPolicyDeleteProcessor method process.

@Override
public EventResult<IdmPasswordPolicyDto> process(EntityEvent<IdmPasswordPolicyDto> event) {
    // cascade set to null all references in sysSystem to remove password policy
    IdmPasswordPolicyDto dto = event.getContent();
    Assert.notNull(dto.getId(), "Password policy identifier is required.");
    // remove references to password policy
    SysSystemFilter filter = new SysSystemFilter();
    filter.setPasswordPolicyGenerationId(dto.getId());
    systemService.find(filter, null).forEach(system -> {
        system.setPasswordPolicyGenerate(null);
        systemService.save(system);
    });
    filter.setPasswordPolicyGenerationId(null);
    filter.setPasswordPolicyValidationId(dto.getId());
    systemService.find(filter, null).forEach(system -> {
        system.setPasswordPolicyValidate(null);
        systemService.save(system);
    });
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) SysSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult)

Example 14 with SysSystemFilter

use of eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter in project CzechIdMng by bcvsolutions.

the class RemoteServerSaveProcessor method process.

@Override
public EventResult<SysConnectorServerDto> process(EntityEvent<SysConnectorServerDto> event) {
    SysConnectorServerDto dto = event.getContent();
    GuardedString password = dto.getPassword();
    SysConnectorServerDto remoteServer = service.saveInternal(dto);
    // save password from remote connector server to confidential storage
    if (password != null) {
        // save for newSystem
        confidentialStorage.save(remoteServer.getId(), SysRemoteServer.class, SysSystemService.REMOTE_SERVER_PASSWORD, password.asString());
        // 
        // set asterisks
        remoteServer.setPassword(new GuardedString(GuardedString.SECRED_PROXY_STRING));
    }
    // 
    // update all systems => we need to be backward compatible (see SysSystemDto.getConnectorInstance() + password is loaded direcly from confidential storage for systems)
    SysSystemFilter systemFilter = new SysSystemFilter();
    systemFilter.setRemoteServerId(remoteServer.getId());
    systemService.find(systemFilter, null).forEach(system -> {
        SysConnectorServerDto connectorServer = new SysConnectorServerDto(remoteServer);
        // usable password
        connectorServer.setPassword(password);
        // 
        system.setConnectorServer(connectorServer);
        systemService.save(system);
    });
    // 
    event.setContent(remoteServer);
    return new DefaultEventResult<>(event, this);
}
Also used : SysSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto)

Example 15 with SysSystemFilter

use of eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter in project CzechIdMng by bcvsolutions.

the class RemoteServerDeleteProcessor method process.

@Override
public EventResult<SysConnectorServerDto> process(EntityEvent<SysConnectorServerDto> event) {
    SysConnectorServerDto remoteServer = event.getContent();
    UUID remoteServerId = remoteServer.getId();
    Assert.notNull(remoteServerId, "Remove server identifier is required.");
    // 
    // Check system not exists
    SysSystemFilter systemFilter = new SysSystemFilter();
    systemFilter.setRemoteServerId(remoteServerId);
    if (systemService.count(systemFilter) > 0) {
        throw new ResultCodeException(AccResultCode.REMOTE_SYSTEM_DELETE_FAILED_HAS_SYSTEMS, ImmutableMap.of("remoteServer", remoteServer.getFullServerName()));
    }
    // 
    // deletes all confidential values
    confidentialStorage.deleteAll(remoteServerId, SysRemoteServer.class);
    // 
    // deletes server
    service.deleteInternal(remoteServer);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : SysSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto) UUID(java.util.UUID)

Aggregations

SysSystemFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter)18 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)11 Test (org.junit.Test)10 SysConnectorServerDto (eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto)8 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)7 UUID (java.util.UUID)7 IdmPasswordPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto)6 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)6 SysSystem (eu.bcvsolutions.idm.acc.entity.SysSystem)5 SysRemoteServerService (eu.bcvsolutions.idm.acc.service.api.SysRemoteServerService)5 SysSystemService (eu.bcvsolutions.idm.acc.service.api.SysSystemService)5 ConfidentialStorage (eu.bcvsolutions.idm.core.api.service.ConfidentialStorage)5 List (java.util.List)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)4 Assert (org.junit.Assert)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 IdmPasswordPolicyGenerateType (eu.bcvsolutions.idm.core.api.domain.IdmPasswordPolicyGenerateType)3 IdmPasswordPolicyType (eu.bcvsolutions.idm.core.api.domain.IdmPasswordPolicyType)3 AbstractReadWriteDtoController (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController)3