use of eu.bcvsolutions.idm.acc.dto.ConnectorTypeDto in project CzechIdMng by bcvsolutions.
the class AdGroupConnectorType method executeStepOne.
/**
* Execute first step of AD wizard.
*/
protected void executeStepOne(ConnectorTypeDto connectorType) {
String memberSystemMappingId = connectorType.getMetadata().get(MEMBER_SYSTEM_MAPPING);
SysSystemMappingDto systemMappingDto = null;
if (memberSystemMappingId != null) {
systemMappingDto = getSystemMappingService().get(UUID.fromString(memberSystemMappingId), IdmBasePermission.READ);
}
if (systemMappingDto != null) {
SysSchemaObjectClassDto objectClassDto = DtoUtils.getEmbedded(systemMappingDto, SysSystemMapping_.objectClass, SysSchemaObjectClassDto.class);
Assert.notNull(objectClassDto, "Schema DTO cannot be null!");
SysSystemDto memberSystemDto = DtoUtils.getEmbedded(objectClassDto, SysSchemaObjectClass_.system, SysSystemDto.class);
Assert.notNull(memberSystemDto, "Member system DTO cannot be null!");
ConnectorType memberConnectorType = getConnectorManager().findConnectorTypeBySystem(memberSystemDto);
if (!(memberConnectorType instanceof AdUserConnectorType)) {
throw new ResultCodeException(AccResultCode.WIZARD_AD_GROUP_WRONG_MEMBER_CONNECTOR_TYPE, ImmutableMap.of("connectorType", memberConnectorType == null ? "none" : memberConnectorType.toString()));
}
ConnectorTypeDto adUserSystemMockConnectorType = new ConnectorTypeDto();
adUserSystemMockConnectorType.setReopened(true);
adUserSystemMockConnectorType.getEmbedded().put(SYSTEM_DTO_KEY, memberSystemDto);
adUserSystemMockConnectorType.getMetadata().put(SYSTEM_DTO_KEY, memberSystemDto.getId().toString());
adUserSystemMockConnectorType = super.load(adUserSystemMockConnectorType);
Map<String, String> metadata = connectorType.getMetadata();
// Find attribute with port.
metadata.put(PORT, adUserSystemMockConnectorType.getMetadata().get(PORT));
// Find attribute with host.
metadata.put(HOST, adUserSystemMockConnectorType.getMetadata().get(HOST));
// Find attribute with user.
metadata.put(USER, adUserSystemMockConnectorType.getMetadata().get(USER));
// Find attribute with ssl switch.
metadata.put(SSL_SWITCH, adUserSystemMockConnectorType.getMetadata().get(SSL_SWITCH));
// Load password.
IdmFormDefinitionDto connectorFormDef = this.getSystemService().getConnectorFormDefinition(memberSystemDto);
metadata.put(PASSWORD, this.getConfidentialValueFromConnectorInstance(CREDENTIALS, memberSystemDto, connectorFormDef));
}
super.executeStepOne(connectorType);
String mappingSyncId = connectorType.getMetadata().get(MAPPING_SYNC_ID);
if (mappingSyncId == null) {
// This attributes will be updated only if system doesn't have mapping.
// Checking by existing mapping and not by reopen flag solves a problem with reopen wizard for to early closed wizard.
// For example in the certificate step.
String systemId = connectorType.getMetadata().get(SYSTEM_DTO_KEY);
Assert.notNull(systemId, "System ID cannot be null!");
SysSystemDto systemDto = this.getSystemService().get(systemId);
initDefaultConnectorSettings(systemDto, this.getSystemService().getConnectorFormDefinition(systemDto));
}
// Get test group and find parent group container. Will be used as default group container.
if (connectorType.getMetadata().get(GROUP_CONTAINER_KEY) == null) {
String testGroup = connectorType.getMetadata().get(TEST_GROUP_KEY);
connectorType.getMetadata().put(GROUP_CONTAINER_KEY, getParent(testGroup));
}
}
use of eu.bcvsolutions.idm.acc.dto.ConnectorTypeDto in project CzechIdMng by bcvsolutions.
the class MsSqlConnectorType method load.
@Override
public ConnectorTypeDto load(ConnectorTypeDto connectorType) {
ConnectorTypeDto connectorTypeDto = super.load(connectorType);
if (!connectorTypeDto.isReopened()) {
return connectorTypeDto;
}
// Load the system.
SysSystemDto systemDto = (SysSystemDto) connectorType.getEmbedded().get(SYSTEM_DTO_KEY);
Assert.notNull(systemDto, "System must exists!");
Map<String, String> metadata = connectorType.getMetadata();
IdmFormDefinitionDto connectorFormDef = this.getSystemService().getConnectorFormDefinition(systemDto);
String jdbcUrlTemplate = getValueFromConnectorInstance(JDBC_URL_TEMPLATE, systemDto, connectorFormDef);
// Load an authentication type.
metadata.put(AUTHENTICATION_TYPE_KEY, jdbcUrlTemplate.contains(WINDOWS_AUTHENTICATION_TYPE_TEMPLATE) ? WINDOWS_AUTHENTICATION_TYPE : SQL_SERVER_AUTHENTICATION_TYPE);
// Load crt skip
metadata.put(TRUST_SERVER_CRT_SWITCH, String.valueOf(jdbcUrlTemplate.contains(TRUST_SERVER_CRT_TEMPLATE)));
// Load NTLM
metadata.put(NTLM_SWITCH, String.valueOf(jdbcUrlTemplate.contains(NTLM_TEMPLATE)));
// Load a domain.
String fullDomain = extractFullParameter(jdbcUrlTemplate, DOMAIN_TEMPLATE);
if (Strings.isNotBlank(fullDomain)) {
fullDomain = fullDomain.replace(DOMAIN_TEMPLATE, "");
}
metadata.put(DOMAIN_KEY, fullDomain);
// Load an instance name.
String fullInstanceName = extractFullParameter(jdbcUrlTemplate, INSTANCE_NAME_TEMPLATE);
if (Strings.isNotBlank(fullInstanceName)) {
fullInstanceName = fullInstanceName.replace(INSTANCE_NAME_TEMPLATE, "");
}
metadata.put(INSTANCE_NAME_KEY, fullInstanceName);
return connectorTypeDto;
}
use of eu.bcvsolutions.idm.acc.dto.ConnectorTypeDto in project CzechIdMng by bcvsolutions.
the class MssqlConnectorTypeTest method testAdditionalMSSQLAttributes.
@Test
public void testAdditionalMSSQLAttributes() {
// If not, whole test will be skipped.
if (!getJdbcConnectorTypeDriverName().equals(getDriver())) {
// Skip test.
// return;
}
ConnectorTypeDto connectorTypeDto = getConnectorTypeDto();
connectorTypeDto.setReopened(false);
ConnectorTypeDto jdbcConnectorTypeDto = connectorManager.load(connectorTypeDto);
assertNotNull(jdbcConnectorTypeDto);
jdbcConnectorTypeDto.getMetadata().put(AbstractJdbcConnectorType.HOST, this.getHost());
jdbcConnectorTypeDto.getMetadata().put(AbstractJdbcConnectorType.PORT, this.getPort());
jdbcConnectorTypeDto.getMetadata().put(AbstractJdbcConnectorType.DATABASE, this.getDatabase());
jdbcConnectorTypeDto.getMetadata().put(AbstractJdbcConnectorType.USER, this.getUsername());
jdbcConnectorTypeDto.getMetadata().put(AbstractJdbcConnectorType.PASSWORD, this.getPassword());
jdbcConnectorTypeDto.getMetadata().put(AbstractJdbcConnectorType.TABLE, "idm_identity");
jdbcConnectorTypeDto.getMetadata().put(AbstractJdbcConnectorType.KEY_COLUMN, "username");
jdbcConnectorTypeDto.setWizardStepName(AbstractJdbcConnectorType.STEP_ONE_CREATE_SYSTEM);
jdbcConnectorTypeDto.getMetadata().put(MsSqlConnectorType.AUTHENTICATION_TYPE_KEY, MsSqlConnectorType.WINDOWS_AUTHENTICATION_TYPE);
jdbcConnectorTypeDto.getMetadata().put(MsSqlConnectorType.TRUST_SERVER_CRT_SWITCH, Boolean.TRUE.toString());
jdbcConnectorTypeDto.getMetadata().put(MsSqlConnectorType.NTLM_SWITCH, Boolean.TRUE.toString());
String domain = getHelper().createName();
jdbcConnectorTypeDto.getMetadata().put(MsSqlConnectorType.DOMAIN_KEY, domain);
String instanceName = getHelper().createName();
jdbcConnectorTypeDto.getMetadata().put(MsSqlConnectorType.INSTANCE_NAME_KEY, instanceName);
// Execute the first step.
ConnectorTypeDto stepExecutedResult = connectorManager.execute(jdbcConnectorTypeDto);
// The system had to be created.
BaseDto system = stepExecutedResult.getEmbedded().get(AbstractJdbcConnectorType.SYSTEM_DTO_KEY);
assertTrue(system instanceof SysSystemDto);
SysSystemDto systemDto = systemService.get(system.getId());
assertNotNull(systemDto);
// Load connector properties from created system.
IcConnectorInstance connectorInstance = systemService.getConnectorInstance(systemDto);
assertEquals("net.tirasa.connid.bundles.db.table.DatabaseTableConnector", connectorInstance.getConnectorKey().getConnectorName());
IdmFormDefinitionDto connectorFormDef = this.systemService.getConnectorFormDefinition(systemDto);
String jdbcUrlTemplate = getValueFromConnectorInstance(AbstractJdbcConnectorType.JDBC_URL_TEMPLATE, systemDto, connectorFormDef);
// Check Windows auth.
Assert.assertTrue(jdbcUrlTemplate.contains(MsSqlConnectorType.WINDOWS_AUTHENTICATION_TYPE_TEMPLATE));
// Check trust CRT.
Assert.assertTrue(jdbcUrlTemplate.contains(MsSqlConnectorType.TRUST_SERVER_CRT_TEMPLATE));
// Check NTLM.
Assert.assertTrue(jdbcUrlTemplate.contains(MsSqlConnectorType.NTLM_TEMPLATE));
// Check Domain.
Assert.assertTrue(jdbcUrlTemplate.contains(MsSqlConnectorType.DOMAIN_TEMPLATE + domain));
// Check instance name.
Assert.assertTrue(jdbcUrlTemplate.contains(MsSqlConnectorType.INSTANCE_NAME_TEMPLATE + instanceName));
// Delete created system.
systemService.delete(systemDto);
}
use of eu.bcvsolutions.idm.acc.dto.ConnectorTypeDto in project CzechIdMng by bcvsolutions.
the class MssqlConnectorTypeTest method testUpdateAdditionalMSSQLAttributes.
@Test
public void testUpdateAdditionalMSSQLAttributes() {
// If not, whole test will be skipped.
if (!getJdbcConnectorTypeDriverName().equals(getDriver())) {
// Skip test.
// return;
}
ConnectorTypeDto connectorTypeDto = getConnectorTypeDto();
connectorTypeDto.setReopened(false);
ConnectorTypeDto jdbcConnectorTypeDto = connectorManager.load(connectorTypeDto);
assertNotNull(jdbcConnectorTypeDto);
jdbcConnectorTypeDto.getMetadata().put(AbstractJdbcConnectorType.HOST, this.getHost());
jdbcConnectorTypeDto.getMetadata().put(AbstractJdbcConnectorType.PORT, this.getPort());
jdbcConnectorTypeDto.getMetadata().put(AbstractJdbcConnectorType.DATABASE, this.getDatabase());
jdbcConnectorTypeDto.getMetadata().put(AbstractJdbcConnectorType.USER, this.getUsername());
jdbcConnectorTypeDto.getMetadata().put(AbstractJdbcConnectorType.PASSWORD, this.getPassword());
jdbcConnectorTypeDto.getMetadata().put(AbstractJdbcConnectorType.TABLE, "idm_identity");
jdbcConnectorTypeDto.getMetadata().put(AbstractJdbcConnectorType.KEY_COLUMN, "username");
jdbcConnectorTypeDto.setWizardStepName(AbstractJdbcConnectorType.STEP_ONE_CREATE_SYSTEM);
jdbcConnectorTypeDto.getMetadata().put(MsSqlConnectorType.AUTHENTICATION_TYPE_KEY, MsSqlConnectorType.WINDOWS_AUTHENTICATION_TYPE);
jdbcConnectorTypeDto.getMetadata().put(MsSqlConnectorType.TRUST_SERVER_CRT_SWITCH, Boolean.TRUE.toString());
jdbcConnectorTypeDto.getMetadata().put(MsSqlConnectorType.NTLM_SWITCH, Boolean.TRUE.toString());
String domain = getHelper().createName();
jdbcConnectorTypeDto.getMetadata().put(MsSqlConnectorType.DOMAIN_KEY, domain);
String instanceName = getHelper().createName();
jdbcConnectorTypeDto.getMetadata().put(MsSqlConnectorType.INSTANCE_NAME_KEY, instanceName);
// Execute the first step.
ConnectorTypeDto stepExecutedResult = connectorManager.execute(jdbcConnectorTypeDto);
// The system had to be created.
BaseDto system = stepExecutedResult.getEmbedded().get(AbstractJdbcConnectorType.SYSTEM_DTO_KEY);
assertTrue(system instanceof SysSystemDto);
SysSystemDto systemDto = systemService.get(system.getId());
assertNotNull(systemDto);
connectorManager.findConnectorTypeBySystem(systemDto);
ConnectorTypeDto reopenSystem = getConnectorTypeDto();
reopenSystem.setReopened(true);
reopenSystem.getEmbedded().put(PostgresqlConnectorType.SYSTEM_DTO_KEY, systemDto);
reopenSystem.getMetadata().put(PostgresqlConnectorType.SYSTEM_DTO_KEY, systemDto.getId().toString());
reopenSystem = connectorManager.load(reopenSystem);
assertNotNull(reopenSystem);
reopenSystem.setWizardStepName(AbstractJdbcConnectorType.STEP_ONE_CREATE_SYSTEM);
// Change addition attributes
reopenSystem.getMetadata().put(MsSqlConnectorType.AUTHENTICATION_TYPE_KEY, MsSqlConnectorType.SQL_SERVER_AUTHENTICATION_TYPE);
reopenSystem.getMetadata().put(MsSqlConnectorType.TRUST_SERVER_CRT_SWITCH, Boolean.FALSE.toString());
reopenSystem.getMetadata().put(MsSqlConnectorType.NTLM_SWITCH, Boolean.FALSE.toString());
String domainTwo = getHelper().createName();
reopenSystem.getMetadata().put(MsSqlConnectorType.DOMAIN_KEY, domainTwo);
String instanceNameTwo = getHelper().createName();
reopenSystem.getMetadata().put(MsSqlConnectorType.INSTANCE_NAME_KEY, instanceNameTwo);
// Execute the first step again.
connectorManager.execute(reopenSystem);
// Load connector properties from created system.
IcConnectorInstance connectorInstance = systemService.getConnectorInstance(systemDto);
assertEquals("net.tirasa.connid.bundles.db.table.DatabaseTableConnector", connectorInstance.getConnectorKey().getConnectorName());
IdmFormDefinitionDto connectorFormDef = this.systemService.getConnectorFormDefinition(systemDto);
String jdbcUrlTemplate = getValueFromConnectorInstance(AbstractJdbcConnectorType.JDBC_URL_TEMPLATE, systemDto, connectorFormDef);
// Check Windows auth.
Assert.assertFalse(jdbcUrlTemplate.contains(MsSqlConnectorType.WINDOWS_AUTHENTICATION_TYPE_TEMPLATE));
// Check trust CRT.
Assert.assertFalse(jdbcUrlTemplate.contains(MsSqlConnectorType.TRUST_SERVER_CRT_TEMPLATE));
// Check NTLM.
Assert.assertFalse(jdbcUrlTemplate.contains(MsSqlConnectorType.NTLM_TEMPLATE));
// Check Domain.
Assert.assertFalse(jdbcUrlTemplate.contains(MsSqlConnectorType.DOMAIN_TEMPLATE + domain));
Assert.assertTrue(jdbcUrlTemplate.contains(MsSqlConnectorType.DOMAIN_TEMPLATE + domainTwo));
// Check instance name.
Assert.assertFalse(jdbcUrlTemplate.contains(MsSqlConnectorType.INSTANCE_NAME_TEMPLATE + instanceName));
Assert.assertTrue(jdbcUrlTemplate.contains(MsSqlConnectorType.INSTANCE_NAME_TEMPLATE + instanceNameTwo));
// Delete created system.
systemService.delete(systemDto);
}
use of eu.bcvsolutions.idm.acc.dto.ConnectorTypeDto 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()));
}
Aggregations