Search in sources :

Example 16 with SysConnectorServerDto

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());
}
Also used : SysSystem(eu.bcvsolutions.idm.acc.entity.SysSystem) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto)

Example 17 with SysConnectorServerDto

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());
}
Also used : IdmExportImportDto(eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto) 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) AbstractExportBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractExportBulkActionTest) Test(org.junit.Test)

Example 18 with SysConnectorServerDto

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());
}
Also used : AccModuleDescriptor(eu.bcvsolutions.idm.acc.AccModuleDescriptor) SysSystem(eu.bcvsolutions.idm.acc.entity.SysSystem) SysConnectorServer(eu.bcvsolutions.idm.acc.entity.SysConnectorServer) SysSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSystemRepository(eu.bcvsolutions.idm.acc.repository.SysSystemRepository) ModuleDescriptorEvent(eu.bcvsolutions.idm.core.api.event.ModuleDescriptorEvent) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto) ModuleDescriptorEventType(eu.bcvsolutions.idm.core.api.event.ModuleDescriptorEvent.ModuleDescriptorEventType) List(java.util.List) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) SysRemoteServerFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRemoteServerFilter) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) SysRemoteServerService(eu.bcvsolutions.idm.acc.service.api.SysRemoteServerService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) SysBlockedOperation(eu.bcvsolutions.idm.acc.entity.SysBlockedOperation) ModuleDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ModuleDescriptorDto) SysSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter) SysRemoteServerFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRemoteServerFilter) SysConnectorServer(eu.bcvsolutions.idm.acc.entity.SysConnectorServer) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) ModuleDescriptorDto(eu.bcvsolutions.idm.core.api.dto.ModuleDescriptorDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSystem(eu.bcvsolutions.idm.acc.entity.SysSystem) SysBlockedOperation(eu.bcvsolutions.idm.acc.entity.SysBlockedOperation) ModuleDescriptorEvent(eu.bcvsolutions.idm.core.api.event.ModuleDescriptorEvent) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 19 with SysConnectorServerDto

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()));
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) IcResultCode(eu.bcvsolutions.idm.ic.domain.IcResultCode) IcRemoteServerException(eu.bcvsolutions.idm.ic.exception.IcRemoteServerException) AbstractConnectorType(eu.bcvsolutions.idm.acc.connector.AbstractConnectorType) SysSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter) Autowired(org.springframework.beans.factory.annotation.Autowired) Enabled(eu.bcvsolutions.idm.core.security.api.domain.Enabled) ApiParam(io.swagger.annotations.ApiParam) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto) IcInvalidCredentialException(eu.bcvsolutions.idm.ic.exception.IcInvalidCredentialException) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) CheckLongPollingResult(eu.bcvsolutions.idm.core.model.service.api.CheckLongPollingResult) Map(java.util.Map) SysRemoteServerService(eu.bcvsolutions.idm.acc.service.api.SysRemoteServerService) LongPollingManager(eu.bcvsolutions.idm.core.model.service.api.LongPollingManager) Pageable(org.springframework.data.domain.Pageable) AuthorizationScope(io.swagger.annotations.AuthorizationScope) SysSyncLogService(eu.bcvsolutions.idm.acc.service.api.SysSyncLogService) IcCantConnectException(eu.bcvsolutions.idm.ic.exception.IcCantConnectException) DeferredResultWrapper(eu.bcvsolutions.idm.core.rest.DeferredResultWrapper) IcConfigurationFacade(eu.bcvsolutions.idm.ic.service.api.IcConfigurationFacade) SysSystem(eu.bcvsolutions.idm.acc.entity.SysSystem) ImmutableMap(com.google.common.collect.ImmutableMap) MediaType(org.springframework.http.MediaType) Set(java.util.Set) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) UUID(java.util.UUID) NotNull(javax.validation.constraints.NotNull) LongPollingSubscriber(eu.bcvsolutions.idm.core.rest.LongPollingSubscriber) Collectors(java.util.stream.Collectors) Resource(org.springframework.hateoas.Resource) RestController(org.springframework.web.bind.annotation.RestController) List(java.util.List) ConnectorManager(eu.bcvsolutions.idm.acc.service.api.ConnectorManager) IcConnectorInfo(eu.bcvsolutions.idm.ic.api.IcConnectorInfo) ExceptionUtils(eu.bcvsolutions.idm.core.api.utils.ExceptionUtils) Entry(java.util.Map.Entry) Strings(org.apache.logging.log4j.util.Strings) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) SystemEvent(eu.bcvsolutions.idm.acc.event.SystemEvent) ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels) SystemEventType(eu.bcvsolutions.idm.acc.event.SystemEvent.SystemEventType) DeferredResult(org.springframework.web.context.request.async.DeferredResult) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ConnectorType(eu.bcvsolutions.idm.acc.service.api.ConnectorType) HashMap(java.util.HashMap) Scheduled(org.springframework.scheduling.annotation.Scheduled) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) CollectionUtils(org.apache.commons.collections4.CollectionUtils) LinkedHashMap(java.util.LinkedHashMap) RequestBody(org.springframework.web.bind.annotation.RequestBody) HttpServletRequest(javax.servlet.http.HttpServletRequest) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) Lists(com.google.common.collect.Lists) PasswordFilterManager(eu.bcvsolutions.idm.acc.service.api.PasswordFilterManager) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) SwaggerConfig(eu.bcvsolutions.idm.core.api.config.swagger.SwaggerConfig) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) AccGroupPermission(eu.bcvsolutions.idm.acc.domain.AccGroupPermission) IcConfigurationService(eu.bcvsolutions.idm.ic.service.api.IcConfigurationService) ConnectorTypeDto(eu.bcvsolutions.idm.acc.dto.ConnectorTypeDto) Api(io.swagger.annotations.Api) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) AccModuleDescriptor(eu.bcvsolutions.idm.acc.AccModuleDescriptor) IdmFormDefinitionController(eu.bcvsolutions.idm.core.eav.rest.impl.IdmFormDefinitionController) IcServerNotFoundException(eu.bcvsolutions.idm.ic.exception.IcServerNotFoundException) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) MultiValueMap(org.springframework.util.MultiValueMap) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) HttpMessageNotReadableException(org.springframework.http.converter.HttpMessageNotReadableException) SysSyncItemLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncItemLogFilter) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) HttpStatus(org.springframework.http.HttpStatus) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) AccPasswordFilterRequestDto(eu.bcvsolutions.idm.acc.dto.AccPasswordFilterRequestDto) BaseController(eu.bcvsolutions.idm.core.api.rest.BaseController) BaseDtoController(eu.bcvsolutions.idm.core.api.rest.BaseDtoController) PageableDefault(org.springframework.data.web.PageableDefault) Resources(org.springframework.hateoas.Resources) ResponseEntity(org.springframework.http.ResponseEntity) SysSyncLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncLogFilter) SysSyncItemLogService(eu.bcvsolutions.idm.acc.service.api.SysSyncItemLogService) IdmGroupPermission(eu.bcvsolutions.idm.core.security.api.domain.IdmGroupPermission) Comparator(java.util.Comparator) Authorization(io.swagger.annotations.Authorization) Assert(org.springframework.util.Assert) Set(java.util.Set) AbstractConnectorType(eu.bcvsolutions.idm.acc.connector.AbstractConnectorType) ConnectorType(eu.bcvsolutions.idm.acc.service.api.ConnectorType) IcServerNotFoundException(eu.bcvsolutions.idm.ic.exception.IcServerNotFoundException) IcInvalidCredentialException(eu.bcvsolutions.idm.ic.exception.IcInvalidCredentialException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) LinkedHashMap(java.util.LinkedHashMap) ConnectorTypeDto(eu.bcvsolutions.idm.acc.dto.ConnectorTypeDto) IcConfigurationService(eu.bcvsolutions.idm.ic.service.api.IcConfigurationService) IcConnectorInfo(eu.bcvsolutions.idm.ic.api.IcConnectorInfo) IcCantConnectException(eu.bcvsolutions.idm.ic.exception.IcCantConnectException) IcRemoteServerException(eu.bcvsolutions.idm.ic.exception.IcRemoteServerException) List(java.util.List) Resources(org.springframework.hateoas.Resources) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with SysConnectorServerDto

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());
}
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)

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