use of eu.bcvsolutions.idm.ic.exception.IcException in project CzechIdMng by bcvsolutions.
the class DefaultVsAccountService method findByUidSystem.
@Override
public VsAccountDto findByUidSystem(String uidValue, UUID systemId) {
Assert.notNull(uidValue, "Uid value cannot be null!");
Assert.notNull(systemId, "Id of CzechIdM system cannot be null!");
VsAccountFilter filter = new VsAccountFilter();
filter.setUid(uidValue);
filter.setSystemId(systemId);
List<VsAccountDto> accounts = this.find(filter, null).getContent();
if (accounts.size() > 1) {
throw new IcException(MessageFormat.format("To many vs accounts for uid [{0}] and system [{1}]!", uidValue, systemId));
}
return accounts.isEmpty() ? null : accounts.get(0);
}
use of eu.bcvsolutions.idm.ic.exception.IcException in project CzechIdMng by bcvsolutions.
the class DefaultVsRequestService method internalExecute.
@Override
public IcUidAttribute internalExecute(VsRequestDto request) {
request.setState(VsRequestState.REALIZED);
Assert.notNull(request.getConfiguration(), "Request have to contains connector configuration!");
Assert.notNull(request.getConnectorKey(), "Request have to contains connector key!");
// Find connector by request
VsVirtualConnector virtualConnector = getVirtualConnector(request);
IcUidAttribute result = null;
// Save the request
this.save(request);
switch(request.getOperationType()) {
case CREATE:
{
result = virtualConnector.internalCreate(request.getConnectorObject().getObjectClass(), request.getConnectorObject().getAttributes());
break;
}
case UPDATE:
{
VsAccountDto account = accountService.findByUidSystem(request.getUid(), request.getSystem());
if (account == null) {
throw new VsException(VsResultCode.VS_REQUEST_UPDATING_ACCOUNT_NOT_EXIST, ImmutableMap.of("uid", request.getUid()));
}
result = virtualConnector.internalUpdate(new IcUidAttributeImpl(null, request.getUid(), null), request.getConnectorObject().getObjectClass(), request.getConnectorObject().getAttributes());
break;
}
case DELETE:
{
VsAccountDto account = accountService.findByUidSystem(request.getUid(), request.getSystem());
if (account == null) {
throw new VsException(VsResultCode.VS_REQUEST_DELETING_ACCOUNT_NOT_EXIST, ImmutableMap.of("uid", request.getUid()));
}
virtualConnector.internalDelete(new IcUidAttributeImpl(null, request.getUid(), null), request.getConnectorObject().getObjectClass());
// All unresolved request created before this delete request will be
// canceled
VsRequestFilter filter = new VsRequestFilter();
filter.setCreatedBefore(request.getCreated());
filter.setUid(request.getUid());
filter.setSystemId(request.getSystem());
filter.setState(VsRequestState.IN_PROGRESS);
// Unresolved request created before this request
List<VsRequestDto> beforeRequests = this.find(filter, null).getContent();
beforeRequests.forEach(beforeRequest -> {
String reason = MessageFormat.format("Request [{0}] was canceled (by SYSTEM), because 'after' delete request [{1}] was realized!", beforeRequest.getId(), request.getId());
this.cancel(beforeRequest, reason);
LOG.info(reason);
});
break;
}
default:
throw new IcException(MessageFormat.format("Unsupported operation type [{0}]", request.getOperationType()));
}
return result;
}
use of eu.bcvsolutions.idm.ic.exception.IcException in project CzechIdMng by bcvsolutions.
the class DefaultVsRequestService method getVirtualConnector.
/**
* Get virtual connector by vs request
*
* @param request
* @return
*/
private VsVirtualConnector getVirtualConnector(VsRequestDto request) {
IcConnectorInfo connectorInfo = //
czechIdMConfigurationService.getAvailableLocalConnectors().stream().filter(//
info -> request.getConnectorKey().equals(info.getConnectorKey().getFullName())).findFirst().orElse(null);
if (connectorInfo == null) {
throw new IcException(MessageFormat.format("We cannot found connector info by connector key [{0}] from virtual system request!", request.getConnectorKey()));
}
IcConnectorInstance connectorKeyInstance = new IcConnectorInstanceImpl(null, connectorInfo.getConnectorKey(), false);
IcConnector connectorInstance = czechIdMConnectorService.getConnectorInstance(connectorKeyInstance, request.getConfiguration());
if (!(connectorInstance instanceof VsVirtualConnector)) {
throw new IcException("Found connector instance is not virtual system connector!");
}
VsVirtualConnector virtualConnector = (VsVirtualConnector) connectorInstance;
return virtualConnector;
}
use of eu.bcvsolutions.idm.ic.exception.IcException 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;
}
use of eu.bcvsolutions.idm.ic.exception.IcException in project CzechIdMng by bcvsolutions.
the class CzechIdMIcConfigurationService method getSchema.
@Override
public IcSchema getSchema(IcConnectorInstance connectorInstance, IcConnectorConfiguration connectorConfiguration) {
Assert.notNull(connectorInstance);
Assert.notNull(connectorInstance.getConnectorKey());
Assert.notNull(connectorConfiguration);
String key = connectorInstance.getConnectorKey().toString();
LOG.debug("Generate schema - CzechIdM {}", key);
IcConnector connector = createConnectorInstance(connectorInstance);
if (!(connector instanceof IcCanGenSchema)) {
throw new IcException(MessageFormat.format("Connector [{0}] not supports generate schema operation!", key));
}
connector.init(connectorConfiguration);
IcSchema schema = ((IcCanGenSchema) connector).schema();
LOG.debug("Generated schema - CzechIdM ({}) schema = {}", key, schema);
return schema;
}
Aggregations