Search in sources :

Example 6 with SysSystemFilter

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

the class DefaultSysSystemServiceFilterTest method testSystemPasswordPolicyValidationId.

@Test
public void testSystemPasswordPolicyValidationId() {
    SysSystemDto system1 = createSystem("test001" + System.currentTimeMillis(), null);
    createSystem("test002" + System.currentTimeMillis(), null);
    SysSystemFilter testFilter = new SysSystemFilter();
    IdmPasswordPolicyDto policy = createPasswordPolicy("first", IdmPasswordPolicyType.VALIDATE);
    system1.setPasswordPolicyValidate(policy.getId());
    system1 = systemService.save(system1);
    testFilter.setPasswordPolicyValidationId(policy.getId());
    // 
    Page<SysSystemDto> pages = systemService.find(testFilter, null);
    assertEquals(1, pages.getTotalElements());
    assertEquals(system1.getId(), pages.getContent().get(0).getId());
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) SysSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 7 with SysSystemFilter

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

the class DefaultSysSystemServiceFilterTest method testSystemPasswordPolicyGenerationId.

@Test
public void testSystemPasswordPolicyGenerationId() {
    SysSystemDto system1 = createSystem("test01" + System.currentTimeMillis(), null);
    createSystem("test02" + System.currentTimeMillis(), null);
    SysSystemFilter testFilter = new SysSystemFilter();
    IdmPasswordPolicyDto policy = createPasswordPolicy("second", IdmPasswordPolicyType.GENERATE);
    system1.setPasswordPolicyGenerate(policy.getId());
    system1 = systemService.save(system1);
    testFilter.setPasswordPolicyGenerationId(policy.getId());
    // 
    Page<SysSystemDto> pages = systemService.find(testFilter, null);
    assertEquals(1, pages.getTotalElements());
    assertEquals(system1.getId(), pages.getContent().get(0).getId());
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) SysSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 8 with SysSystemFilter

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

the class AccInitRemoteServerProcessor method process.

@Override
public EventResult<ModuleDescriptorDto> process(EntityEvent<ModuleDescriptorDto> event) {
    // all remote systems => will be two at max
    List<SysConnectorServerDto> remoteServers = Lists.newArrayList(remoteServerService.find(null).getContent());
    // fill password
    remoteServers.forEach(remoteServer -> {
        remoteServer.setPassword(confidentialStorage.getGuardedString(remoteServer.getId(), SysRemoteServer.class, SysSystemService.REMOTE_SERVER_PASSWORD));
    });
    // 
    // find all systems with remote flag and empty related remoteServer
    SysSystemFilter systemFilter = new SysSystemFilter();
    systemFilter.setRemote(Boolean.TRUE);
    systemService.find(systemFilter, null).stream().filter(// remote server is not referenced => old definition with remote flag
    system -> Objects.isNull(system.getRemoteServer())).filter(system -> {
        // remote server is properly filled
        // cannot be filled from frontend, but just for sure
        SysConnectorServerDto connectorServer = system.getConnectorServer();
        if (connectorServer == null) {
            return false;
        }
        return StringUtils.isNotBlank(connectorServer.getHost());
    }).forEach(system -> {
        SysConnectorServerDto systemConnector = system.getConnectorServer();
        try {
            systemConnector.setPassword(confidentialStorage.getGuardedString(system.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD));
        } catch (SerializationException ex) {
            LOG.error("Password for configured system [{}] is broken, will be ignored.", system.getCode());
        }
        // try to find remote system by all fields
        SysConnectorServerDto remoteServer = remoteServers.stream().filter(r -> {
            return StringUtils.equals(r.getHost(), systemConnector.getHost()) && Integer.compare(r.getPort(), systemConnector.getPort()) == 0 && BooleanUtils.compare(r.isUseSsl(), systemConnector.isUseSsl()) == 0 && Integer.compare(r.getTimeout(), systemConnector.getTimeout()) == 0 && (// password is broken, e.g. when confidential storage was dropped
            systemConnector.getPassword() == null || StringUtils.equals(r.getPassword().asString(), systemConnector.getPassword().asString()));
        }).findFirst().orElse(null);
        // 
        if (remoteServer != null) {
            LOG.info("Remote server [{}] will be used for configured system [{}].", remoteServer.getFullServerName(), system.getCode());
            system.setRemoteServer(remoteServer.getId());
            systemService.save(system);
        } else {
            String systemCode = system.getCode();
            systemConnector.setDescription(String.format("Created automatically by upgrade to CzechIdM version 10.8.0 by target system [%s].", systemCode));
            GuardedString password = systemConnector.getPassword();
            remoteServer = remoteServerService.save(systemConnector);
            // preserve password
            remoteServer.setPassword(password);
            remoteServers.add(remoteServer);
            system.setRemoteServer(remoteServer.getId());
            systemService.save(system);
            LOG.info("New remote server [{}] was created and used for configured system [{}].", remoteServer.getFullServerName(), systemCode);
        }
    });
    // 
    // Turn off for next start => already processed
    getConfigurationService().setBooleanValue(getConfigurationPropertyName(ConfigurationService.PROPERTY_ENABLED), false);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : Description(org.springframework.context.annotation.Description) SysSystem(eu.bcvsolutions.idm.acc.entity.SysSystem) AbstractInitApplicationProcessor(eu.bcvsolutions.idm.core.api.event.processor.AbstractInitApplicationProcessor) SysSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) Autowired(org.springframework.beans.factory.annotation.Autowired) BooleanUtils(org.apache.commons.lang3.BooleanUtils) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) StringUtils(org.apache.commons.lang3.StringUtils) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto) SysRemoteServer(eu.bcvsolutions.idm.acc.entity.SysRemoteServer) Objects(java.util.Objects) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) List(java.util.List) Component(org.springframework.stereotype.Component) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) Lists(com.google.common.collect.Lists) SerializationException(org.apache.commons.lang3.SerializationException) SysRemoteServerService(eu.bcvsolutions.idm.acc.service.api.SysRemoteServerService) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) ModuleDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ModuleDescriptorDto) SysSystem(eu.bcvsolutions.idm.acc.entity.SysSystem) SerializationException(org.apache.commons.lang3.SerializationException) 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) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto) SysRemoteServer(eu.bcvsolutions.idm.acc.entity.SysRemoteServer)

Example 9 with SysSystemFilter

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

the class SysSystemControllerRestTest method testFindByPasswordPolicyValidation.

@Test
public void testFindByPasswordPolicyValidation() {
    SysSystemDto system = prepareDto();
    system.setPasswordPolicyValidate(createPasswordPolicy(IdmPasswordPolicyType.VALIDATE));
    system.setDescription(getHelper().createName());
    SysSystemDto systemOne = createDto(system);
    system = prepareDto();
    system.setPasswordPolicyValidate(createPasswordPolicy(IdmPasswordPolicyType.VALIDATE));
    system.setDescription(systemOne.getDescription());
    // mock
    createDto(system);
    // 
    SysSystemFilter filter = new SysSystemFilter();
    filter.setPasswordPolicyValidationId(systemOne.getPasswordPolicyValidate());
    filter.setText(system.getDescription());
    List<SysSystemDto> results = find(filter);
    Assert.assertEquals(1, results.size());
    Assert.assertTrue(results.stream().allMatch(r -> r.getId().equals(systemOne.getId())));
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) SysSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter) Autowired(org.springframework.beans.factory.annotation.Autowired) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) MockMvcResultMatchers.content(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) IdmPasswordPolicyGenerateType(eu.bcvsolutions.idm.core.api.domain.IdmPasswordPolicyGenerateType) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) SecurityMockMvcRequestPostProcessors.authentication(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) SysRemoteServerService(eu.bcvsolutions.idm.acc.service.api.SysRemoteServerService) SysSystem(eu.bcvsolutions.idm.acc.entity.SysSystem) IdmPasswordPolicyType(eu.bcvsolutions.idm.core.api.domain.IdmPasswordPolicyType) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) UUID(java.util.UUID) List(java.util.List) MockMvcRequestBuilders.get(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) IdmPasswordPolicyService(eu.bcvsolutions.idm.core.api.service.IdmPasswordPolicyService) SysSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) Test(org.junit.Test)

Example 10 with SysSystemFilter

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

the class SysSystemControllerRestTest method testFindByPasswordPolicyGeneration.

@Test
public void testFindByPasswordPolicyGeneration() {
    SysSystemDto system = prepareDto();
    system.setPasswordPolicyGenerate(createPasswordPolicy(IdmPasswordPolicyType.GENERATE));
    system.setDescription(getHelper().createName());
    SysSystemDto systemOne = createDto(system);
    system = prepareDto();
    system.setPasswordPolicyGenerate(createPasswordPolicy(IdmPasswordPolicyType.GENERATE));
    system.setDescription(systemOne.getDescription());
    // mock
    createDto(system);
    // 
    SysSystemFilter filter = new SysSystemFilter();
    filter.setPasswordPolicyGenerationId(systemOne.getPasswordPolicyGenerate());
    filter.setText(system.getDescription());
    List<SysSystemDto> results = find(filter);
    Assert.assertEquals(1, results.size());
    Assert.assertTrue(results.stream().allMatch(r -> r.getId().equals(systemOne.getId())));
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) SysSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter) Autowired(org.springframework.beans.factory.annotation.Autowired) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) MockMvcResultMatchers.content(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) IdmPasswordPolicyGenerateType(eu.bcvsolutions.idm.core.api.domain.IdmPasswordPolicyGenerateType) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) SecurityMockMvcRequestPostProcessors.authentication(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) SysRemoteServerService(eu.bcvsolutions.idm.acc.service.api.SysRemoteServerService) SysSystem(eu.bcvsolutions.idm.acc.entity.SysSystem) IdmPasswordPolicyType(eu.bcvsolutions.idm.core.api.domain.IdmPasswordPolicyType) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) UUID(java.util.UUID) List(java.util.List) MockMvcRequestBuilders.get(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) IdmPasswordPolicyService(eu.bcvsolutions.idm.core.api.service.IdmPasswordPolicyService) SysSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) Test(org.junit.Test)

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