use of eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto in project CzechIdMng by bcvsolutions.
the class IdentityProvisioningTest method testAssignedRoles.
@Test
public void testAssignedRoles() {
SysSystemDto systemDto = helper.createTestResourceSystem(true);
SysSystemMappingDto defaultMapping = helper.getDefaultMapping(systemDto);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(systemDto.getId());
List<SysSchemaAttributeDto> schemaAttributes = schemaAttributeService.find(schemaAttributeFilter, null).getContent();
SysSchemaAttributeDto descriptionSchemaAttribute = schemaAttributes.stream().filter(attribute -> TestHelper.ATTRIBUTE_MAPPING_DESCRIPTION.equalsIgnoreCase(attribute.getName())).findFirst().get();
SysSystemAttributeMappingDto attributeAssignedRoles = new SysSystemAttributeMappingDto();
attributeAssignedRoles.setUid(false);
attributeAssignedRoles.setEntityAttribute(true);
attributeAssignedRoles.setIdmPropertyName(IdentityProvisioningExecutor.ASSIGNED_ROLES_FIELD);
attributeAssignedRoles.setTransformToResourceScript("if(attributeValue == null) " + System.lineSeparator() + "{return null;}" + System.lineSeparator() + " String result = '';" + System.lineSeparator() + " for(Object assignedRole : attributeValue)" + System.lineSeparator() + " {result = result + (assignedRole.toString())};" + System.lineSeparator() + " return result;");
attributeAssignedRoles.setName(descriptionSchemaAttribute.getName());
attributeAssignedRoles.setSchemaAttribute(descriptionSchemaAttribute.getId());
attributeAssignedRoles.setSystemMapping(defaultMapping.getId());
schemaAttributeMappingService.save(attributeAssignedRoles);
IdmRoleDto roleWithSystem = helper.createRole();
IdmRoleDto roleWithOutSystem = helper.createRole();
helper.createRoleSystem(roleWithSystem, systemDto);
IdmIdentityDto identity = helper.createIdentity();
helper.createIdentityRole(identity, roleWithOutSystem, null, null);
helper.createIdentityRole(identity, roleWithSystem, null, null);
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityId(identity.getId());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(identityRoleFilter, PageRequest.of(0, Integer.MAX_VALUE, Sort.by(IdmIdentityRole_.created.getName()))).getContent();
TestResource resource = helper.findResource(identity.getUsername());
assertNotNull(resource);
String valueOnResource = resource.getDescrip();
String result = "";
for (IdmIdentityRoleDto identityRole : identityRoles) {
IdmFormInstanceDto formInstanceDto = identityRoleService.getRoleAttributeValues(identityRole);
identityRole.getEavs().clear();
identityRole.getEavs().add(formInstanceDto);
result = result + IdentityProvisioningExecutor.convertToAssignedRoleDto(identityRole).toString();
}
assertEquals(result, valueOnResource);
}
use of eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto in project CzechIdMng by bcvsolutions.
the class PerformanceAccountManagementTest method testAcmPerformanceAdd200One.
@Ignore
@Test
public void testAcmPerformanceAdd200One() {
SysSystemDto system = initIdentityData();
Assert.assertNotNull(system);
SysSystemMappingDto mapping = systemMappingService.findProvisioningMapping(system.getId(), SystemEntityType.IDENTITY);
Assert.assertNotNull(mapping);
mapping = systemMappingService.save(mapping);
IdmIdentityDto identity = identityService.getByUsername(IDENTITY_PERFORMANCE);
boolean first = false;
if (identity == null) {
identity = helper.createIdentity(IDENTITY_PERFORMANCE);
first = true;
}
AccIdentityAccountFilter roleAccountFilter = new AccIdentityAccountFilter();
roleAccountFilter.setEntityId(identity.getId());
roleAccountFilter.setOwnership(Boolean.TRUE);
List<AccIdentityAccountDto> identityAccounts = identityAccountService.find(roleAccountFilter, null).getContent();
List<IdmRoleDto> roles = this.createRolesWithSystem(system, 200);
IdmIdentityContractDto primeContract = identityContractService.getPrimeContract(identity.getId());
Date startAcm = new Date();
IdmRoleRequestDto request = helper.createRoleRequest(primeContract, roles.toArray(new IdmRoleDto[0]));
helper.executeRequest(request, false, true);
Date endAcm = new Date();
System.out.println("testAcmPerformance200One - ACM duration: " + (endAcm.getTime() - startAcm.getTime()));
identityAccounts = identityAccountService.find(roleAccountFilter, null).getContent();
if (first) {
Assert.assertEquals(200, identityAccounts.size());
} else {
Assert.assertEquals(400, identityAccounts.size());
}
}
use of eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto in project CzechIdMng by bcvsolutions.
the class MappingContextTest method testMappingContextIdentityRolesForSystem.
@Test
public void testMappingContextIdentityRolesForSystem() {
SysSystemDto system = helper.createTestResourceSystem(true);
Assert.assertNotNull(system);
SysSystemMappingDto mapping = systemMappingService.findProvisioningMapping(system.getId(), SystemEntityType.IDENTITY);
Assert.assertNotNull(mapping);
// Create the description attribute (print context as string).
createDescriptionAttribute(system, mapping);
// Set context transformation to the mapping.
// Add identity roles for this system to the context.
mapping.setAddContextIdentityRolesForSystem(true);
mapping = initContextForMapping(mapping);
IdmRoleDto roleWithSystem = helper.createRole();
IdmRoleDto roleWithoutSystem = helper.createRole();
helper.createRoleSystem(roleWithSystem, system);
IdmIdentityDto identity = helper.createIdentity();
helper.createIdentityRole(identity, roleWithoutSystem, null, null);
IdmIdentityRoleDto identityRoleWithSystem = helper.createIdentityRole(identity, roleWithSystem, null, null);
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityId(identity.getId());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(identityRoleFilter, PageRequest.of(0, Integer.MAX_VALUE, Sort.by(IdmIdentityRole_.created.getName()))).getContent();
Assert.assertEquals(2, identityRoles.size());
TestResource resource = helper.findResource(identity.getUsername());
assertNotNull(resource);
assertEquals(identity.getFirstName(), resource.getFirstname());
MappingContext context = new MappingContext();
context.put("test", "TestValueOne");
context.setIdentityRolesForSystem(Lists.newArrayList(identityRoleWithSystem));
assertEquals(context.toString(), resource.getDescrip());
// Delete role mapping
systemMappingService.delete(mapping);
}
use of eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto in project CzechIdMng by bcvsolutions.
the class IdentityRoleValidRequestSchedulerTest method createAndSaveSystemWithMapping.
private SysSystemDto createAndSaveSystemWithMapping() {
system = null;
systemMapping = null;
SysSystemAttributeMappingDto nameAttributeMapping = null;
SysSystemAttributeMappingDto firstNameAttributeMapping = null;
SysSystemAttributeMappingDto lastNameAttributeMapping = null;
SysSystemAttributeMappingDto passwordAttributeMapping = null;
// prepare test system
system = helper.createSystem(TestResource.TABLE_NAME);
// generate schema
List<SysSchemaObjectClassDto> objectClasses = systemService.generateSchema(system);
// create test mapping
systemMapping = new SysSystemMappingDto();
systemMapping.setName("default_" + System.currentTimeMillis());
systemMapping.setEntityType(SystemEntityType.IDENTITY);
systemMapping.setOperationType(SystemOperationType.PROVISIONING);
systemMapping.setObjectClass(objectClasses.get(0).getId());
systemMapping = mappingService.save(systemMapping);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(system.getId());
Page<SysSchemaAttributeDto> schemaAttributesPage = schemaAttributeService.find(schemaAttributeFilter, null);
for (SysSchemaAttributeDto schemaAttr : schemaAttributesPage) {
if ("__NAME__".equals(schemaAttr.getName())) {
nameAttributeMapping = new SysSystemAttributeMappingDto();
nameAttributeMapping.setUid(true);
nameAttributeMapping.setEntityAttribute(true);
nameAttributeMapping.setIdmPropertyName("username");
nameAttributeMapping.setName(schemaAttr.getName());
nameAttributeMapping.setSchemaAttribute(schemaAttr.getId());
nameAttributeMapping.setSystemMapping(systemMapping.getId());
nameAttributeMapping = attributeMappingService.save(nameAttributeMapping);
} else if ("firstname".equalsIgnoreCase(schemaAttr.getName())) {
firstNameAttributeMapping = new SysSystemAttributeMappingDto();
firstNameAttributeMapping.setIdmPropertyName("firstName");
firstNameAttributeMapping.setSchemaAttribute(schemaAttr.getId());
firstNameAttributeMapping.setName(schemaAttr.getName());
firstNameAttributeMapping.setSystemMapping(systemMapping.getId());
firstNameAttributeMapping = attributeMappingService.save(firstNameAttributeMapping);
} else if ("lastname".equalsIgnoreCase(schemaAttr.getName())) {
lastNameAttributeMapping = new SysSystemAttributeMappingDto();
lastNameAttributeMapping.setIdmPropertyName("lastName");
lastNameAttributeMapping.setName(schemaAttr.getName());
lastNameAttributeMapping.setSchemaAttribute(schemaAttr.getId());
lastNameAttributeMapping.setSystemMapping(systemMapping.getId());
lastNameAttributeMapping = attributeMappingService.save(lastNameAttributeMapping);
} else if (IcConnectorFacade.PASSWORD_ATTRIBUTE_NAME.equalsIgnoreCase(schemaAttr.getName())) {
passwordAttributeMapping = new SysSystemAttributeMappingDto();
passwordAttributeMapping.setIdmPropertyName("password");
passwordAttributeMapping.setSchemaAttribute(schemaAttr.getId());
passwordAttributeMapping.setName(schemaAttr.getName());
passwordAttributeMapping.setSystemMapping(systemMapping.getId());
passwordAttributeMapping = attributeMappingService.save(passwordAttributeMapping);
}
}
assertNotNull(system);
assertNotNull(nameAttributeMapping);
assertNotNull(firstNameAttributeMapping);
assertNotNull(lastNameAttributeMapping);
assertNotNull(passwordAttributeMapping);
return system;
}
use of eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto in project CzechIdMng by bcvsolutions.
the class DefaultAccAuthenticatorTest method initData.
private void initData() {
SysSystemDto system = createTestSystem();
List<SysSchemaObjectClassDto> objectClasses = sysSystemService.generateSchema(system);
IdmIdentityDto identity = new IdmIdentityDto();
identity.setUsername(USERNAME);
identity.setLastName(USERNAME);
identity.setPassword(new GuardedString(PASSWORD));
identity = identityService.save(identity);
// Create mapped attributes to schema
SysSystemMappingDto systemMapping = new SysSystemMappingDto();
systemMapping.setName("default_" + System.currentTimeMillis());
systemMapping.setEntityType(SystemEntityType.IDENTITY);
systemMapping.setOperationType(SystemOperationType.PROVISIONING);
systemMapping.setObjectClass(objectClasses.get(0).getId());
final SysSystemMappingDto entityHandlingResult = systemEntityHandlingService.save(systemMapping);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(system.getId());
SysSystemAttributeMappingDto attributeHandlingLastName = new SysSystemAttributeMappingDto();
SysSystemAttributeMappingDto attributeHandlingPassword = new SysSystemAttributeMappingDto();
SysSystemAttributeMappingDto attributeHandlingUsername = new SysSystemAttributeMappingDto();
Page<SysSchemaAttributeDto> schemaAttributesPage = schemaAttributeService.find(schemaAttributeFilter, null);
for (SysSchemaAttributeDto schemaAttr : schemaAttributesPage) {
if ("__NAME__".equals(schemaAttr.getName())) {
attributeHandlingUsername.setUid(true);
attributeHandlingUsername.setEntityAttribute(true);
attributeHandlingUsername.setAuthenticationAttribute(true);
attributeHandlingUsername.setIdmPropertyName("username");
attributeHandlingUsername.setTransformToResourceScript("if(attributeValue){return \"x\"+ attributeValue;}");
attributeHandlingUsername.setName(schemaAttr.getName());
attributeHandlingUsername.setSchemaAttribute(schemaAttr.getId());
attributeHandlingUsername.setSystemMapping(entityHandlingResult.getId());
attributeHandlingUsername = schemaAttributeHandlingService.save(attributeHandlingUsername);
} else if ("lastname".equalsIgnoreCase(schemaAttr.getName())) {
attributeHandlingLastName.setIdmPropertyName("lastName");
attributeHandlingLastName.setName(schemaAttr.getName());
attributeHandlingLastName.setSchemaAttribute(schemaAttr.getId());
attributeHandlingLastName.setSystemMapping(entityHandlingResult.getId());
attributeHandlingLastName = schemaAttributeHandlingService.save(attributeHandlingLastName);
} else if (IcConnectorFacade.PASSWORD_ATTRIBUTE_NAME.equalsIgnoreCase(schemaAttr.getName())) {
attributeHandlingPassword.setIdmPropertyName("password");
attributeHandlingPassword.setSchemaAttribute(schemaAttr.getId());
attributeHandlingPassword.setName(schemaAttr.getName());
attributeHandlingPassword.setSystemMapping(entityHandlingResult.getId());
attributeHandlingPassword = schemaAttributeHandlingService.save(attributeHandlingPassword);
}
}
// create two roles with same system and different override username
IdmRoleDto role1 = getHelper().createRole(ROLE_NAME);
SysRoleSystemDto role1System = new SysRoleSystemDto();
role1System.setRole(role1.getId());
role1System.setSystem(system.getId());
role1System.setSystemMapping(entityHandlingResult.getId());
role1System = roleSystemService.save(role1System);
IdmRoleDto role2 = getHelper().createRole(ROLE_NAME + "2");
role2 = roleService.save(role2);
SysRoleSystemDto roleSystem2 = new SysRoleSystemDto();
roleSystem2.setSystem(system.getId());
roleSystem2.setSystemMapping(entityHandlingResult.getId());
roleSystem2.setRole(role2.getId());
roleSystem2 = roleSystemService.save(roleSystem2);
SysRoleSystemAttributeDto overloadedRole2 = new SysRoleSystemAttributeDto();
overloadedRole2.setSystemAttributeMapping(attributeHandlingUsername.getId());
overloadedRole2.setUid(true);
overloadedRole2.setEntityAttribute(true);
overloadedRole2.setTransformScript("return \"z" + USERNAME + "\";");
overloadedRole2.setIdmPropertyName("username");
overloadedRole2.setName("username");
overloadedRole2.setRoleSystem(roleSystem2.getId());
overloadedRole2 = roleSystemAttributeService.save(overloadedRole2);
}
Aggregations