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());
}
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());
}
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);
}
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())));
}
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())));
}
Aggregations