use of eu.bcvsolutions.idm.core.api.event.ModuleDescriptorEvent in project CzechIdMng by bcvsolutions.
the class DefaultModuleService method setEnabled.
@Override
public void setEnabled(String moduleId, boolean enabled) {
ModuleDescriptor moduleDescriptor = moduleDescriptorRegistry.getPluginFor(moduleId);
ModuleDescriptorDto moduleDescriptorDto = null;
if (moduleDescriptor == null) {
LOG.info("Frontend module [{}] will be enabled [{}].", moduleId, enabled);
// FE module - create basic descriptor
moduleDescriptorDto = new ModuleDescriptorDto(moduleId);
moduleDescriptorDto.setDisableable(true);
moduleDescriptorDto.setDisabled(!configurationService.getBooleanValue(getModuleConfigurationProperty(moduleId, ConfigurationService.PROPERTY_ENABLED), false));
} else {
LOG.info("Backend module [{}] will be enabled [{}].", moduleId, enabled);
//
moduleDescriptorDto = toDto(moduleDescriptor);
}
//
ModuleDescriptorEvent event = new ModuleDescriptorEvent(enabled ? ModuleDescriptorEventType.ENABLE : ModuleDescriptorEventType.DISABLE, moduleDescriptorDto);
entityEventManager.process(event);
}
use of eu.bcvsolutions.idm.core.api.event.ModuleDescriptorEvent in project CzechIdMng by bcvsolutions.
the class DefaultModuleServiceUnitTest method testIsDisableable.
@Test(expected = ModuleNotDisableableException.class)
public void testIsDisableable() {
ModuleDisableProcessor disableProcessor = new ModuleDisableProcessor();
ModuleDescriptorDto moduleDescriptor = new ModuleDescriptorDto(ModuleDescriptorOne.MODULE_ID);
moduleDescriptor.setDisableable(false);
//
disableProcessor.process(new ModuleDescriptorEvent(ModuleDescriptorEventType.DISABLE, moduleDescriptor));
}
use of eu.bcvsolutions.idm.core.api.event.ModuleDescriptorEvent in project CzechIdMng by bcvsolutions.
the class InitApplicationData method init.
protected void init() {
securityService.setSystemAuthentication();
//
LOG.info("Init application - start ...");
try {
//
// Cancels all previously ran events (before server is restarted).
// Init is called before new event is published => defined here (cannot be done in processor).
entityEventManager.init();
// start application by event
ModuleDescriptorEvent event = new ModuleDescriptorEvent(ModuleDescriptorEventType.INIT, new ModuleDescriptorDto(AppModule.MODULE_ID));
// publish event => all registered processors will be notified
entityEventManager.publishEvent(event);
//
LOG.info("Init application - complete.");
} finally {
securityService.logout();
}
}
use of eu.bcvsolutions.idm.core.api.event.ModuleDescriptorEvent in project CzechIdMng by bcvsolutions.
the class AccInitRemoteServerProcessorIntegrationTest method testInit.
@Test
public void testInit() {
String host = getHelper().createName();
String password = getHelper().createName();
String description = getHelper().createName();
//
SysConnectorServerDto remoteServer = new SysConnectorServerDto();
remoteServer.setHost(host);
remoteServer.setPassword(new GuardedString(password));
remoteServer.setPort(2);
remoteServer.setTimeout(2);
remoteServer.setUseSsl(true);
remoteServerService.save(remoteServer);
//
SysRemoteServerFilter filter = new SysRemoteServerFilter();
filter.setText(host);
List<SysConnectorServerDto> results = remoteServerService.find(filter, null).getContent();
Assert.assertEquals(1, results.size());
SysConnectorServerDto existRemoteServer = results.get(0);
//
// wee need to save system old way => repository is used
SysSystem system = new SysSystem();
system.setRemote(true);
system.setName(getHelper().createName());
system.setDescription(description);
system.setConnectorServer(new SysConnectorServer());
system.getConnectorServer().setHost(host);
system.getConnectorServer().setPassword(new GuardedString(password));
system.getConnectorServer().setPort(1);
system.getConnectorServer().setTimeout(2);
system.getConnectorServer().setUseSsl(true);
system.setBlockedOperation(new SysBlockedOperation());
SysSystemDto systemOne = systemService.get(systemRepository.save(system).getId());
confidentialStorage.saveGuardedString(systemOne.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD, new GuardedString(password));
//
system = new SysSystem();
system.setRemote(true);
system.setName(getHelper().createName());
system.setDescription(description);
system.setConnectorServer(new SysConnectorServer());
system.getConnectorServer().setHost(host);
system.getConnectorServer().setPassword(new GuardedString(password));
system.getConnectorServer().setPort(1);
system.getConnectorServer().setTimeout(2);
system.getConnectorServer().setUseSsl(true);
system.setBlockedOperation(new SysBlockedOperation());
SysSystemDto systemTwo = systemService.get(systemRepository.save(system).getId());
confidentialStorage.saveGuardedString(systemTwo.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD, new GuardedString(password));
//
system = new SysSystem();
system.setRemote(true);
system.setName(getHelper().createName());
system.setDescription(description);
system.setConnectorServer(new SysConnectorServer());
system.getConnectorServer().setHost(host);
String differentPassword = getHelper().createName();
// different password
system.getConnectorServer().setPassword(new GuardedString(differentPassword));
system.getConnectorServer().setPort(1);
system.getConnectorServer().setTimeout(2);
system.getConnectorServer().setUseSsl(true);
system.setBlockedOperation(new SysBlockedOperation());
SysSystemDto systemThree = systemService.get(systemRepository.save(system).getId());
confidentialStorage.saveGuardedString(systemThree.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD, new GuardedString(differentPassword));
//
system = new SysSystem();
system.setRemote(true);
system.setName(getHelper().createName());
system.setDescription(description);
system.setConnectorServer(new SysConnectorServer());
system.getConnectorServer().setHost(host);
system.getConnectorServer().setPassword(new GuardedString(password));
system.getConnectorServer().setPort(1);
system.getConnectorServer().setTimeout(2);
// useSsl - different
system.getConnectorServer().setUseSsl(false);
system.setBlockedOperation(new SysBlockedOperation());
SysSystemDto systemFour = systemService.get(systemRepository.save(system).getId());
confidentialStorage.saveGuardedString(systemFour.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD, new GuardedString(password));
//
system = new SysSystem();
system.setRemote(true);
system.setName(getHelper().createName());
system.setDescription(description);
system.setConnectorServer(new SysConnectorServer());
system.getConnectorServer().setHost(host);
system.getConnectorServer().setPassword(new GuardedString(password));
system.getConnectorServer().setPort(2);
system.getConnectorServer().setTimeout(2);
// useSsl - different
system.getConnectorServer().setUseSsl(true);
system.setBlockedOperation(new SysBlockedOperation());
SysSystemDto systemFive = systemService.get(systemRepository.save(system).getId());
confidentialStorage.saveGuardedString(systemFive.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD, new GuardedString(password));
//
SysSystemFilter systemFilter = new SysSystemFilter();
systemFilter.setText(description);
List<SysSystemDto> systems = systemService.find(systemFilter, null).getContent();
Assert.assertEquals(5, systems.size());
Assert.assertTrue(systems.stream().allMatch(s -> s.isRemote()));
Assert.assertTrue(systems.stream().allMatch(s -> s.getRemoteServer() == null));
//
// process migration
initProcessor.process(new ModuleDescriptorEvent(ModuleDescriptorEventType.INIT, new ModuleDescriptorDto(AccModuleDescriptor.MODULE_ID)));
//
systems = systemService.find(systemFilter, null).getContent();
Assert.assertTrue(systems.stream().allMatch(s -> s.isRemote()));
Assert.assertTrue(systems.stream().allMatch(s -> s.getRemoteServer() != null));
results = remoteServerService.find(filter, null).getContent();
Assert.assertEquals(4, results.size());
//
// one - two => same
systemOne = systemService.get(systemOne);
systemTwo = systemService.get(systemTwo);
Assert.assertEquals(systemOne.getRemoteServer(), systemTwo.getRemoteServer());
Assert.assertEquals(password, confidentialStorage.getGuardedString(systemOne.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD).asString());
Assert.assertEquals(password, confidentialStorage.getGuardedString(systemTwo.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD).asString());
Assert.assertEquals(password, remoteServerService.getPassword(systemTwo.getRemoteServer()).asString());
//
// three - different password
systemThree = systemService.get(systemThree);
Assert.assertEquals(differentPassword, confidentialStorage.getGuardedString(systemThree.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD).asString());
Assert.assertEquals(differentPassword, remoteServerService.getPassword(systemThree.getRemoteServer()).asString());
Assert.assertNotEquals(systemOne.getRemoteServer(), systemThree.getRemoteServer());
//
// four - different ssl
systemFour = systemService.get(systemFour);
Assert.assertEquals(password, confidentialStorage.getGuardedString(systemOne.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD).asString());
Assert.assertEquals(password, remoteServerService.getPassword(systemFour.getRemoteServer()).asString());
Assert.assertNotEquals(systemOne.getRemoteServer(), systemFour.getRemoteServer());
Assert.assertNotEquals(systemThree.getRemoteServer(), systemFour.getRemoteServer());
//
// five - exists
systemFive = systemService.get(systemFive);
Assert.assertEquals(existRemoteServer.getId(), systemFive.getRemoteServer());
}
Aggregations