Search in sources :

Example 1 with IcConnectorClass

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);
}
Also used : IcConnectorInfo(eu.bcvsolutions.idm.ic.api.IcConnectorInfo) IcConnectorConfigurationCzechIdMImpl(eu.bcvsolutions.idm.ic.czechidm.domain.IcConnectorConfigurationCzechIdMImpl) IcException(eu.bcvsolutions.idm.ic.exception.IcException) IcConnectorClass(eu.bcvsolutions.idm.ic.api.annotation.IcConnectorClass) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Example 2 with IcConnectorClass

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());
}
Also used : Serializable(java.io.Serializable) BasicVirtualConnector(eu.bcvsolutions.idm.vs.connector.basic.BasicVirtualConnector) SysConnectorKeyDto(eu.bcvsolutions.idm.acc.dto.SysConnectorKeyDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) IcConnectorInfo(eu.bcvsolutions.idm.ic.api.IcConnectorInfo) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IcConnectorClass(eu.bcvsolutions.idm.ic.api.annotation.IcConnectorClass) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)

Example 3 with IcConnectorClass

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;
}
Also used : IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) ArrayList(java.util.ArrayList) IcException(eu.bcvsolutions.idm.ic.exception.IcException) IcConnectorInfo(eu.bcvsolutions.idm.ic.api.IcConnectorInfo) IcConnectorClass(eu.bcvsolutions.idm.ic.api.annotation.IcConnectorClass) ConfigurationClass(eu.bcvsolutions.idm.core.api.domain.ConfigurationClass) IcConnectorClass(eu.bcvsolutions.idm.ic.api.annotation.IcConnectorClass) IcConnector(eu.bcvsolutions.idm.ic.api.IcConnector) Reflections(org.reflections.Reflections)

Aggregations

IcConnectorInfo (eu.bcvsolutions.idm.ic.api.IcConnectorInfo)3 IcConnectorClass (eu.bcvsolutions.idm.ic.api.annotation.IcConnectorClass)3 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)2 IcException (eu.bcvsolutions.idm.ic.exception.IcException)2 SysConnectorKeyDto (eu.bcvsolutions.idm.acc.dto.SysConnectorKeyDto)1 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)1 ConfigurationClass (eu.bcvsolutions.idm.core.api.domain.ConfigurationClass)1 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)1 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)1 IcConnector (eu.bcvsolutions.idm.ic.api.IcConnector)1 IcConnectorConfiguration (eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration)1 IcConnectorConfigurationCzechIdMImpl (eu.bcvsolutions.idm.ic.czechidm.domain.IcConnectorConfigurationCzechIdMImpl)1 BasicVirtualConnector (eu.bcvsolutions.idm.vs.connector.basic.BasicVirtualConnector)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 Reflections (org.reflections.Reflections)1