Search in sources :

Example 21 with SysConnectorServerDto

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());
}
Also used : GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) Test(org.junit.Test)

Example 22 with SysConnectorServerDto

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())));
}
Also used : Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) List(java.util.List) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) SecurityMockMvcRequestPostProcessors.authentication(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) SysRemoteServerFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRemoteServerFilter) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) MockMvcRequestBuilders.get(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) SysRemoteServerFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRemoteServerFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto) Test(org.junit.Test) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)

Example 23 with SysConnectorServerDto

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());
}
Also used : GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto) Test(org.junit.Test) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)

Example 24 with SysConnectorServerDto

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());
}
Also used : GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto) Test(org.junit.Test) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)

Example 25 with SysConnectorServerDto

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;
}
Also used : Set(java.util.Set) IcServerNotFoundException(eu.bcvsolutions.idm.ic.exception.IcServerNotFoundException) IcInvalidCredentialException(eu.bcvsolutions.idm.ic.exception.IcInvalidCredentialException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IcConnectorInfo(eu.bcvsolutions.idm.ic.api.IcConnectorInfo) IcConfigurationService(eu.bcvsolutions.idm.ic.service.api.IcConfigurationService) IcCantConnectException(eu.bcvsolutions.idm.ic.exception.IcCantConnectException) IcRemoteServerException(eu.bcvsolutions.idm.ic.exception.IcRemoteServerException) UUID(java.util.UUID) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto)

Aggregations

SysConnectorServerDto (eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto)25 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)13 Test (org.junit.Test)11 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)10 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)7 SysSystemFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter)6 SysSystem (eu.bcvsolutions.idm.acc.entity.SysSystem)6 UUID (java.util.UUID)6 AbstractReadWriteDtoControllerRestTest (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)5 IcCantConnectException (eu.bcvsolutions.idm.ic.exception.IcCantConnectException)5 IcInvalidCredentialException (eu.bcvsolutions.idm.ic.exception.IcInvalidCredentialException)5 IcRemoteServerException (eu.bcvsolutions.idm.ic.exception.IcRemoteServerException)5 IcServerNotFoundException (eu.bcvsolutions.idm.ic.exception.IcServerNotFoundException)5 IcConfigurationService (eu.bcvsolutions.idm.ic.service.api.IcConfigurationService)5 List (java.util.List)5 Set (java.util.Set)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 SysRemoteServerService (eu.bcvsolutions.idm.acc.service.api.SysRemoteServerService)4 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)4 HashMap (java.util.HashMap)4