Search in sources :

Example 21 with IcException

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

the class BasicVirtualConnector method internalDelete.

@Override
public void internalDelete(IcUidAttribute uid, IcObjectClass objectClass) {
    Assert.notNull(objectClass, "Object class cannot be null!");
    String uidValue = this.validateAndGetUid(uid);
    if (!IcObjectClassInfo.ACCOUNT.equals(objectClass.getType())) {
        throw new IcException("Only ACCOUNT object class is supported now!");
    }
    // Find account by UID and System ID
    VsAccountDto account = accountService.findByUidSystem(uidValue, systemId);
    if (account == null) {
        throw new IcException(MessageFormat.format("Vs account was not found for UID [{0}] and system ID [{1}]!", uidValue, systemId));
    }
    // Delete vs account and connected form values
    accountService.delete(account);
}
Also used : VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) IcException(eu.bcvsolutions.idm.ic.exception.IcException)

Example 22 with IcException

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

the class BasicVirtualConnector method create.

@Override
public IcUidAttribute create(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));
    }
    // Create and execute request
    VsRequestDto request = createRequest(objectClass, attributes, (String) uidValue, VsOperationType.CREATE);
    return requestService.execute(request);
}
Also used : IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) IcException(eu.bcvsolutions.idm.ic.exception.IcException) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto)

Example 23 with IcException

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

the class BasicVirtualConnector method read.

@Override
public IcConnectorObject read(IcUidAttribute uid, IcObjectClass objectClass) {
    Assert.notNull(objectClass, "Object class 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!");
    }
    // Find account by UID and System ID
    VsAccountDto account = accountService.findByUidSystem(uidValue, systemId);
    // All attributes from VS account
    List<IcAttribute> vsAttributes = new ArrayList<>();
    // Create uid attribute
    IcAttributeImpl uidAttribute = new IcAttributeImpl(IcAttributeInfo.NAME, uidValue);
    vsAttributes.add(uidAttribute);
    if (account != null) {
        // Create enable attribute
        if (this.virtualConfiguration.isDisableSupported()) {
            IcAttributeImpl enableAttribute = new IcAttributeImpl(IcAttributeInfo.ENABLE, account.isEnable());
            vsAttributes.add(enableAttribute);
        }
        // Attributes from definition and configuration
        UUID accountId = account.getId();
        Arrays.asList(virtualConfiguration.getAttributes()).forEach(virtualAttirbute -> {
            IcAttribute attribute = accountService.getIcAttribute(accountId, virtualAttirbute, formDefinition);
            if (attribute == null) {
                return;
            }
            vsAttributes.add(attribute);
        });
    }
    // Overwrite attributes form VS account with attributes from unresloved
    // requests
    List<IcAttribute> attributes = this.overwriteAttributesByUnresolvedRequests(account, uidValue, vsAttributes);
    if (attributes == null) {
        return null;
    }
    IcConnectorObjectImpl connectorObject = new IcConnectorObjectImpl();
    connectorObject.setUidValue(uidValue);
    connectorObject.setObjectClass(new IcObjectClassImpl(IcObjectClassInfo.ACCOUNT));
    connectorObject.setAttributes(attributes);
    return connectorObject;
}
Also used : IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) IcAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeImpl) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) VsAccountDto(eu.bcvsolutions.idm.vs.dto.VsAccountDto) ArrayList(java.util.ArrayList) IcException(eu.bcvsolutions.idm.ic.exception.IcException) UUID(java.util.UUID) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl)

Example 24 with IcException

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

the class BasicVirtualConnector method delete.

@Override
public void delete(IcUidAttribute uid, IcObjectClass objectClass) {
    Assert.notNull(objectClass, "Object class cannot be null!");
    String uidValue = validateAndGetUid(uid);
    if (!IcObjectClassInfo.ACCOUNT.equals(objectClass.getType())) {
        throw new IcException("Only ACCOUNT object class is supported now!");
    }
    // Create and execute request
    VsRequestDto request = createRequest(objectClass, null, (String) uidValue, VsOperationType.DELETE);
    requestService.execute(request);
}
Also used : IcException(eu.bcvsolutions.idm.ic.exception.IcException) VsRequestDto(eu.bcvsolutions.idm.vs.dto.VsRequestDto)

Example 25 with IcException

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

the class BasicVirtualConnector method updateSystemEntity.

/**
 * We have to change system entity directly from VS module (request can be
 * started/executed async => standard process update UID in system entity (ACC
 * module) will not works!)
 *
 * @param uidValue
 * @param attributeUidValue
 * @param systemEntityMustExists
 */
private void updateSystemEntity(String uidValue, Object attributeUidValue, boolean systemEntityMustExists) {
    SysSystemEntityFilter systemEntityFilter = new SysSystemEntityFilter();
    systemEntityFilter.setUid(uidValue);
    systemEntityFilter.setSystemId(systemId);
    List<SysSystemEntityDto> systemEntities = systemEntityService.find(systemEntityFilter, null).getContent();
    if (systemEntities.isEmpty() && !systemEntityMustExists) {
        return;
    }
    if (systemEntities.isEmpty()) {
        throw new IcException(MessageFormat.format("System entity was not found for UID [{0}] and system ID [{1}]! Change UID attribute (new [{2}]) cannot be executed!", uidValue, systemId, attributeUidValue));
    }
    if (systemEntities.size() > 1) {
        throw new IcException(MessageFormat.format("For UID [{0}] and system ID [{1}] was found too many items [{2}]! Change UID attribute (new [{3}]) cannot be executed!", uidValue, systemId, systemEntities.size(), attributeUidValue));
    }
    SysSystemEntityDto systemEntity = systemEntities.get(0);
    systemEntity.setUid((String) attributeUidValue);
    systemEntity.setWish(false);
    // Save changed system entity
    systemEntityService.save(systemEntity);
    LOG.info("Update account - UID was changed (old: {} new: {}). System entity was updated.", uidValue, attributeUidValue);
}
Also used : IcException(eu.bcvsolutions.idm.ic.exception.IcException) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) SysSystemEntityFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemEntityFilter)

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