use of eu.bcvsolutions.idm.acc.dto.SysSystemGroupSystemDto 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.dto.SysSystemGroupSystemDto in project CzechIdMng by bcvsolutions.
the class SystemGroupSystemSaveProcessor method process.
@Override
public EventResult<SysSystemGroupSystemDto> process(EntityEvent<SysSystemGroupSystemDto> event) {
SysSystemGroupSystemDto systemGroupDto = event.getContent();
systemGroupDto = systemGroupService.saveInternal(systemGroupDto);
event.setContent(systemGroupDto);
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.acc.dto.SysSystemGroupSystemDto in project CzechIdMng by bcvsolutions.
the class CrossDomainAdUserConnectorTypeTest method testRoleInCrossDomainGroupCannotCreateAccountForBusinessRole.
@Test
public void testRoleInCrossDomainGroupCannotCreateAccountForBusinessRole() {
ConnectorType connectorType = connectorManager.getConnectorType(MockCrossDomainAdUserConnectorType.NAME);
SysSystemDto systemDto = initSystem(connectorType);
SysSystemAttributeMappingFilter filter = new SysSystemAttributeMappingFilter();
filter.setSystemId(systemDto.getId());
filter.setName(MockCrossDomainAdUserConnectorType.LDAP_GROUPS_ATTRIBUTE);
List<SysSystemAttributeMappingDto> attributes = attributeMappingService.find(filter, null).getContent();
assertEquals(1, attributes.size());
SysSystemAttributeMappingDto ldapGroupsAttribute = attributes.stream().findFirst().get();
// Creates cross-domain group.
SysSystemGroupDto groupSystemDto = new SysSystemGroupDto();
groupSystemDto.setCode(getHelper().createName());
groupSystemDto.setType(SystemGroupType.CROSS_DOMAIN);
groupSystemDto = systemGroupService.save(groupSystemDto);
SysSystemGroupSystemDto systemGroupSystemOne = new SysSystemGroupSystemDto();
systemGroupSystemOne.setSystemGroup(groupSystemDto.getId());
systemGroupSystemOne.setMergeAttribute(ldapGroupsAttribute.getId());
systemGroupSystemOne.setSystem(systemDto.getId());
systemGroupSystemService.save(systemGroupSystemOne);
// Creates the login role.
IdmRoleDto loginRole = helper.createRole();
helper.createRoleSystem(loginRole, systemDto);
IdmRoleDto parentNoLoginRole = helper.createRole();
// Creates no-login role.
IdmRoleDto noLoginRole = helper.createRole();
SysRoleSystemDto roleSystem = helper.createRoleSystem(noLoginRole, systemDto);
roleSystem.setCreateAccountByDefault(true);
roleSystemService.save(roleSystem);
SysRoleSystemFilter roleSystemFilter = new SysRoleSystemFilter();
roleSystemFilter.setIsInCrossDomainGroupRoleId(noLoginRole.getId());
roleSystemFilter.setCheckIfIsInCrossDomainGroup(Boolean.TRUE);
roleSystemFilter.setId(roleSystem.getId());
List<SysRoleSystemDto> roleSystemDtos = roleSystemService.find(roleSystemFilter, null).getContent();
assertEquals(0, roleSystemDtos.size());
// Creates overridden ldapGroup merge attribute.
createOverriddenLdapGroupAttribute(ldapGroupsAttribute, roleSystem);
// Role-system should be in cross-domain group now.
roleSystemDtos = roleSystemService.find(roleSystemFilter, null).getContent();
assertEquals(1, roleSystemDtos.size());
SysRoleSystemDto roleSystemDto = roleSystemDtos.stream().findFirst().get();
assertTrue(roleSystemDto.isInCrossDomainGroup());
IdmRoleCompositionDto roleComposition = getHelper().createRoleComposition(parentNoLoginRole, noLoginRole);
IdmIdentityDto identity = getHelper().createIdentity();
IdmIdentityContractDto contract = getHelper().getPrimeContract(identity.getId());
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityId(identity.getId());
identityRoleFilter.setRoleId(noLoginRole.getId());
assertEquals(0, identityRoleService.count(identityRoleFilter));
// Assign parent role.
IdmRoleRequestDto roleRequestDto = getHelper().assignRoles(contract, false, parentNoLoginRole);
assertEquals(RoleRequestState.EXECUTED, roleRequestDto.getState());
assertNull(roleRequestDto.getSystemState());
assertEquals(1, identityRoleService.count(identityRoleFilter));
AccIdentityAccountFilter identityAccountFilter = new AccIdentityAccountFilter();
identityAccountFilter.setIdentityId(identity.getId());
identityAccountFilter.setSystemId(systemDto.getId());
assertEquals(0, identityAccountService.find(identityAccountFilter, null).getContent().size());
roleRequestDto = getHelper().assignRoles(contract, false, loginRole);
assertEquals(RoleRequestState.EXECUTED, roleRequestDto.getState());
assertNotNull(roleRequestDto.getSystemState());
assertEquals(1, identityAccountService.find(identityAccountFilter, null).getContent().size());
// Check if provisioning contains ldapGroups attribute with value ('ONE') from the role.
SysProvisioningOperationFilter provisioningOperationFilter = new SysProvisioningOperationFilter();
provisioningOperationFilter.setSystemId(systemDto.getId());
provisioningOperationFilter.setEntityType(SystemEntityType.IDENTITY);
provisioningOperationFilter.setEntityIdentifier(identity.getId());
List<SysProvisioningOperationDto> provisioningOperationDtos = provisioningOperationService.find(provisioningOperationFilter, null).getContent();
assertEquals(1, provisioningOperationDtos.size());
SysProvisioningOperationDto provisioningOperationDto = provisioningOperationDtos.stream().findFirst().get();
ProvisioningAttributeDto provisioningAttributeLdapGroupsDto = provisioningOperationDto.getProvisioningContext().getAccountObject().keySet().stream().filter(provisioningAtt -> MockCrossDomainAdUserConnectorType.LDAP_GROUPS_ATTRIBUTE.equals(provisioningAtt.getSchemaAttributeName())).findFirst().get();
assertNotNull(provisioningAttributeLdapGroupsDto);
Object ldapGroupsValue = provisioningOperationDto.getProvisioningContext().getAccountObject().get(provisioningAttributeLdapGroupsDto);
assertEquals("ONE", ((List<?>) ldapGroupsValue).get(0));
// Clean
provisioningOperationService.deleteOperations(systemDto.getId());
getHelper().deleteIdentity(identity.getId());
roleCompositionService.delete(roleComposition);
getHelper().deleteRole(noLoginRole.getId());
getHelper().deleteRole(parentNoLoginRole.getId());
}
use of eu.bcvsolutions.idm.acc.dto.SysSystemGroupSystemDto in project CzechIdMng by bcvsolutions.
the class SystemGroupSystemDeleteProcessor method process.
@Override
public EventResult<SysSystemGroupSystemDto> process(EntityEvent<SysSystemGroupSystemDto> event) {
SysSystemGroupSystemDto dto = event.getContent();
systemGroupSystemService.deleteInternal(dto);
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.acc.dto.SysSystemGroupSystemDto in project CzechIdMng by bcvsolutions.
the class AdUserConnectorType method getCrossDomainConnectorObject.
public IcConnectorObject getCrossDomainConnectorObject(SysSystemDto system, String uid, IcObjectClass objectClass, IcConnectorObject icConnectorObject) {
// Find merge attributes in cross-domains.
SysSystemGroupSystemFilter systemGroupSystemFilter = new SysSystemGroupSystemFilter();
systemGroupSystemFilter.setGroupType(SystemGroupType.CROSS_DOMAIN);
systemGroupSystemFilter.setDisabled(Boolean.FALSE);
systemGroupSystemFilter.setSystemId(system.getId());
List<SysSystemGroupSystemDto> systemGroupSystemDtos = systemGroupSystemService.find(systemGroupSystemFilter, null).getContent();
systemGroupSystemDtos.forEach(systemGroupSystemDto -> {
SysSystemAttributeMappingDto mergeAttribute = DtoUtils.getEmbedded(systemGroupSystemDto, SysSystemGroupSystem_.mergeAttribute, SysSystemAttributeMappingDto.class);
SysSchemaAttributeDto schemaMergeAttribute = DtoUtils.getEmbedded(mergeAttribute, SysSystemAttributeMapping_.schemaAttribute, SysSchemaAttributeDto.class);
// Load values for this attribute from others systems in group.
List<Object> connectorValuesByAttribute = this.getConnectorValuesByAttribute(uid, objectClass, schemaMergeAttribute.getName(), system, icConnectorObject, null);
IcAttribute icAttribute = icConnectorObject.getAttributes().stream().filter(attribute -> schemaMergeAttribute.getName().equals(attribute.getName())).findFirst().orElse(null);
if (icAttribute instanceof IcAttributeImpl) {
// Add results to original connector-object.
IcAttributeImpl icAttributeImpl = (IcAttributeImpl) icAttribute;
icAttributeImpl.setMultiValue(true);
icAttributeImpl.setValues(connectorValuesByAttribute);
} else {
// Attribute missing in connector-object -> create new one.
icConnectorObject.getAttributes().add(new IcAttributeImpl(schemaMergeAttribute.getName(), connectorValuesByAttribute));
}
});
return icConnectorObject;
}
Aggregations