Search in sources :

Example 6 with IcException

use of eu.bcvsolutions.idm.ic.exception.IcException in project CzechIdMng by bcvsolutions.

the class BasicVirtualConnector method search.

@Override
public void search(IcObjectClass objectClass, IcFilter filter, IcResultsHandler handler) {
    Assert.notNull(objectClass, "Object class cannot be null!");
    Assert.notNull(handler, "Result handler cannot be null for search operation!");
    if (!IcObjectClassInfo.ACCOUNT.equals(objectClass.getType())) {
        throw new IcException("Only ACCOUNT object class is supported now!");
    }
    if (filter == null) {
        Pageable pageable = new PageRequest(0, 10);
        searchByPage(handler, pageable);
    } else {
        // TODO: Search by filter
        throw new IcException("Virtual system connector does not support search by filter! Filter must be null!. It means search return always all accounts.");
    }
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) IcException(eu.bcvsolutions.idm.ic.exception.IcException)

Example 7 with IcException

use of eu.bcvsolutions.idm.ic.exception.IcException in project CzechIdMng by bcvsolutions.

the class BasicVirtualConnector method updateFormAttributeValue.

private void updateFormAttributeValue(Object uidValue, String virtualAttirbute, UUID accountId, List<IcAttribute> attributes) {
    IcAttribute attribute = geAttribute(attributes, virtualAttirbute);
    if (attribute == null) {
        return;
    }
    List<Object> values = attribute.getValues();
    List<Serializable> serializableValues = new ArrayList<>();
    if (values != null) {
        values.forEach(value -> {
            if (!(value instanceof Serializable)) {
                throw new IcException(MessageFormat.format("Ic attribute value [{0}] is not Serializable! For account with UID [{1}].", value, uidValue));
            }
            serializableValues.add((Serializable) value);
        });
    }
    formService.saveValues(accountId, VsAccount.class, this.formDefinition, virtualAttirbute, serializableValues);
}
Also used : Serializable(java.io.Serializable) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) ArrayList(java.util.ArrayList) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) IcException(eu.bcvsolutions.idm.ic.exception.IcException)

Example 8 with IcException

use of eu.bcvsolutions.idm.ic.exception.IcException in project CzechIdMng by bcvsolutions.

the class BasicVirtualConnector method update.

@Override
public IcUidAttribute update(IcUidAttribute uid, IcObjectClass objectClass, List<IcAttribute> attributes) {
    Assert.notNull(objectClass, "Object class cannot be null!");
    Assert.notNull(attributes, "Attributes cannot be null!");
    Assert.notNull(uid, "UID cannot be null!");
    if (!IcObjectClassInfo.ACCOUNT.equals(objectClass.getType())) {
        throw new IcException("Only ACCOUNT object class is supported now!");
    }
    String uidValue = uid.getUidValue();
    if (uidValue == null) {
        throw new IcException("UID value cannot be null!");
    }
    VsRequestDto request = createRequest(objectClass, attributes, (String) uidValue, VsOperationType.UPDATE);
    return requestService.execute(request);
}
Also used : IcException(eu.bcvsolutions.idm.ic.exception.IcException) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto)

Example 9 with IcException

use of eu.bcvsolutions.idm.ic.exception.IcException 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 10 with IcException

use of eu.bcvsolutions.idm.ic.exception.IcException in project CzechIdMng by bcvsolutions.

the class BasicVirtualConnector method internalCreate.

@Override
public IcUidAttribute internalCreate(IcObjectClass objectClass, List<IcAttribute> attributes) {
    Assert.notNull(objectClass, "Object class cannot be null!");
    Assert.notNull(attributes, "Attributes cannot be null!");
    if (!IcObjectClassInfo.ACCOUNT.equals(objectClass.getType())) {
        throw new IcException("Only ACCOUNT object class is supported now!");
    }
    IcAttribute uidAttribute = geAttribute(attributes, IcAttributeInfo.NAME);
    if (uidAttribute == null) {
        throw new IcException("UID attribute was not found!");
    }
    Object uidValue = uidAttribute.getValue();
    if (!(uidValue instanceof String)) {
        throw new IcException(MessageFormat.format("UID attribute value [{0}] must be String!", uidValue));
    }
    String uid = (String) uidValue;
    // Find account by UID and System ID - If will be found, then we will do
    // update instead create
    VsAccountDto account = accountService.findByUidSystem(uid, systemId);
    if (account != null) {
        LOG.info("Create account - Virtual system account for UID [{}] already exist. We will execute update!", uidValue);
        return this.internalUpdate(new IcUidAttributeImpl(null, uid, null), objectClass, attributes);
    }
    account = new VsAccountDto();
    // Set ENABLE - if is supported
    IcAttribute enableAttribute = geAttribute(attributes, IcAttributeInfo.ENABLE);
    if (enableAttribute != null && this.virtualConfiguration.isDisableSupported()) {
        Object attributeEnableValue = enableAttribute.getValue();
        if (!(attributeEnableValue instanceof Boolean)) {
            throw new IcException(MessageFormat.format("ENABLE attribute value [{0}] must be Boolean!", attributeEnableValue));
        }
        account.setEnable((Boolean) attributeEnableValue);
    }
    account.setUid(uid);
    account.setSystemId(this.systemId);
    account.setConnectorKey(connectorKey);
    account = accountService.save(account);
    UUID accountId = account.getId();
    // Attributes from definition and configuration
    Arrays.asList(virtualConfiguration.getAttributes()).forEach(virtualAttirbute -> {
        updateFormAttributeValue(uidValue, virtualAttirbute, accountId, attributes);
    });
    // We have to change system entity directly (set wish=false!!!) from VS module
    // (request can be started/executed async => standard
    // process update UID in system entity (ACC module) will not
    // works!)
    updateSystemEntity(uid, uid, false);
    return new IcUidAttributeImpl(IcAttributeInfo.NAME, account.getUid(), null);
}
Also used : IcUidAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) IcException(eu.bcvsolutions.idm.ic.exception.IcException) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) UUID(java.util.UUID)

Aggregations

IcException (eu.bcvsolutions.idm.ic.exception.IcException)25 IcConnector (eu.bcvsolutions.idm.ic.api.IcConnector)10 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)7 IcAttribute (eu.bcvsolutions.idm.ic.api.IcAttribute)6 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)6 VsAccountDto (eu.bcvsolutions.idm.vs.dto.VsAccountDto)6 IcConnectorInfo (eu.bcvsolutions.idm.ic.api.IcConnectorInfo)4 IcObjectClassImpl (eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl)4 VsRequestDto (eu.bcvsolutions.idm.vs.dto.VsRequestDto)4 ArrayList (java.util.ArrayList)4 UUID (java.util.UUID)4 IcUidAttribute (eu.bcvsolutions.idm.ic.api.IcUidAttribute)3 IcUidAttributeImpl (eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl)3 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)2 ConfigurationClass (eu.bcvsolutions.idm.core.api.domain.ConfigurationClass)2 IcConnectorInstance (eu.bcvsolutions.idm.ic.api.IcConnectorInstance)2 IcConnectorClass (eu.bcvsolutions.idm.ic.api.annotation.IcConnectorClass)2 IcConnectorInstanceImpl (eu.bcvsolutions.idm.ic.impl.IcConnectorInstanceImpl)2 VsVirtualConnector (eu.bcvsolutions.idm.vs.connector.api.VsVirtualConnector)2 PageRequest (org.springframework.data.domain.PageRequest)2