use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.
the class MsSqlConnectorType method executeStepOne.
@Override
protected void executeStepOne(ConnectorTypeDto connectorType) {
String port = connectorType.getMetadata().get(PORT);
Assert.notNull(port, "Port cannot be null!");
String host = connectorType.getMetadata().get(HOST);
Assert.notNull(host, "Host cannot be null!");
String database = connectorType.getMetadata().get(DATABASE);
Assert.notNull(database, "Database cannot be null!");
String table = connectorType.getMetadata().get(TABLE);
Assert.notNull(table, "Table cannot be null!");
String keyColumn = connectorType.getMetadata().get(KEY_COLUMN);
Assert.notNull(keyColumn, "Key column cannot be null!");
String authenticationType = connectorType.getMetadata().get(AUTHENTICATION_TYPE_KEY);
Assert.notNull(authenticationType, "Authentication type cannot be null!");
String domain = connectorType.getMetadata().get(DOMAIN_KEY);
String instanceName = connectorType.getMetadata().get(INSTANCE_NAME_KEY);
String ntlmString = connectorType.getMetadata().get(NTLM_SWITCH);
boolean ntlm = Boolean.parseBoolean(ntlmString);
String trustServerCrtString = connectorType.getMetadata().get(TRUST_SERVER_CRT_SWITCH);
boolean trustServerCrt = Boolean.parseBoolean(trustServerCrtString);
// User and password is mandatory only for SQL Server authentication type or for NTLM
String user = connectorType.getMetadata().get(USER);
boolean passwordIsMandatory = false;
if (authenticationType.equals(SQL_SERVER_AUTHENTICATION_TYPE) || (authenticationType.equals(WINDOWS_AUTHENTICATION_TYPE) && ntlm)) {
Assert.notNull(user, "Username cannot be null!");
passwordIsMandatory = true;
}
String password = connectorType.getMetadata().get(PASSWORD);
if (Strings.isBlank(password) && !passwordIsMandatory) {
// Password is null and is not mandatory, but connector wants it -> random value.
password = "random_password";
}
// Remove password from metadata.
connectorType.getMetadata().remove(PASSWORD);
String systemId = connectorType.getMetadata().get(SYSTEM_DTO_KEY);
SysSystemDto systemDto;
if (systemId != null) {
// System already exists.
systemDto = getSystemService().get(UUID.fromString(systemId), IdmBasePermission.READ);
} else {
// Create new system.
systemDto = new SysSystemDto();
}
systemDto.setName(connectorType.getMetadata().get(SYSTEM_NAME));
// Resolve remote system.
systemDto.setRemoteServer(connectorType.getRemoteServer());
// Find connector key and set it to the system.
IcConnectorKey connectorKey = getConnectorManager().findConnectorKey(connectorType);
Assert.notNull(connectorKey, "Connector key was not found!");
systemDto.setConnectorKey(new SysConnectorKeyDto(connectorKey));
systemDto = getSystemService().save(systemDto, IdmBasePermission.CREATE);
// Put new system to the connector type (will be returned to FE).
connectorType.getEmbedded().put(SYSTEM_DTO_KEY, systemDto);
IdmFormDefinitionDto connectorFormDef = this.getSystemService().getConnectorFormDefinition(systemDto);
// Set the port.
this.setValueToConnectorInstance(PORT, port, systemDto, connectorFormDef);
// Set the host.
this.setValueToConnectorInstance(HOST, host, systemDto, connectorFormDef);
// Set the database.
this.setValueToConnectorInstance(DATABASE, database, systemDto, connectorFormDef);
// Set the table.
this.setValueToConnectorInstance(TABLE, table, systemDto, connectorFormDef);
// Set the user.
this.setValueToConnectorInstance(USER, user, systemDto, connectorFormDef);
// Set the password.
// Password is mandatory only if none exists in connector configuration and for SQL Server authentication type or for NTLM.
String passwordInSystem = this.getValueFromConnectorInstance(PASSWORD, systemDto, connectorFormDef);
if (Strings.isNotBlank(password) && !GuardedString.SECRED_PROXY_STRING.equals(password)) {
this.setValueToConnectorInstance(PASSWORD, password, systemDto, connectorFormDef);
} else if (passwordIsMandatory) {
Assert.notNull(passwordInSystem, "Password cannot be null!");
}
// Set the JDBC driver.
this.setValueToConnectorInstance(JDBC_DRIVER, getJdbcDriverName(), systemDto, connectorFormDef);
// Compile JDBC url with additional parameters.
String jdbcUrlTemplate = getJdbcUrlTemplate();
if (connectorType.isReopened()) {
// For reopen system will be used persisted url.
String jdbcUrlTemplateOriginal = getValueFromConnectorInstance(JDBC_URL_TEMPLATE, systemDto, connectorFormDef);
if (Strings.isNotBlank(jdbcUrlTemplateOriginal)) {
jdbcUrlTemplate = jdbcUrlTemplateOriginal;
}
}
String jdbcUrl = compileJdbcUrl(jdbcUrlTemplate, authenticationType, ntlm, trustServerCrt, domain, instanceName);
// Set the JDBC url template.
this.setValueToConnectorInstance(JDBC_URL_TEMPLATE, jdbcUrl, systemDto, connectorFormDef);
// Set the column with PK.
this.setValueToConnectorInstance(KEY_COLUMN, keyColumn, systemDto, connectorFormDef);
// Generate schema
try {
List<SysSchemaObjectClassDto> schemas = this.getSystemService().generateSchema(systemDto);
SysSchemaObjectClassDto schemaAccount = schemas.stream().filter(schema -> IcObjectClassInfo.ACCOUNT.equals(schema.getObjectClassName())).findFirst().orElse(null);
Assert.notNull(schemaAccount, "We cannot found schema for ACCOUNT!");
connectorType.getMetadata().put(SCHEMA_ID_KEY, schemaAccount.getId().toString());
} catch (ResultCodeException ex) {
// Throw nice exception if lib for Windows authentication missing.
Throwable cause = ex.getCause();
if (cause.getMessage().contains("This driver is not configured for integrated authentication.")) {
Throwable linked = cause.getCause();
if (linked instanceof SQLException) {
Throwable missingDriverEx = linked.getCause();
if (missingDriverEx != null) {
String missingDriverExMessage = missingDriverEx.getMessage();
if (missingDriverExMessage.length() > 120) {
missingDriverExMessage = missingDriverExMessage.substring(0, 119) + "...";
}
throw new ResultCodeException(AccResultCode.WIZARD_MSSQL_CONNECTOR_LIB_MISSING, ImmutableMap.of("text", missingDriverExMessage), ex);
}
}
}
throw ex;
}
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.
the class SystemExportBulkAction method exportSchema.
/**
* Export system schemas
*
* @param systemId
*/
private void exportSchema(UUID systemId) {
SysSchemaObjectClassFilter objectClassFilter = new SysSchemaObjectClassFilter();
objectClassFilter.setSystemId(systemId);
List<SysSchemaObjectClassDto> objectClasses = objectClassService.find(objectClassFilter, null).getContent();
if (objectClasses.isEmpty()) {
schemaObjectClassService.export(ExportManager.BLANK_UUID, getBatch());
}
objectClasses.forEach(schema -> {
schemaObjectClassService.export(schema.getId(), getBatch());
});
// Set parent field -> set authoritative mode.
this.getExportManager().setAuthoritativeMode(SysSchemaObjectClass_.system.getName(), "systemId", SysSchemaObjectClassDto.class, getBatch());
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.
the class AbstractJdbcConnectorType method executeStepOne.
/**
* Execute first step of JDBC wizard.
*
* @param connectorType
*/
protected void executeStepOne(ConnectorTypeDto connectorType) {
String port = connectorType.getMetadata().get(PORT);
Assert.notNull(port, "Port cannot be null!");
String host = connectorType.getMetadata().get(HOST);
Assert.notNull(host, "Host cannot be null!");
String database = connectorType.getMetadata().get(DATABASE);
Assert.notNull(database, "Database cannot be null!");
String table = connectorType.getMetadata().get(TABLE);
Assert.notNull(table, "Table cannot be null!");
String keyColumn = connectorType.getMetadata().get(KEY_COLUMN);
Assert.notNull(keyColumn, "Key column cannot be null!");
String user = connectorType.getMetadata().get(USER);
Assert.notNull(user, "Username cannot be null!");
String password = connectorType.getMetadata().get(PASSWORD);
// Remove password from metadata.
connectorType.getMetadata().remove(PASSWORD);
String systemId = connectorType.getMetadata().get(SYSTEM_DTO_KEY);
SysSystemDto systemDto;
if (systemId != null) {
// System already exists.
systemDto = getSystemService().get(UUID.fromString(systemId), IdmBasePermission.READ);
} else {
// Create new system.
systemDto = new SysSystemDto();
}
systemDto.setName(connectorType.getMetadata().get(SYSTEM_NAME));
// Resolve remote system.
systemDto.setRemoteServer(connectorType.getRemoteServer());
// Find connector key and set it to the system.
IcConnectorKey connectorKey = connectorManager.findConnectorKey(connectorType);
Assert.notNull(connectorKey, "Connector key was not found!");
systemDto.setConnectorKey(new SysConnectorKeyDto(connectorKey));
systemDto = getSystemService().save(systemDto, IdmBasePermission.CREATE);
// Put new system to the connector type (will be returned to FE).
connectorType.getEmbedded().put(SYSTEM_DTO_KEY, systemDto);
IdmFormDefinitionDto connectorFormDef = this.getSystemService().getConnectorFormDefinition(systemDto);
// Set the port.
this.setValueToConnectorInstance(PORT, port, systemDto, connectorFormDef);
// Set the host.
this.setValueToConnectorInstance(HOST, host, systemDto, connectorFormDef);
// Set the database.
this.setValueToConnectorInstance(DATABASE, database, systemDto, connectorFormDef);
// Set the table.
this.setValueToConnectorInstance(TABLE, table, systemDto, connectorFormDef);
// Set the user.
this.setValueToConnectorInstance(USER, user, systemDto, connectorFormDef);
// Set the password.
// Password is mandatory only if none exists in connector configuration.
String passwordInSystem = this.getValueFromConnectorInstance(PASSWORD, systemDto, connectorFormDef);
if (Strings.isNotBlank(password) && !GuardedString.SECRED_PROXY_STRING.equals(password)) {
this.setValueToConnectorInstance(PASSWORD, password, systemDto, connectorFormDef);
} else {
Assert.notNull(passwordInSystem, "Password cannot be null!");
}
// Set the JDBC driver.
this.setValueToConnectorInstance(JDBC_DRIVER, getJdbcDriverName(), systemDto, connectorFormDef);
// Set the JDBC url template.
this.setValueToConnectorInstance(JDBC_URL_TEMPLATE, getJdbcUrlTemplate(), systemDto, connectorFormDef);
// Set the column with PK.
this.setValueToConnectorInstance(KEY_COLUMN, keyColumn, systemDto, connectorFormDef);
// Generate schema
List<SysSchemaObjectClassDto> schemas = this.getSystemService().generateSchema(systemDto);
SysSchemaObjectClassDto schemaAccount = schemas.stream().filter(schema -> IcObjectClassInfo.ACCOUNT.equals(schema.getObjectClassName())).findFirst().orElse(null);
Assert.notNull(schemaAccount, "We cannot found schema for ACCOUNT!");
connectorType.getMetadata().put(SCHEMA_ID_KEY, schemaAccount.getId().toString());
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.
the class RoleSynchronizationExecutor method resolveAssignRole.
private boolean resolveAssignRole(boolean isNew, SynchronizationContext context, IdmRoleDto roleDto, SysSyncRoleConfigDto config, SysSyncItemLogDto logItem, IcConnectorObject connectorObject, SysSystemAttributeMappingDto memberOfAttributeDto, SysSchemaObjectClassDto schemaObjectClassDto) {
// Find attribute for get members (DNs)
SysSystemAttributeMappingDto roleMembersAttributeDto = context.getMappedAttributes().stream().filter(attribute -> !attribute.isDisabledAttribute() && attribute.isEntityAttribute() && ROLE_MEMBERS_FIELD.equals(attribute.getIdmPropertyName())).findFirst().orElse(null);
Assert.notNull(roleMembersAttributeDto, "Mapped attribute with role's members was not found. Please create it!");
if (!isNew && AttributeMappingStrategyType.CREATE == roleMembersAttributeDto.getStrategyType()) {
addToItemLog(logItem, "The attribute with role's members has strategy set to 'Set only for new entity'. Role isn't new, so resolving controlling an assignment of roles to users by the external system will be skipped for this role.");
} else {
addToItemLog(logItem, "Controlling an assignment of roles to users by the external system is activated.");
Object membersObj = this.getValueByMappedAttribute(roleMembersAttributeDto, connectorObject.getAttributes(), context);
if (membersObj == null) {
membersObj = Lists.newArrayList();
}
if (membersObj instanceof String) {
membersObj = Lists.newArrayList(membersObj);
}
Assert.isInstanceOf(List.class, membersObj, "The value from attribute with role's members must be List of Strings!");
@SuppressWarnings("unchecked") List<String> members = (List<String>) membersObj;
SysRoleSystemDto roleSystemDto = findRoleSystemDto(roleDto, memberOfAttributeDto, schemaObjectClassDto);
if (roleSystemDto == null) {
addToItemLog(logItem, "Relation between this role and system was not found. Assigning of role to users will be skip for this role.");
return false;
}
SysRoleSystemAttributeDto memberAttribute = findMemberAttribute(memberOfAttributeDto, schemaObjectClassDto, roleSystemDto);
if (memberAttribute == null) {
addToItemLog(logItem, "The member attribute between this role and system was not found. Assigning of role to users will be skip for this role.");
return false;
}
// Find identities with this role.
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setRoleId(roleDto.getId());
List<IdmIdentityRoleDto> existsIdentityRoleDtos = identityRoleService.find(identityRoleFilter, null).getContent();
// Get cache with users (DN vs UID).
Map<String, String> usersUidCache = getUserUidCache();
SysSchemaAttributeDto memberIdentifierAttribute = lookupService.lookupEmbeddedDto(config, SysSyncRoleConfig_.memberIdentifierAttribute);
Assert.notNull(memberIdentifierAttribute, "User identifier attribute cannot be null!");
Set<String> membersUid = Sets.newHashSet();
Set<UUID> membersContractIds = Sets.newHashSet();
// Call user system for every member (if isn't already in the cache).
SysSystemDto userSystemDto = systemService.get(roleSystemDto.getSystem());
IcConnectorConfiguration icConfig = systemService.getConnectorConfiguration(userSystemDto);
IcConnectorInstance connectorInstance = systemService.getConnectorInstance(userSystemDto);
IcObjectClass objectClass = new IcObjectClassImpl(schemaObjectClassDto.getObjectClassName());
if (icConfig instanceof IcConnectorConfigurationImpl) {
// Enable pooling - a performance reason.
IcConnectorConfigurationImpl icConfigImpl = (IcConnectorConfigurationImpl) icConfig;
icConfigImpl.setConnectorPoolingSupported(true);
}
final int[] count = { 0 };
for (String member : members) {
if (!transformDnToUid(config, usersUidCache, memberIdentifierAttribute, membersUid, icConfig, connectorInstance, objectClass, count, member)) {
return false;
}
}
count[0] = 0;
membersUid.forEach(uid -> assignMissingIdentityRoles(roleDto, config, logItem, existsIdentityRoleDtos, membersContractIds, userSystemDto, count, uid, context));
if (!checkForCancelAndFlush(config)) {
return false;
}
// Remove redundant identity roles.
List<IdmIdentityRoleDto> redundantIdentityRoles = existsIdentityRoleDtos.stream().filter(existsIdentityRole -> !membersContractIds.contains(existsIdentityRole.getIdentityContract())).collect(Collectors.toList());
count[0] = 0;
redundantIdentityRoles.forEach(redundantIdentityRole -> removeRedundantIdentityRoles(roleDto, config, logItem, count, redundantIdentityRole));
}
return true;
}
use of eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto in project CzechIdMng by bcvsolutions.
the class RoleSynchronizationExecutor method checkForwardAcmChange.
/**
* Check if forward ACM value is different then value form a transformation.
*/
private void checkForwardAcmChange(IdmRoleDto dto, SynchronizationContext context, String attributeProperty, Object transformedValue) {
if (!context.isEntityDifferent() && dto.getId() != null && getConfig(context).isForwardAcmSwitch()) {
// Check if forward ACM value should be modified (differential sync).
SysSystemAttributeMappingDto memberOfAttributeDto = lookupService.lookupEmbeddedDto(getConfig(context), SysSyncRoleConfig_.memberOfAttribute);
Assert.notNull(memberOfAttributeDto, "Member attribute cannot be null!");
SysSchemaAttributeDto schemaAttributeDto = lookupService.lookupEmbeddedDto(memberOfAttributeDto, SysSystemAttributeMapping_.schemaAttribute);
SysSchemaObjectClassDto schemaObjectClassDto = lookupService.lookupEmbeddedDto(schemaAttributeDto, SysSchemaAttribute_.objectClass);
Assert.notNull(schemaObjectClassDto, "Schema cannot be null!");
boolean forwardAcmFromValue = getForwardAcmFromValue(transformedValue);
SysRoleSystemDto roleSystemDto = findRoleSystemDto(dto, memberOfAttributeDto, schemaObjectClassDto);
if (roleSystemDto == null || roleSystemDto.isForwardAccountManagemen() != forwardAcmFromValue) {
setDifferentChange(context, attributeProperty);
}
}
}
Aggregations