use of eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto in project CzechIdMng by bcvsolutions.
the class SysSystemController method getConnectorFormDefinition.
/**
* Returns definition for given system
* or throws exception with code {@code CONNECTOR_CONFIGURATION_FOR_SYSTEM_NOT_FOUND}, when system is wrong configured
*
* @param system
* @return
*/
private synchronized IdmFormDefinitionDto getConnectorFormDefinition(SysSystemDto system) {
Assert.notNull(system);
// connector key can't be null
if (system.getConnectorKey() == null) {
throw new ResultCodeException(AccResultCode.CONNECTOR_FORM_DEFINITION_NOT_FOUND, ImmutableMap.of("system", system.getId()));
}
// for remote connector form definition we need password for remote connector server
if (system.isRemote()) {
SysConnectorServerDto connectorServer = system.getConnectorServer();
connectorServer.setPassword(this.confidentialStorage.getGuardedString(system.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD));
system.setConnectorServer(connectorServer);
}
//
return systemService.getConnectorFormDefinition(system.getConnectorInstance());
}
use of eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto in project CzechIdMng by bcvsolutions.
the class SystemExportBulkActionIntegrationTest method testExportAndUseRemoteSystem.
@Test
public void testExportAndUseRemoteSystem() {
SysConnectorServerDto connectorServer = new SysConnectorServerDto();
String host = getHelper().createName();
connectorServer.setHost(host);
connectorServer.setPort(43);
String password = "password";
connectorServer.setPassword(new GuardedString(password));
connectorServer = remoteServerService.save(connectorServer);
SysSystemDto system = createSystem();
system.setRemoteServer(connectorServer.getId());
system = systemService.save(system);
Assert.assertFalse(system.isDisabled());
// Make export, upload, delete system and import
IdmExportImportDto importBatch = executeExportAndImport(system, SystemExportBulkAction.NAME);
system = systemService.get(system.getId());
Assert.assertNotNull(system);
Assert.assertNotNull(system.getRemoteServer());
Assert.assertTrue(system.isDisabled());
Assert.assertNotNull(system.getConnectorServer());
Assert.assertNotNull(system.getConnectorServer().getHost());
// Password is preserved from remote server
Assert.assertEquals(password, confidentialStorage.getGuardedString(system.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD).asString());
//
// get remote server
SysConnectorServerDto importedConnectorServer = remoteServerService.get(system.getRemoteServer());
Assert.assertEquals(connectorServer.getId(), importedConnectorServer.getId());
Assert.assertEquals(connectorServer.getHost(), importedConnectorServer.getHost());
Assert.assertEquals(connectorServer.getPort(), importedConnectorServer.getPort());
Assert.assertEquals(connectorServer.isUseSsl(), importedConnectorServer.isUseSsl());
Assert.assertEquals(connectorServer.getTimeout(), importedConnectorServer.getTimeout());
// Password is preserved
Assert.assertEquals(password, remoteServerService.getPassword(importedConnectorServer.getId()).asString());
// delete remote server and create new with the same setting => find by example
deleteRemoteServer(system);
//
connectorServer = new SysConnectorServerDto();
connectorServer.setHost(host);
connectorServer.setPort(43);
connectorServer.setPassword(new GuardedString(password));
connectorServer = remoteServerService.save(connectorServer);
// Execute import (check authoritative mode)
importBatch = importManager.executeImport(importBatch, false);
Assert.assertNotNull(importBatch);
Assert.assertEquals(ExportImportType.IMPORT, importBatch.getType());
Assert.assertEquals(OperationState.EXECUTED, importBatch.getResult().getState());
//
system = systemService.get(system);
importedConnectorServer = remoteServerService.get(system.getRemoteServer());
Assert.assertEquals(connectorServer.getId(), importedConnectorServer.getId());
Assert.assertEquals(connectorServer.getHost(), importedConnectorServer.getHost());
Assert.assertEquals(connectorServer.getPort(), importedConnectorServer.getPort());
Assert.assertEquals(connectorServer.isUseSsl(), importedConnectorServer.isUseSsl());
Assert.assertEquals(connectorServer.getTimeout(), importedConnectorServer.getTimeout());
// Password is preserved
Assert.assertEquals(password, confidentialStorage.getGuardedString(system.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD).asString());
Assert.assertEquals(password, remoteServerService.getPassword(importedConnectorServer.getId()).asString());
}
use of eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto 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());
}
use of eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto in project CzechIdMng by bcvsolutions.
the class SysSystemController method getSupportedTypes.
/**
* Returns all registered connector types.
*
* @return connector types
*/
@ResponseBody
@RequestMapping(method = RequestMethod.GET, value = "/search/supported")
@PreAuthorize("hasAuthority('" + AccGroupPermission.SYSTEM_READ + "')")
@ApiOperation(value = "Get all supported connector types", nickname = "getSupportedConnectorTypes", tags = { SysSystemController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = AccGroupPermission.SYSTEM_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = AccGroupPermission.SYSTEM_READ, description = "") }) })
public Resources<ConnectorTypeDto> getSupportedTypes() {
Map<SysConnectorServerDto, List<IcConnectorInfo>> allConnectorInfos = new LinkedHashMap<>();
// All remote connectors - optionally, but with higher priority.
remoteServerService.find(null).forEach(connectorServer -> {
for (IcConfigurationService config : icConfiguration.getIcConfigs().values()) {
try {
connectorServer.setPassword(remoteServerService.getPassword(connectorServer.getId()));
Set<IcConnectorInfo> availableRemoteConnectors = config.getAvailableRemoteConnectors(connectorServer);
if (CollectionUtils.isNotEmpty(availableRemoteConnectors)) {
allConnectorInfos.put(connectorServer, Lists.newArrayList(availableRemoteConnectors));
}
} catch (IcInvalidCredentialException e) {
ExceptionUtils.log(LOG, new ResultCodeException(AccResultCode.REMOTE_SERVER_INVALID_CREDENTIAL, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e));
} catch (IcServerNotFoundException e) {
ExceptionUtils.log(LOG, new ResultCodeException(AccResultCode.REMOTE_SERVER_NOT_FOUND, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e));
} catch (IcCantConnectException e) {
ExceptionUtils.log(LOG, new ResultCodeException(AccResultCode.REMOTE_SERVER_CANT_CONNECT, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e));
} catch (IcRemoteServerException e) {
ExceptionUtils.log(LOG, new ResultCodeException(AccResultCode.REMOTE_SERVER_UNEXPECTED_ERROR, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e));
}
}
});
// Local connectors
Map<String, Set<IcConnectorInfo>> availableLocalConnectors = icConfiguration.getAvailableLocalConnectors();
if (availableLocalConnectors != null) {
List<IcConnectorInfo> localConnectorInfos = Lists.newArrayList();
availableLocalConnectors.values().forEach(infos -> {
localConnectorInfos.addAll(infos);
});
SysConnectorServerDto localServer = new SysConnectorServerDto();
localServer.setLocal(true);
allConnectorInfos.put(localServer, localConnectorInfos);
}
//
List<ConnectorTypeDto> resolvedConnectorTypes = Lists.newArrayListWithExpectedSize(allConnectorInfos.values().stream().mapToInt(List::size).sum());
for (ConnectorType supportedConnectorType : connectorManager.getSupportedTypes()) {
// remote connector has higher priority => linked hash map => find first
// Find connector info and set version to the connectorTypeDto.
SysConnectorServerDto connectorServer = null;
IcConnectorInfo info = null;
for (Entry<SysConnectorServerDto, List<IcConnectorInfo>> entry : allConnectorInfos.entrySet()) {
for (IcConnectorInfo connectorInfo : entry.getValue()) {
if (supportedConnectorType.getConnectorName().equals(connectorInfo.getConnectorKey().getConnectorName())) {
connectorServer = entry.getKey();
info = connectorInfo;
break;
}
}
if (info != null) {
break;
}
}
if (info == null) {
// default connector types are resolved bellow
continue;
}
ConnectorTypeDto connectorType = connectorManager.convertTypeToDto(supportedConnectorType);
if (connectorServer != null) {
connectorType.setRemoteServer(connectorServer.getId());
}
connectorType.setLocal(connectorType.getRemoteServer() == null);
connectorType.setVersion(info.getConnectorKey().getBundleVersion());
connectorType.setName(info.getConnectorDisplayName());
resolvedConnectorTypes.add(connectorType);
}
// Find connectors without extension (specific connector type).
List<ConnectorTypeDto> defaultConnectorTypes = Lists.newArrayList();
for (Entry<SysConnectorServerDto, List<IcConnectorInfo>> entry : allConnectorInfos.entrySet()) {
SysConnectorServerDto connectorServer = entry.getKey();
for (IcConnectorInfo connectorInfo : entry.getValue()) {
ConnectorTypeDto connectorType = connectorManager.convertIcConnectorInfoToDto(connectorInfo);
if (!resolvedConnectorTypes.stream().anyMatch(supportedType -> supportedType.getConnectorName().equals(connectorType.getConnectorName()) && supportedType.isHideParentConnector())) {
if (connectorServer != null) {
connectorType.setRemoteServer(connectorServer.getId());
}
connectorType.setLocal(connectorType.getRemoteServer() == null);
defaultConnectorTypes.add(connectorType);
}
}
}
resolvedConnectorTypes.addAll(defaultConnectorTypes);
return new Resources<>(resolvedConnectorTypes.stream().sorted(Comparator.comparing(ConnectorTypeDto::getOrder)).collect(Collectors.toList()));
}
use of eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto in project CzechIdMng by bcvsolutions.
the class SysSystemControllerRestTest method testGetRemoteServerPasswordContainsAsterisks.
@Test
public void testGetRemoteServerPasswordContainsAsterisks() throws Exception {
String password = "testPassword123654";
SysConnectorServerDto conServer = new SysConnectorServerDto();
conServer.setPassword(new GuardedString(password));
conServer.setHost("localhost");
conServer = remoteServerService.save(conServer);
//
SysSystemDto system = prepareDto();
system.setRemoteServer(conServer.getId());
system = createDto(system);
ObjectMapper mapper = getMapper();
String response = getMockMvc().perform(get(getDetailUrl(system.getId())).with(authentication(getAdminAuthentication())).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isOk()).andExpect(content().contentType(TestHelper.HAL_CONTENT_TYPE)).andReturn().getResponse().getContentAsString();
SysSystemDto gotSystem = (SysSystemDto) mapper.readValue(response, SysSystemDto.class);
Assert.assertNotNull(gotSystem);
Assert.assertEquals(GuardedString.SECRED_PROXY_STRING, gotSystem.getConnectorServer().getPassword().asString());
//
// check password is set in both agendas
Assert.assertEquals(password, remoteServerService.getPassword(conServer.getId()).asString());
Assert.assertEquals(password, confidentialStorage.getGuardedString(gotSystem.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD).asString());
Assert.assertEquals(conServer.getHost(), gotSystem.getConnectorServer().getHost());
Assert.assertEquals(conServer.getPort(), gotSystem.getConnectorServer().getPort());
Assert.assertEquals(conServer.isUseSsl(), gotSystem.getConnectorServer().isUseSsl());
Assert.assertEquals(conServer.getTimeout(), gotSystem.getConnectorServer().getTimeout());
//
// change password on remote server
password = "testPassword123654Update";
conServer.setPassword(new GuardedString(password));
conServer = remoteServerService.save(conServer);
Assert.assertEquals(GuardedString.SECRED_PROXY_STRING, conServer.getPassword().asString());
Assert.assertEquals(password, remoteServerService.getPassword(conServer.getId()).asString());
Assert.assertEquals(password, confidentialStorage.getGuardedString(gotSystem.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD).asString());
//
// resave remote server without password is defined
conServer.setPassword(null);
conServer = remoteServerService.save(conServer);
Assert.assertEquals(password, remoteServerService.getPassword(conServer.getId()).asString());
Assert.assertEquals(password, confidentialStorage.getGuardedString(gotSystem.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD).asString());
}
Aggregations