Search in sources :

Example 26 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 27 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)

Aggregations

IcException (eu.bcvsolutions.idm.ic.exception.IcException)27 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)5 UUID (java.util.UUID)5 IcObjectClassImpl (eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl)4 VsRequestDto (eu.bcvsolutions.idm.vs.dto.VsRequestDto)4 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)3 IcUidAttribute (eu.bcvsolutions.idm.ic.api.IcUidAttribute)3 IcConnectorClass (eu.bcvsolutions.idm.ic.api.annotation.IcConnectorClass)3 IcUidAttributeImpl (eu.bcvsolutions.idm.ic.impl.IcUidAttributeImpl)3 VsVirtualConnector (eu.bcvsolutions.idm.vs.connector.api.VsVirtualConnector)3 Transactional (org.springframework.transaction.annotation.Transactional)3 ConfigurationClass (eu.bcvsolutions.idm.core.api.domain.ConfigurationClass)2 IcConnectorConfigurationCzechIdMImpl (eu.bcvsolutions.idm.ic.czechidm.domain.IcConnectorConfigurationCzechIdMImpl)2 BasicVirtualConfiguration (eu.bcvsolutions.idm.vs.connector.basic.BasicVirtualConfiguration)2 ArrayList (java.util.ArrayList)2