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.");
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations