use of eu.bcvsolutions.idm.ic.api.annotation.IcConnectorClass in project CzechIdMng by bcvsolutions.
the class BasicVirtualConnector method init.
@Override
public void init(IcConnectorConfiguration configuration) {
Assert.notNull(configuration);
this.configuration = configuration;
if (!(configuration instanceof IcConnectorConfigurationCzechIdMImpl)) {
throw new IcException(MessageFormat.format("Connector configuration for virtual system must be instance of [{0}]", IcConnectorConfigurationCzechIdMImpl.class.getName()));
}
systemId = ((IcConnectorConfigurationCzechIdMImpl) configuration).getSystemId();
if (systemId == null) {
throw new IcException("System ID cannot be null (for virtual system)");
}
SysSystemDto system = this.systemService.get(systemId);
if (system == null) {
throw new IcException("System cannot be null (for virtual system)");
}
// TODO: This is workaround how mark SysSystem as virtual
if (!system.isVirtual()) {
system.setVirtual(true);
system = this.systemService.save(system);
}
IcConnectorClass connectorAnnotation = this.getClass().getAnnotation(IcConnectorClass.class);
IcConnectorInfo info = CzechIdMIcConvertUtil.convertConnectorClass(connectorAnnotation, this.getClass());
// Load configuration object
virtualConfiguration = (BasicVirtualConfiguration) CzechIdMIcConvertUtil.convertIcConnectorConfiguration(configuration, connectorAnnotation.configurationClass());
// Validate configuration
virtualConfiguration.validate();
connectorKey = info.getConnectorKey().getFullName();
String virtualSystemKey = MessageFormat.format("{0}:systemId={1}", connectorKey, systemId.toString());
String type = VsAccount.class.getName();
// Create/Update form definition and attributes
formDefinition = updateFormDefinition(virtualSystemKey, type, system, virtualConfiguration);
// Update identity and role implementers relations
updateSystemImplementers(this.virtualConfiguration, this.systemId);
}
use of eu.bcvsolutions.idm.ic.api.annotation.IcConnectorClass 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.ic.api.annotation.IcConnectorClass in project CzechIdMng by bcvsolutions.
the class CzechIdMIcConfigurationService method getAvailableLocalConnectors.
/**
* Return available local connectors for this IC implementation
*
* @return
*/
@SuppressWarnings("unchecked")
@Override
public Set<IcConnectorInfo> getAvailableLocalConnectors() {
if (connectorInfos == null) {
connectorInfos = new HashSet<>();
connectorsConfigurations = new HashMap<>();
connectorsClass = new HashMap<>();
List<Class<?>> annotated = new ArrayList<>();
// Find all class with annotation IcConnectorClass under specific
// packages
localConnectorsPackages.forEach(packageWithConnectors -> {
Reflections reflections = new Reflections(packageWithConnectors);
annotated.addAll(reflections.getTypesAnnotatedWith(IcConnectorClass.class));
});
LOG.info(MessageFormat.format("Found annotated classes with IcConnectorClass [{0}]", annotated));
for (Class<?> clazz : annotated) {
IcConnectorClass connectorAnnotation = clazz.getAnnotation(IcConnectorClass.class);
if (!this.getFramework().equals(connectorAnnotation.framework())) {
continue;
}
if (!IcConnector.class.isAssignableFrom(clazz)) {
throw new IcException(MessageFormat.format("Cannot create instance of CzechIdM connector [{0}]! Connector class must be child of [{0}]!", IcConnector.class.getSimpleName()));
}
IcConnectorInfo info = CzechIdMIcConvertUtil.convertConnectorClass(connectorAnnotation, (Class<? extends IcConnector>) clazz);
Class<? extends ConfigurationClass> configurationClass = connectorAnnotation.configurationClass();
connectorInfos.add(info);
IcConnectorConfiguration configuration = initDefaultConfiguration(configurationClass);
// Put default configuration to cache
connectorsConfigurations.put(info.getConnectorKey().getFullName(), configuration);
// Put connector class to cache
connectorsClass.put(info.getConnectorKey().getFullName(), ((Class<? extends IcConnector>) clazz));
}
LOG.info(MessageFormat.format("Found all local connector connectorInfos [{0}]", connectorInfos.toString()));
}
return connectorInfos;
}
Aggregations