use of eu.bcvsolutions.idm.acc.dto.SysConnectorKeyDto in project CzechIdMng by bcvsolutions.
the class SystemSaveProcessor method process.
@Override
public EventResult<SysSystemDto> process(EntityEvent<SysSystemDto> event) {
SysSystemDto dto = event.getContent();
// create default connector server
if (dto.getConnectorServer() == null) {
dto.setConnectorServer(new SysConnectorServerDto());
}
// create default connector key
if (dto.getConnectorKey() == null) {
dto.setConnectorKey(new SysConnectorKeyDto());
}
// create default blocked operations
if (dto.getBlockedOperation() == null) {
dto.setBlockedOperation(new SysBlockedOperationDto());
}
if (!service.isNew(dto)) {
// Check if is connector changed
SysSystemDto oldSystem = service.get(dto.getId());
if (!dto.getConnectorKey().equals(oldSystem.getConnectorKey())) {
// If is connector changed, we set virtual to false. (Virtual
// connectors set this attribute on true by themselves)
dto.setVirtual(false);
}
// check blocked provisioning operation and clear provisioning break cache
clearProvisionignBreakCache(dto, oldSystem);
}
SysSystemDto newSystem = service.saveInternal(dto);
event.setContent(newSystem);
// save password from remote connector server to confidential storage
if (dto.getConnectorServer().getPassword() != null) {
// save for newSystem
confidentialStorage.save(newSystem.getId(), SysSystem.class, SysSystemService.REMOTE_SERVER_PASSWORD, dto.getConnectorServer().getPassword().asString());
//
// set asterix
newSystem.getConnectorServer().setPassword(new GuardedString(GuardedString.SECRED_PROXY_STRING));
}
// TODO: clone content - mutable previous event content :/
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.acc.dto.SysConnectorKeyDto in project CzechIdMng by bcvsolutions.
the class DefaultVsSystemService method create.
@Override
public SysSystemDto create(VsSystemDto vsSystem) {
Assert.notNull(vsSystem, "Vs system dto cannot be null (for create new virtual system)");
Assert.notNull(vsSystem.getName(), "Vs system name cannot be null (for create new virtual system)");
LOG.info("Create new virtual system with name [{}].", vsSystem.getName());
SysSystemDto system = new SysSystemDto();
// Find connector for VS
Class<? extends VsVirtualConnector> defaultVirtualConnector = BasicVirtualConnector.class;
IcConnectorClass connectorAnnotation = defaultVirtualConnector.getAnnotation(IcConnectorClass.class);
IcConnectorInfo info = CzechIdMIcConvertUtil.convertConnectorClass(connectorAnnotation, (Class<? extends IcConnector>) defaultVirtualConnector);
// Set connector key for VS
system.setConnectorKey(new SysConnectorKeyDto(info.getConnectorKey()));
system.setName(vsSystem.getName());
// Create system
system = this.systemService.save(system, IdmBasePermission.CREATE);
// Find and update attributes for implementers
IdmFormDefinitionDto connectorFormDef = this.systemService.getConnectorFormDefinition(system.getConnectorInstance());
IdmFormAttributeDto implementersFormAttr = connectorFormDef.getMappedAttributeByCode(IMPLEMENTERS_PROPERTY);
formService.saveValues(system, implementersFormAttr, new ArrayList<>(vsSystem.getImplementers()));
IdmFormAttributeDto implementerRolesFormAttr = connectorFormDef.getMappedAttributeByCode(IMPLEMENTER_ROLES_PROPERTY);
formService.saveValues(system, implementerRolesFormAttr, new ArrayList<>(vsSystem.getImplementerRoles()));
IdmFormAttributeDto attributesFormAttr = connectorFormDef.getMappedAttributeByCode(ATTRIBUTES_PROPERTY);
if (!vsSystem.getAttributes().isEmpty()) {
formService.saveValues(system, attributesFormAttr, new ArrayList<>(vsSystem.getAttributes()));
} else {
List<Serializable> defaultAttributes = Lists.newArrayList((Serializable[]) BasicVirtualConfiguration.DEFAULT_ATTRIBUTES);
defaultAttributes.add(RIGHTS_ATTRIBUTE);
formService.saveValues(system, attributesFormAttr, defaultAttributes);
}
this.systemService.checkSystem(system);
// Search attribute definition for rights and set him to multivalue
String virtualSystemKey = MessageFormat.format("{0}:systemId={1}", system.getConnectorKey().getFullName(), system.getId().toString());
String type = VsAccount.class.getName();
IdmFormDefinitionDto definition = this.formService.getDefinition(type, virtualSystemKey);
IdmFormAttributeDto rightsFormAttr = formAttributeService.findAttribute(type, definition.getCode(), RIGHTS_ATTRIBUTE);
if (rightsFormAttr != null) {
rightsFormAttr.setMultiple(true);
formService.saveAttribute(rightsFormAttr);
}
// Generate schema
List<SysSchemaObjectClassDto> schemas = this.systemService.generateSchema(system);
SysSchemaObjectClassDto schemaAccount = schemas.stream().filter(schema -> IcObjectClassInfo.ACCOUNT.equals(schema.getObjectClassName())).findFirst().orElse(null);
Assert.notNull(schemaAccount, "We cannot found schema for ACCOUNT!");
// Create mapping by default attributes
this.createDefaultMapping(system, schemaAccount, vsSystem);
return this.systemService.get(system.getId());
}
use of eu.bcvsolutions.idm.acc.dto.SysConnectorKeyDto in project CzechIdMng by bcvsolutions.
the class DefaultTestHelper method createSystem.
/**
* @param tableName
* @param systemName
* @return
*/
@Override
public SysSystemDto createSystem(String tableName, String systemName, String statusColumnName, String keyColumnName) {
// create owner
org.apache.tomcat.jdbc.pool.DataSource tomcatDataSource = ((org.apache.tomcat.jdbc.pool.DataSource) dataSource);
SysSystemDto system = new SysSystemDto();
system.setName(systemName == null ? tableName + "_" + System.currentTimeMillis() : systemName);
system.setConnectorKey(new SysConnectorKeyDto(systemService.getTestConnectorKey()));
system = systemService.save(system);
IdmFormDefinitionDto savedFormDefinition = systemService.getConnectorFormDefinition(system.getConnectorInstance());
List<IdmFormValueDto> values = new ArrayList<>();
IdmFormValueDto jdbcUrlTemplate = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("jdbcUrlTemplate"));
jdbcUrlTemplate.setValue(tomcatDataSource.getUrl());
values.add(jdbcUrlTemplate);
IdmFormValueDto jdbcDriver = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("jdbcDriver"));
jdbcDriver.setValue(tomcatDataSource.getDriverClassName());
values.add(jdbcDriver);
IdmFormValueDto user = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("user"));
user.setValue(tomcatDataSource.getUsername());
values.add(user);
IdmFormValueDto password = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("password"));
password.setValue(tomcatDataSource.getPoolProperties().getPassword());
values.add(password);
IdmFormValueDto table = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("table"));
table.setValue(tableName);
values.add(table);
if (!Strings.isNullOrEmpty(keyColumnName)) {
IdmFormValueDto keyColumn = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("keyColumn"));
keyColumn.setValue(keyColumnName);
values.add(keyColumn);
}
IdmFormValueDto passwordColumn = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("passwordColumn"));
passwordColumn.setValue("password");
values.add(passwordColumn);
IdmFormValueDto allNative = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("allNative"));
allNative.setValue(true);
values.add(allNative);
IdmFormValueDto rethrowAllSQLExceptions = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("rethrowAllSQLExceptions"));
rethrowAllSQLExceptions.setValue(true);
values.add(rethrowAllSQLExceptions);
if (!Strings.isNullOrEmpty(statusColumnName)) {
IdmFormValueDto statusColumn = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("statusColumn"));
statusColumn.setValue(statusColumnName);
values.add(statusColumn);
}
IdmFormValueDto disabledStatusValue = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("disabledStatusValue"));
disabledStatusValue.setValue("disabled");
values.add(disabledStatusValue);
IdmFormValueDto enabledStatusValue = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("enabledStatusValue"));
enabledStatusValue.setValue("enabled");
values.add(enabledStatusValue);
IdmFormValueDto changeLogColumnValue = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("changeLogColumn"));
changeLogColumnValue.setValue(null);
values.add(changeLogColumnValue);
// TODO: eav to dto
SysSystem systemEntity = systemRepository.findOne(system.getId());
formService.saveValues(systemEntity, savedFormDefinition, values);
return system;
}
use of eu.bcvsolutions.idm.acc.dto.SysConnectorKeyDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemService method createTestSystem.
@Deprecated
@Transactional
public SysSystemDto createTestSystem() {
// create owner
SysSystemDto system = new SysSystemDto();
system.setName("sysOne_" + System.currentTimeMillis());
system.setConnectorKey(new SysConnectorKeyDto(getTestConnectorKey()));
system = save(system);
IdmFormDefinitionDto savedFormDefinition = getConnectorFormDefinition(system.getConnectorInstance());
List<IdmFormValueDto> values = new ArrayList<>();
IdmFormValueDto host = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("host"));
host.setValue("localhost");
values.add(host);
IdmFormValueDto port = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("port"));
port.setValue("5432");
values.add(port);
IdmFormValueDto user = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("user"));
user.setValue("idmadmin");
values.add(user);
IdmFormValueDto password = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("password"));
password.setValue("idmadmin");
values.add(password);
IdmFormValueDto database = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("database"));
database.setValue("bcv_idm_storage");
values.add(database);
IdmFormValueDto table = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("table"));
table.setValue("system_users");
values.add(table);
IdmFormValueDto keyColumn = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("keyColumn"));
keyColumn.setValue("name");
values.add(keyColumn);
IdmFormValueDto passwordColumn = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("passwordColumn"));
passwordColumn.setValue("password");
values.add(passwordColumn);
IdmFormValueDto allNative = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("allNative"));
allNative.setValue(Boolean.TRUE);
values.add(allNative);
IdmFormValueDto jdbcDriver = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("jdbcDriver"));
jdbcDriver.setValue("org.postgresql.Driver");
values.add(jdbcDriver);
IdmFormValueDto jdbcUrlTemplate = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("jdbcUrlTemplate"));
jdbcUrlTemplate.setValue("jdbc:postgresql://%h:%p/%d");
values.add(jdbcUrlTemplate);
IdmFormValueDto rethrowAllSQLExceptions = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("rethrowAllSQLExceptions"));
rethrowAllSQLExceptions.setValue(Boolean.TRUE);
values.add(rethrowAllSQLExceptions);
IdmFormValueDto statusColumn = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("statusColumn"));
statusColumn.setValue("status");
values.add(statusColumn);
IdmFormValueDto disabledStatusValue = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("disabledStatusValue"));
disabledStatusValue.setValue("disabled");
values.add(disabledStatusValue);
IdmFormValueDto enabledStatusValue = new IdmFormValueDto(savedFormDefinition.getMappedAttributeByCode("enabledStatusValue"));
enabledStatusValue.setValue("enabled");
values.add(enabledStatusValue);
// TODO: eav to DTO
getFormService().saveValues(getEntity(system.getId()), savedFormDefinition, values);
return system;
}
Aggregations