Search in sources :

Example 1 with SysConnectorServerDto

use of eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto in project CzechIdMng by bcvsolutions.

the class DefaultSysRemoteServerService method internalExport.

@Override
protected SysConnectorServerDto internalExport(UUID id) {
    SysConnectorServerDto remoteServer = super.internalExport(id);
    // Set remote connector server password to the null. We don't want update password on target IdM.
    remoteServer.setPassword(null);
    // 
    return remoteServer;
}
Also used : SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto)

Example 2 with SysConnectorServerDto

use of eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto in project CzechIdMng by bcvsolutions.

the class RemoteServerDeleteBulkAction method prevalidate.

@Override
public ResultModels prevalidate() {
    IdmBulkActionDto action = getAction();
    List<UUID> entities = getEntities(action, new StringBuilder());
    ResultModels result = new ResultModels();
    Map<ResultModel, Long> models = new HashMap<>();
    entities.forEach(remoteServerId -> {
        SysSystemFilter systemFilter = new SysSystemFilter();
        systemFilter.setRemoteServerId(remoteServerId);
        long count = systemService.count(systemFilter);
        if (count > 0) {
            SysConnectorServerDto remoteServer = getService().get(remoteServerId);
            models.put(new DefaultResultModel(AccResultCode.REMOTE_SYSTEM_DELETE_FAILED_HAS_SYSTEMS, ImmutableMap.of("remoteServer", remoteServer.getFullServerName(), "count", count)), count);
        }
    });
    // 
    // Sort by count
    List<Entry<ResultModel, Long>> collect = models.entrySet().stream().sorted(Collections.reverseOrder(Map.Entry.comparingByValue())).collect(Collectors.toList());
    collect.forEach(entry -> {
        result.addInfo(entry.getKey());
    });
    // 
    return result;
}
Also used : IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) SysSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemFilter) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) HashMap(java.util.HashMap) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) ResultModel(eu.bcvsolutions.idm.core.api.dto.ResultModel) ResultModels(eu.bcvsolutions.idm.core.api.dto.ResultModels) Entry(java.util.Map.Entry) UUID(java.util.UUID) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto)

Example 3 with SysConnectorServerDto

use of eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto in project CzechIdMng by bcvsolutions.

the class DefaultConnectorServerConfiguration method getDefaultRemoteServer.

@Override
public SysConnectorServerDto getDefaultRemoteServer() {
    UUID remoteServerId = getDefaultRemoteServerId();
    if (remoteServerId == null) {
        return null;
    }
    SysConnectorServerDto remoteServer = lookupService.lookupDto(SysConnectorServerDto.class, remoteServerId);
    if (remoteServer == null) {
        LOG.warn("Default remote server with identifier [{}] not found, returning null. Change configuration [{}]", remoteServerId, PROPERTY_DEFAULT_REMOTE_SERVER);
        return null;
    }
    return remoteServer;
}
Also used : UUID(java.util.UUID) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto)

Example 4 with SysConnectorServerDto

use of eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto in project CzechIdMng by bcvsolutions.

the class SystemExportBulkActionIntegrationTest method testExportAndImportRemoteSystem.

@Test
public void testExportAndImportRemoteSystem() {
    SysConnectorServerDto connectorServer = new SysConnectorServerDto();
    connectorServer.setHost(getHelper().createName());
    connectorServer.setPort(43);
    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
    executeExportAndImport(system, SystemExportBulkAction.NAME, ImmutableMap.of(EXECUTE_BEFORE_DTO_DELETE, this::deleteRemoteServer));
    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 not imported -> for new created system must be null!
    Assert.assertNull(system.getConnectorServer().getPassword());
    // 
    // get remote server
    SysConnectorServerDto importedConnectorServer = remoteServerService.get(system.getRemoteServer());
    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 not imported -> for new created remote server must be null!
    Assert.assertTrue(remoteServerService.getPassword(importedConnectorServer.getId()).asString().isEmpty());
}
Also used : 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 5 with SysConnectorServerDto

use of eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto in project CzechIdMng by bcvsolutions.

the class SysSystemController method getAvailableRemoteConnectors.

/**
 * Rest endpoints return available remote connectors.
 * If entity hasn't set for remote or isn't exists return empty map of connectors
 *
 * @param backendId
 * @return
 */
@RequestMapping(method = RequestMethod.GET, value = "{backendId}/search/remote")
@PreAuthorize("hasAuthority('" + AccGroupPermission.SYSTEM_READ + "')")
@ApiOperation(value = "Get available remote connectors", nickname = "getAvailableRemoteConnectors", 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 = "") }) }, notes = "Supported remote conectors (by remote server configuration).")
public ResponseEntity<Map<String, Set<IcConnectorInfo>>> getAvailableRemoteConnectors(@ApiParam(value = "System's uuid identifier or code.", required = true) @PathVariable @NotNull String backendId) {
    SysSystemDto dto = this.getDto(backendId);
    Map<String, Set<IcConnectorInfo>> infos = new HashMap<>();
    // if entity hasn't set up for remote return empty map
    if (dto == null || !dto.isRemote()) {
        return new ResponseEntity<Map<String, Set<IcConnectorInfo>>>(infos, HttpStatus.OK);
    }
    Assert.notNull(dto.getConnectorServer(), "Connector server is required.");
    // 
    try {
        for (IcConfigurationService config : icConfiguration.getIcConfigs().values()) {
            SysConnectorServerDto server = dto.getConnectorServer();
            server.setPassword(this.confidentialStorage.getGuardedString(dto.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD));
            infos.put(config.getFramework(), config.getAvailableRemoteConnectors(server));
        }
    } 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);
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IcServerNotFoundException(eu.bcvsolutions.idm.ic.exception.IcServerNotFoundException) IcInvalidCredentialException(eu.bcvsolutions.idm.ic.exception.IcInvalidCredentialException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSystem(eu.bcvsolutions.idm.acc.entity.SysSystem) ResponseEntity(org.springframework.http.ResponseEntity) IcConfigurationService(eu.bcvsolutions.idm.ic.service.api.IcConfigurationService) IcCantConnectException(eu.bcvsolutions.idm.ic.exception.IcCantConnectException) IcRemoteServerException(eu.bcvsolutions.idm.ic.exception.IcRemoteServerException) SysConnectorServerDto(eu.bcvsolutions.idm.acc.dto.SysConnectorServerDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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