use of eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto in project CzechIdMng by bcvsolutions.
the class SysRemoteServerController method getConnectorFrameworks.
/**
* Return available connector frameworks with connectors on remote connector server.
*/
@RequestMapping(method = RequestMethod.GET, value = "/{backendId}/frameworks")
@PreAuthorize("hasAuthority('" + AccGroupPermission.REMOTESERVER_READ + "')")
@ApiOperation(value = "Get available connectors", nickname = "getAvailableConnectors", tags = { SysRemoteServerController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = AccGroupPermission.REMOTESERVER_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = AccGroupPermission.REMOTESERVER_READ, description = "") }) }, notes = "Available connector frameworks with connectors on remote connector server.")
public ResponseEntity<Map<String, Set<IcConnectorInfo>>> getConnectorFrameworks(@ApiParam(value = "Remote server uuid identifier or code.", required = true) @PathVariable @NotNull String backendId) {
SysConnectorServerDto connectorServer = getDto(backendId);
if (connectorServer == null) {
throw new EntityNotFoundException(getService().getEntityClass(), backendId);
}
Map<String, Set<IcConnectorInfo>> infos = new HashMap<>();
//
try {
for (IcConfigurationService config : icConfiguration.getIcConfigs().values()) {
connectorServer.setPassword(remoteServerService.getPassword(connectorServer.getId()));
infos.put(config.getFramework(), config.getAvailableRemoteConnectors(connectorServer));
}
} catch (IcInvalidCredentialException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_INVALID_CREDENTIAL, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
} catch (IcServerNotFoundException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_NOT_FOUND, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
} catch (IcCantConnectException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_CANT_CONNECT, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
} catch (IcRemoteServerException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_UNEXPECTED_ERROR, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
}
//
return new ResponseEntity<Map<String, Set<IcConnectorInfo>>>(infos, HttpStatus.OK);
}
use of eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto in project CzechIdMng by bcvsolutions.
the class SysRemoteServerController method getConnectorTypes.
/**
* Returns connector types registered on given remote server.
*
* @return connector types
*/
@ResponseBody
@RequestMapping(method = RequestMethod.GET, value = "/{backendId}/connector-types")
@PreAuthorize("hasAuthority('" + AccGroupPermission.REMOTESERVER_READ + "')")
@ApiOperation(value = "Get supported connector types", nickname = "getConnectorTypes", tags = { SysRemoteServerController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = AccGroupPermission.REMOTESERVER_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = AccGroupPermission.REMOTESERVER_READ, description = "") }) })
public Resources<ConnectorTypeDto> getConnectorTypes(@ApiParam(value = "Remote server uuid identifier or code.", required = true) @PathVariable @NotNull String backendId) {
SysConnectorServerDto connectorServer = getDto(backendId);
if (connectorServer == null) {
throw new EntityNotFoundException(getService().getEntityClass(), backendId);
}
//
try {
List<IcConnectorInfo> connectorInfos = Lists.newArrayList();
for (IcConfigurationService config : icConfiguration.getIcConfigs().values()) {
connectorServer.setPassword(remoteServerService.getPassword(connectorServer.getId()));
Set<IcConnectorInfo> availableRemoteConnectors = config.getAvailableRemoteConnectors(connectorServer);
if (CollectionUtils.isNotEmpty(availableRemoteConnectors)) {
connectorInfos.addAll(availableRemoteConnectors);
}
}
// Find connector types for existing connectors.
List<ConnectorTypeDto> connectorTypes = connectorManager.getSupportedTypes().stream().filter(connectorType -> {
return connectorInfos.stream().anyMatch(connectorInfo -> connectorType.getConnectorName().equals(connectorInfo.getConnectorKey().getConnectorName()));
}).map(connectorType -> {
// Find connector info and set version to the connectorTypeDto.
IcConnectorInfo info = connectorInfos.stream().filter(connectorInfo -> connectorType.getConnectorName().equals(connectorInfo.getConnectorKey().getConnectorName())).findFirst().orElse(null);
ConnectorTypeDto connectorTypeDto = connectorManager.convertTypeToDto(connectorType);
connectorTypeDto.setLocal(true);
if (info != null) {
connectorTypeDto.setVersion(info.getConnectorKey().getBundleVersion());
connectorTypeDto.setName(info.getConnectorDisplayName());
}
return connectorTypeDto;
}).collect(Collectors.toList());
// Find connectors without extension (specific connector type).
List<ConnectorTypeDto> defaultConnectorTypes = connectorInfos.stream().map(info -> {
ConnectorTypeDto connectorTypeDto = connectorManager.convertIcConnectorInfoToDto(info);
connectorTypeDto.setLocal(true);
return connectorTypeDto;
}).filter(type -> {
return !connectorTypes.stream().anyMatch(supportedType -> supportedType.getConnectorName().equals(type.getConnectorName()) && supportedType.isHideParentConnector());
}).collect(Collectors.toList());
connectorTypes.addAll(defaultConnectorTypes);
return new Resources<>(connectorTypes.stream().sorted(Comparator.comparing(ConnectorTypeDto::getOrder)).collect(Collectors.toList()));
} catch (IcInvalidCredentialException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_INVALID_CREDENTIAL, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
} catch (IcServerNotFoundException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_NOT_FOUND, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
} catch (IcCantConnectException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_CANT_CONNECT, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
} catch (IcRemoteServerException e) {
throw new ResultCodeException(AccResultCode.REMOTE_SERVER_UNEXPECTED_ERROR, ImmutableMap.of("server", e.getHost() + ":" + e.getPort()), e);
}
}
use of eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto 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.SysConnectorServerDto in project CzechIdMng by bcvsolutions.
the class SystemSaveProcessor method process.
@Override
public EventResult<SysSystemDto> process(EntityEvent<SysSystemDto> event) {
SysSystemDto dto = event.getContent();
SysSystemDto previousSystem = event.getOriginalSource();
// resolve connector server
UUID remoteServerId = dto.getRemoteServer();
if (remoteServerId != null && (previousSystem == null || !remoteServerId.equals(previousSystem.getRemoteServer()))) {
// fill remote system to system connector server (backward compatibility)
SysConnectorServerDto remoteServer = lookupService.lookupEmbeddedDto(dto, SysSystemDto.PROPERTY_REMOTE_SERVER);
dto.setConnectorServer(new SysConnectorServerDto(remoteServer));
dto.getConnectorServer().setPassword(remoteServerService.getPassword(remoteServerId));
} else if (dto.getConnectorServer() == null) {
dto.setConnectorServer(new SysConnectorServerDto());
}
// create default connector key
if (dto.getConnectorKey() == null) {
dto.setConnectorKey(new SysConnectorKeyDto());
}
// create default blocked operations
if (dto.getBlockedOperation() == null) {
dto.setBlockedOperation(new SysBlockedOperationDto());
}
//
if (previousSystem != null) {
// Check if is connector changed
if (!dto.getConnectorKey().equals(previousSystem.getConnectorKey())) {
// If is connector changed, we set virtual to false. (Virtual
// connectors set this attribute on true by themselves)
dto.setVirtual(false);
}
// check blocked provisioning operation and clear provisioning break cache
clearProvisionignBreakCache(dto, previousSystem);
}
SysSystemDto newSystem = service.saveInternal(dto);
event.setContent(newSystem);
// save password from remote connector server to confidential storage
if (dto.getConnectorServer().getPassword() != null) {
// save for newSystem
confidentialStorage.save(newSystem.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD, dto.getConnectorServer().getPassword().asString());
//
// set asterix
newSystem.getConnectorServer().setPassword(new GuardedString(GuardedString.SECRED_PROXY_STRING));
}
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto in project CzechIdMng by bcvsolutions.
the class SysSystemControllerRestTest method testGetRemoteServerPasswordContainsAsterisksByUuidCode.
@Test
public void testGetRemoteServerPasswordContainsAsterisksByUuidCode() 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 name is UUID in string. For testing if will be used lookupService for get correct system.
String codeFromUUID = UUID.randomUUID().toString();
system.setName(codeFromUUID);
system.setRemoteServer(conServer.getId());
createDto(system);
ObjectMapper mapper = getMapper();
String response = getMockMvc().perform(get(getDetailUrl(codeFromUUID)).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());
}
Aggregations