use of eu.bcvsolutions.idm.acc.service.api.ConnectorType in project CzechIdMng by bcvsolutions.
the class DefaultAccAccountService method getConnectorObject.
@Override
public IcConnectorObject getConnectorObject(AccAccountDto account, BasePermission... permissions) {
Assert.notNull(account, "Account cannot be null!");
this.checkAccess(account, permissions);
List<SysSchemaAttributeDto> schemaAttributes = this.getSchemaAttributes(account.getSystem(), null);
if (schemaAttributes == null) {
return null;
}
try {
// Find connector-type.
SysSystemDto systemDto = lookupService.lookupEmbeddedDto(account, AccAccount_.system);
ConnectorType connectorType = connectorManager.findConnectorTypeBySystem(systemDto);
// Find first mapping for entity type and system, from the account and return his object class.
IcObjectClass icObjectClass = schemaObjectClassService.findByAccount(account.getSystem(), account.getEntityType());
IcConnectorObject fullObject = this.systemService.readConnectorObject(account.getSystem(), account.getRealUid(), icObjectClass, connectorType);
return this.getConnectorObjectForSchema(fullObject, schemaAttributes);
} catch (Exception ex) {
SysSystemDto system = DtoUtils.getEmbedded(account, AccAccount_.system, SysSystemDto.class);
throw new ResultCodeException(AccResultCode.ACCOUNT_CANNOT_BE_READ_FROM_TARGET, ImmutableMap.of("account", account.getUid(), "system", system != null ? system.getName() : account.getSystem()), ex);
}
}
use of eu.bcvsolutions.idm.acc.service.api.ConnectorType in project CzechIdMng by bcvsolutions.
the class SysSystemController method loadConnectorType.
@ResponseBody
@RequestMapping(path = "/connector-types/load", method = RequestMethod.PUT)
@PreAuthorize("hasAuthority('" + AccGroupPermission.SYSTEM_READ + "')")
@ApiOperation(value = "Load data for specific connector type -> open existed system in the wizard step.", nickname = "loadConnectorType", response = ConnectorTypeDto.class, tags = { SysSystemController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = AccGroupPermission.SYSTEM_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = AccGroupPermission.SYSTEM_READ, description = "") }) })
public ResponseEntity<ConnectorTypeDto> loadConnectorType(@NotNull @Valid @RequestBody ConnectorTypeDto connectorTypeDto) {
if (!connectorTypeDto.isReopened()) {
// Load default values for new system.
ConnectorTypeDto result = connectorManager.load(connectorTypeDto);
return new ResponseEntity<ConnectorTypeDto>(result, HttpStatus.OK);
}
// Load data for already existed system.
String systemId = connectorTypeDto.getMetadata().get(AbstractConnectorType.SYSTEM_DTO_KEY);
Assert.notNull(systemId, "System ID have to be present in the connector type metadata.");
SysSystemDto systemDto = getDto(systemId);
if (systemDto != null) {
// If connector name is null, then default connector type will be used.
if (Strings.isBlank(connectorTypeDto.getId())) {
ConnectorType connectorType = connectorManager.findConnectorTypeBySystem(systemDto);
ConnectorTypeDto newConnectorTypeDto = connectorManager.convertTypeToDto(connectorType);
newConnectorTypeDto.setReopened(connectorTypeDto.isReopened());
newConnectorTypeDto.setMetadata(connectorTypeDto.getMetadata());
connectorTypeDto = newConnectorTypeDto;
}
connectorTypeDto.getEmbedded().put(AbstractConnectorType.SYSTEM_DTO_KEY, systemDto);
ConnectorTypeDto result = connectorManager.load(connectorTypeDto);
return new ResponseEntity<ConnectorTypeDto>(result, HttpStatus.OK);
}
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", systemId));
}
use of eu.bcvsolutions.idm.acc.service.api.ConnectorType 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.acc.service.api.ConnectorType in project CzechIdMng by bcvsolutions.
the class AbstractProvisioningProcessor method process.
/**
* Prepare provisioning operation execution
*/
@Override
public EventResult<SysProvisioningOperationDto> process(EntityEvent<SysProvisioningOperationDto> event) {
SysProvisioningOperationDto provisioningOperation = event.getContent();
SysSystemDto system = systemService.get(provisioningOperation.getSystem());
IcConnectorObject connectorObject = provisioningOperation.getProvisioningContext().getConnectorObject();
IcObjectClass objectClass = connectorObject.getObjectClass();
SysSystemEntityDto systemEntity = systemEntityService.getByProvisioningOperation(provisioningOperation);
// If exists password in attributes and system support password filter set also echo
boolean processEcho = false;
List<UUID> accountIds = null;
LOG.debug("Start provisioning operation [{}] for object with uid [{}] and connector object [{}]", provisioningOperation.getOperationType(), systemEntity.getUid(), objectClass.getType());
// Find connector identification persisted in system
if (system.getConnectorKey() == null) {
throw new ProvisioningException(AccResultCode.CONNECTOR_KEY_FOR_SYSTEM_NOT_FOUND, ImmutableMap.of("system", system.getName()));
}
// Load connector configuration from connectorType.
ConnectorType connectorType = connectorManager.findConnectorTypeBySystem(system);
IcConnectorConfiguration connectorConfig = connectorType.getConnectorConfiguration(system);
//
try {
provisioningOperation = provisioningOperationService.saveOperation(provisioningOperation);
// convert confidential string to guarded strings before provisioning realization
connectorObject = provisioningOperationService.getFullConnectorObject(provisioningOperation);
provisioningOperation.getProvisioningContext().setConnectorObject(connectorObject);
for (IcAttribute attribute : connectorObject.getAttributes()) {
if (attribute.getName().equals(ProvisioningService.PASSWORD_SCHEMA_PROPERTY_NAME) && attribute instanceof IcPasswordAttribute) {
if (this.hasSystemPasswordFilter(system)) {
IcPasswordAttributeImpl password = ((IcPasswordAttributeImpl) attribute);
accountIds = getAccounts(system.getId(), systemEntity.getId());
for (UUID accountId : accountIds) {
passwordFilterManager.setEchoForChange(accountId, password.getPasswordValue());
}
processEcho = true;
}
break;
}
}
//
IcUidAttribute resultUid = processInternal(provisioningOperation, connectorConfig);
// update system entity, when identifier on target system differs
if (resultUid != null && resultUid.getUidValue() != null) {
if (!systemEntity.getUid().equals(resultUid.getUidValue()) || systemEntity.isWish()) {
systemEntity.setUid(resultUid.getUidValue());
systemEntity.setWish(false);
systemEntity = systemEntityService.save(systemEntity);
LOG.info("UID was changed. System entity with uid [{}] was updated", systemEntity.getUid());
}
} else {
// e.g. update doesn't return
if (systemEntity.isWish()) {
systemEntity.setWish(false);
systemEntity = systemEntityService.save(systemEntity);
LOG.info("UID was changed. System entity with uid [{}] was updated", systemEntity.getUid());
}
}
provisioningOperation = provisioningOperationService.handleSuccessful(provisioningOperation);
} catch (Exception ex) {
provisioningOperation = provisioningOperationService.handleFailed(provisioningOperation, ex);
if (processEcho) {
// Clear echo record about password change
accountIds.forEach(accountId -> {
passwordFilterManager.clearChangedEcho(accountId);
});
}
}
// set operation back to content
event.setContent(provisioningOperation);
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.acc.service.api.ConnectorType in project CzechIdMng by bcvsolutions.
the class AdGroupConnectorTypeTest method testStepOneByMemberSystem.
@Test
public void testStepOneByMemberSystem() {
// Create system with members.
SysSystemDto memberSystemDto = createMemberSystem();
SysSystemMappingFilter mappingFilter = new SysSystemMappingFilter();
mappingFilter.setSystemId(memberSystemDto.getId());
mappingFilter.setOperationType(SystemOperationType.PROVISIONING);
mappingFilter.setEntityType(SystemEntityType.IDENTITY);
SysSystemMappingDto mappingDto = mappingService.find(mappingFilter, null).getContent().stream().findFirst().orElse(null);
assertNotNull(mappingDto);
ConnectorType connectorType = connectorManager.getConnectorType(MockAdGroupConnectorType.NAME);
ConnectorTypeDto connectorTypeDto = connectorManager.convertTypeToDto(connectorType);
connectorTypeDto.setReopened(false);
connectorManager.load(connectorTypeDto);
assertNotNull(connectorTypeDto);
connectorTypeDto.getMetadata().put(MockAdGroupConnectorType.SYSTEM_NAME, this.getHelper().createName());
connectorTypeDto.getMetadata().put(MockAdGroupConnectorType.MEMBER_SYSTEM_MAPPING, mappingDto.getId().toString());
connectorTypeDto.setWizardStepName(MockAdGroupConnectorType.STEP_ONE);
// Execute the first step.
ConnectorTypeDto stepExecutedResult = connectorManager.execute(connectorTypeDto);
BaseDto systemDto = stepExecutedResult.getEmbedded().get(MockAdGroupConnectorType.SYSTEM_DTO_KEY);
assertNotNull("System ID cannot be null!", systemDto);
SysSystemDto system = systemService.get(systemDto.getId());
assertNotNull(system);
// Clean
systemService.delete((SysSystemDto) systemDto);
systemService.delete(memberSystemDto);
}
Aggregations