use of eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto in project CzechIdMng by bcvsolutions.
the class SysSystemControllerRestTest method testGetRemoteServerPasswordContainsAsterisksByCode.
@Test
public void testGetRemoteServerPasswordContainsAsterisksByCode() 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.getCode())).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());
}
use of eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto in project CzechIdMng by bcvsolutions.
the class SysRemoteServerControllerRestTest method testFindByText.
@Test
public void testFindByText() {
String text = getHelper().createName();
SysConnectorServerDto remoteServer = prepareDto();
remoteServer.setHost(text);
remoteServer.setPassword(new GuardedString(getHelper().createName()));
remoteServer.setDescription(getHelper().createName());
SysConnectorServerDto remoteServerOne = createDto(remoteServer);
remoteServer = prepareDto();
remoteServer.setHost(getHelper().createName());
remoteServer.setPassword(new GuardedString(getHelper().createName()));
remoteServer.setDescription(text);
SysConnectorServerDto remoteServerTwo = createDto(remoteServer);
// other
createDto();
//
SysRemoteServerFilter filter = new SysRemoteServerFilter();
filter.setText(text);
List<SysConnectorServerDto> results = find(filter);
Assert.assertEquals(2, results.size());
Assert.assertTrue(results.stream().allMatch(r -> r.getPassword().asString().equals(GuardedString.SECRED_PROXY_STRING)));
Assert.assertTrue(results.stream().anyMatch(r -> r.getId().equals(remoteServerOne.getId())));
Assert.assertTrue(results.stream().anyMatch(r -> r.getId().equals(remoteServerTwo.getId())));
}
use of eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto in project CzechIdMng by bcvsolutions.
the class SysRemoteServerControllerRestTest method testGetConnectorFrameworks.
@Test
public void testGetConnectorFrameworks() throws Exception {
String text = getHelper().createName();
SysConnectorServerDto remoteServer = prepareDto();
remoteServer.setHost(text);
remoteServer.setPassword(new GuardedString(getHelper().createName()));
remoteServer.setDescription(getHelper().createName());
remoteServer = createDto(remoteServer);
//
// get connectors -> ends with exception => mock connection server
getMockMvc().perform(get(getDetailUrl(remoteServer.getId()) + "/frameworks").with(authentication(getAdminAuthentication())).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isBadRequest());
}
use of eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto in project CzechIdMng by bcvsolutions.
the class SysRemoteServerControllerRestTest method testGetConnectorTypes.
@Test
public void testGetConnectorTypes() throws Exception {
String text = getHelper().createName();
SysConnectorServerDto remoteServer = prepareDto();
remoteServer.setHost(text);
remoteServer.setPassword(new GuardedString(getHelper().createName()));
remoteServer.setDescription(getHelper().createName());
remoteServer = createDto(remoteServer);
//
// get connectors -> ends with exception => mock connection server
getMockMvc().perform(get(getDetailUrl(remoteServer.getId()) + "/connector-types").with(authentication(getAdminAuthentication())).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isBadRequest());
}
use of eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto in project CzechIdMng by bcvsolutions.
the class DefaultConnectorManager method findConnectorKey.
@Override
public IcConnectorKey findConnectorKey(ConnectorTypeDto connectorType) {
Assert.notNull(connectorType, "Connector type cannot be null!");
String connectorName = connectorType.getConnectorName();
Assert.notNull(connectorName, "Connector name cannot be null!");
UUID remoteServer = connectorType.getRemoteServer();
//
if (remoteServer == null) {
// local
Map<String, Set<IcConnectorInfo>> availableLocalConnectors = icConfiguration.getAvailableLocalConnectors();
if (availableLocalConnectors == null) {
return null;
}
List<IcConnectorInfo> connectorInfos = Lists.newArrayList();
for (Set<IcConnectorInfo> icConnectorInfos : availableLocalConnectors.values()) {
connectorInfos.addAll(icConnectorInfos);
}
IcConnectorInfo connectorInfo = connectorInfos.stream().filter(info -> connectorName.equals(info.getConnectorKey().getConnectorName())).findFirst().orElse(null);
return connectorInfo != null ? connectorInfo.getConnectorKey() : null;
}
// remote connector
try {
SysConnectorServerDto connectorServer = remoteServerService.get(remoteServer);
if (connectorServer == null) {
return null;
}
for (IcConfigurationService config : icConfiguration.getIcConfigs().values()) {
connectorServer.setPassword(remoteServerService.getPassword(connectorServer.getId()));
Set<IcConnectorInfo> availableRemoteConnectors = config.getAvailableRemoteConnectors(connectorServer);
if (CollectionUtils.isNotEmpty(availableRemoteConnectors)) {
IcConnectorInfo connectorInfo = availableRemoteConnectors.stream().filter(info -> connectorName.equals(info.getConnectorKey().getConnectorName())).findFirst().orElse(null);
if (connectorInfo != null) {
return connectorInfo.getConnectorKey();
}
}
}
} 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));
}
return null;
}
Aggregations