use of eu.bcvsolutions.idm.ic.api.IcConnectorInstance 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.api.IcConnectorInstance in project CzechIdMng by bcvsolutions.
the class OperationOptionsIntegrationTest method t1_testOperationOptionsSetting.
@Test
public void t1_testOperationOptionsSetting() {
Mockito.when(mockFacadeFactory.getConnectorFacade(Mockito.any(), Mockito.any())).thenReturn(mockConnector);
SysSystemDto system = systemService.getByCode(TEST_SYSTEM_NAME);
SysSystemMappingDto mapping = accTestHelper.createMapping(system);
IcConnectorInstance connectorInstance = systemService.getConnectorInstance(system);
IdmFormDefinitionDto operationOptionsConnectorFormDefinition = systemService.getOperationOptionsConnectorFormDefinition(system);
IcObjectClassImpl icObjectClass = new IcObjectClassImpl(sysSchemaObjectClassService.get(mapping.getObjectClass()).getObjectClassName());
connIdIcConnectorService.search(connectorInstance, systemService.getConnectorConfiguration(system), icObjectClass, null, a -> true);
Mockito.verify(mockFacadeFactory, Mockito.atLeastOnce()).getConnectorFacade(Mockito.any(), Mockito.any());
Mockito.verify(mockConnector, Mockito.times(1)).search(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.argThat(operationOptions -> operationOptions.getOptions().isEmpty()));
formService.saveValues(system, operationOptionsConnectorFormDefinition, OperationOptions.OP_PAGE_SIZE, Collections.singletonList(42069));
formService.saveValues(system, operationOptionsConnectorFormDefinition, OperationOptions.OP_ATTRIBUTES_TO_GET, Arrays.asList("attr1", "attr2"));
connIdIcConnectorService.search(connectorInstance, systemService.getConnectorConfiguration(system), icObjectClass, null, a -> true);
connIdIcConnectorService.createObject(connectorInstance, systemService.getConnectorConfiguration(system), icObjectClass, Collections.emptyList());
connIdIcConnectorService.updateObject(connectorInstance, systemService.getConnectorConfiguration(system), icObjectClass, new IcUidAttributeImpl("a", "a", "a"), Collections.emptyList());
connIdIcConnectorService.authenticateObject(connectorInstance, systemService.getConnectorConfiguration(system), icObjectClass, "aaa", new GuardedString("a"));
connIdIcConnectorService.deleteObject(connectorInstance, systemService.getConnectorConfiguration(system), icObjectClass, new IcUidAttributeImpl("a", "a", "a"));
connIdIcConnectorService.readObject(connectorInstance, systemService.getConnectorConfiguration(system), icObjectClass, new IcUidAttributeImpl("a", "a", "a"));
connIdIcConnectorService.synchronization(connectorInstance, systemService.getConnectorConfiguration(system), icObjectClass, null, a -> true);
ArgumentMatcher<OperationOptions> optionsMatcher = operationOptions -> !operationOptions.getOptions().isEmpty() && operationOptions.getPageSize() == 42069 && Arrays.asList(operationOptions.getAttributesToGet()).containsAll(Arrays.asList("attr1", "attr2"));
Mockito.verify(mockConnector, Mockito.times(1)).search(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.argThat(optionsMatcher));
Mockito.verify(mockConnector, Mockito.times(1)).getObject(Mockito.any(), Mockito.any(), Mockito.argThat(optionsMatcher));
Mockito.verify(mockConnector, Mockito.times(1)).create(Mockito.any(), Mockito.any(), Mockito.argThat(optionsMatcher));
Mockito.verify(mockConnector, Mockito.times(1)).update(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.argThat(optionsMatcher));
Mockito.verify(mockConnector, Mockito.times(1)).delete(Mockito.any(), Mockito.any(), Mockito.argThat(optionsMatcher));
Mockito.verify(mockConnector, Mockito.times(1)).sync(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.argThat(optionsMatcher));
Mockito.verify(mockConnector, Mockito.times(1)).authenticate(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.argThat(optionsMatcher));
}
use of eu.bcvsolutions.idm.ic.api.IcConnectorInstance in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemServiceIntegrationTest method testCreateConnectorConfiguration.
@Test
public void testCreateConnectorConfiguration() {
// TODO: test system will be moved here, after UI eav form implementation
@SuppressWarnings("deprecation") IcConnectorKey connectorKey = systemService.getTestConnectorKey();
// create connector instance impl with connector key
IcConnectorInstance connectorInstance = new IcConnectorInstanceImpl(null, connectorKey, false);
IcConnectorConfiguration conf = icConfigurationAggregatorService.getConnectorConfiguration(connectorInstance);
IdmFormDefinitionDto savedFormDefinition = systemService.getConnectorFormDefinition(connectorInstance);
assertEquals(conf.getConfigurationProperties().getProperties().size(), savedFormDefinition.getFormAttributes().size());
assertEquals(conf.getConfigurationProperties().getProperties().get(3).getDisplayName(), savedFormDefinition.getFormAttributes().get(3).getName());
}
use of eu.bcvsolutions.idm.ic.api.IcConnectorInstance in project CzechIdMng by bcvsolutions.
the class AdUserConnectorType method getConnectorValuesByAttribute.
/**
* Search connector values for given attribute.
* If is system in cross-domain system group, then is will be call this method for all systems in a group.
* For searching in other systems will be used SID, GROUPS and 'foreignSecurityPrincipals' container.
*/
@Override
public List<Object> getConnectorValuesByAttribute(String uid, IcObjectClass objectClass, String schemaAttributeName, SysSystemDto system, IcConnectorObject connectorObject, SysSystemGroupSystemDto systemGroupSystem) {
List<Object> connectorValues = super.getConnectorValuesByAttribute(uid, objectClass, schemaAttributeName, system, connectorObject, systemGroupSystem);
if (systemGroupSystem == null) {
// Find if the system is in a group with cross-domain type and for given schema attribute.
SysSystemGroupSystemFilter systemGroupSystemFilter = new SysSystemGroupSystemFilter();
systemGroupSystemFilter.setGroupType(SystemGroupType.CROSS_DOMAIN);
systemGroupSystemFilter.setDisabled(Boolean.FALSE);
systemGroupSystemFilter.setSystemId(system.getId());
systemGroupSystemFilter.setMergeAttributeCode(schemaAttributeName);
UUID systemGroupId = systemGroupSystemService.find(systemGroupSystemFilter, null).getContent().stream().findFirst().map(SysSystemGroupSystemDto::getSystemGroup).orElse(null);
if (systemGroupId == null) {
// System is not in a cross-domain group -> we have all connector values.
return connectorValues;
}
// Found all group-systems for this group (without given system).
systemGroupSystemFilter.setSystemGroupId(systemGroupId);
systemGroupSystemFilter.setSystemId(null);
List<SysSystemGroupSystemDto> groupSystems = systemGroupSystemService.find(systemGroupSystemFilter, null).getContent().stream().filter(groupSystem -> !system.getId().equals(groupSystem.getSystem())).collect(Collectors.toList());
// Call connector type for every system and load values for given attribute.
groupSystems.forEach(groupSystem -> {
SysSystemDto systemInGroup = DtoUtils.getEmbedded(groupSystem, SysSystemGroupSystem_.system, SysSystemDto.class);
ConnectorType connectorType = getConnectorManager().findConnectorTypeBySystem(systemInGroup);
if (connectorType != null) {
List<Object> connectorValuesForSystemInGroup = connectorType.getConnectorValuesByAttribute(uid, objectClass, schemaAttributeName, systemInGroup, connectorObject, groupSystem);
if (connectorValuesForSystemInGroup != null) {
connectorValuesForSystemInGroup.forEach(value -> {
if (!connectorValues.contains(value)) {
connectorValues.add(value);
}
});
}
}
});
} else {
// System group is not null, so this is sub system in group. We need to get groups by SID.
Assert.notNull(connectorObject, "The parent connector object cannot be null!");
IcAttribute sid = connectorObject.getAttributeByName(SID_ATTRIBUTE_KEY);
Assert.notNull(sid, "SID attribute cannot be null!");
Object sidValue = sid.getValue();
Assert.notNull(sidValue, "SID value cannot be null!");
IdmFormDefinitionDto operationOptionsFormDefinition = this.getSystemService().getOperationOptionsConnectorFormDefinition(system);
Assert.notNull(operationOptionsFormDefinition, "Operation options form-definition cannot be null!");
// Find attribute with container with existed users.
String userContainer = getValueFromConnectorInstance(USER_SEARCH_CONTAINER_KEY, system, operationOptionsFormDefinition);
Assert.notNull(userContainer, "User container cannot be null!");
// First we have to find root DN (only DCs).
String dcs = getRoot(userContainer);
String foreignSecurityPrincipalsDN = MessageFormat.format("CN={0},CN={1},{2}", convertSidToStr((byte[]) sidValue), FOREIGN_SECURITY_PRINCIPALS_CN, dcs);
IcConnectorConfiguration connectorConfiguration = getSystemService().getConnectorConfiguration(system);
IcConnectorInstance connectorInstance = getSystemService().getConnectorInstance(system);
Set<String> groups = searchGroups("member", connectorConfiguration, connectorInstance, foreignSecurityPrincipalsDN);
connectorValues.addAll(groups);
}
return connectorValues;
}
use of eu.bcvsolutions.idm.ic.api.IcConnectorInstance in project CzechIdMng by bcvsolutions.
the class DefaultVsSystemService method getConnectorInstance.
@Transactional
@Override
public IcConnector getConnectorInstance(UUID systemId, IcConnectorInfo connectorInfo) {
Assert.notNull(systemId, "System ID is required!");
Assert.notNull(connectorInfo, "Connector info is required.");
IcConnectorInstance connectorKeyInstance = new IcConnectorInstanceImpl(null, connectorInfo.getConnectorKey(), false);
IcConnectorConfiguration configuration = systemService.getConnectorConfiguration(systemService.get(systemId));
// VŠ: !Bigger change ... configuration of system is not load from the request,
// but is online loading.
// There was problem with implementers. They was updated by implementers stored
// in the request configuration!
IcConnector connectorInstance = czechIdMConnectorService.getConnectorInstance(connectorKeyInstance, configuration);
return connectorInstance;
}
Aggregations