use of eu.bcvsolutions.idm.acc.entity.TestResource in project CzechIdMng by bcvsolutions.
the class AccountProtectionSystemTest method protectedAccountDeleteTest.
/**
* When is account in protection mode, then cannot be deleted.
*/
@Test(expected = ResultCodeException.class)
public void protectedAccountDeleteTest() {
IdmIdentityDto identity = helper.createIdentity();
SysSystemDto system = initSystem();
IdmRoleDto roleOne = roleService.getByCode(ROLE_ONE);
// Set system to protected mode
SysSystemMappingDto mapping = systemMappingService.findBySystem(system, SystemOperationType.PROVISIONING, SystemEntityType.IDENTITY).get(0);
mapping.setProtectionEnabled(Boolean.TRUE);
mapping.setProtectionInterval(null);
systemMappingService.save(mapping);
IdmIdentityRoleDto identityRole = helper.createIdentityRole(identity, roleOne);
AccAccountDto account = accountService.getAccount(identity.getUsername(), system.getId());
Assert.assertNotNull(account);
Assert.assertFalse(account.isInProtection());
TestResource createdAccount = helper.findResource(account.getUid());
Assert.assertNotNull(createdAccount);
// Remove role from identity
identityRoleService.deleteById(identityRole.getId());
account = accountService.getAccount(identity.getUsername(), system.getId());
Assert.assertNotNull(account);
Assert.assertTrue(account.isInProtection());
Assert.assertNull(account.getEndOfProtection());
createdAccount = helper.findResource(account.getUid());
Assert.assertNotNull(createdAccount);
Assert.assertEquals(identity.getFirstName(), createdAccount.getFirstname());
// Delete AccAccount directly
accountService.delete(account);
}
use of eu.bcvsolutions.idm.acc.entity.TestResource in project CzechIdMng by bcvsolutions.
the class AccountProtectionSystemTest method accountWithProtectionRetryTest.
@Test
public void accountWithProtectionRetryTest() {
IdmIdentityDto identity = helper.createIdentity();
SysSystemDto system = initSystem();
IdmRoleDto roleOne = roleService.getByCode(ROLE_ONE);
// Set system to protected mode
SysSystemMappingDto mapping = helper.getDefaultMapping(system);
mapping.setProtectionInterval(null);
mapping.setProtectionEnabled(true);
mapping = systemMappingService.save(mapping);
IdmIdentityRoleDto identityRole = helper.createIdentityRole(identity, roleOne);
AccAccountDto account = accountService.getAccount(identity.getUsername(), system.getId());
// Remove role from identity
identityRoleService.deleteById(identityRole.getId());
account = accountService.getAccount(identity.getUsername(), system.getId());
Assert.assertNotNull(account);
Assert.assertTrue(account.isInProtection());
Assert.assertNull(account.getEndOfProtection());
TestResource createdAccount = helper.findResource(account.getUid());
Assert.assertNotNull(createdAccount);
Assert.assertEquals(identity.getFirstName(), createdAccount.getFirstname());
// We again assign same role
identityRole = helper.createIdentityRole(identity, roleOne);
// Account must be unprotected
account = accountService.getAccount(identity.getUsername(), system.getId());
Assert.assertNotNull(account);
Assert.assertFalse(account.isInProtection());
createdAccount = helper.findResource(account.getUid());
Assert.assertNotNull(createdAccount);
Assert.assertEquals(identity.getFirstName(), createdAccount.getFirstname());
}
use of eu.bcvsolutions.idm.acc.entity.TestResource in project CzechIdMng by bcvsolutions.
the class AccountProtectionSystemTest method protectedAccountExpiredDeleteTest.
/**
* When is account in protection mode (but expired), then can be deleted.
*/
@Test()
public void protectedAccountExpiredDeleteTest() {
IdmIdentityDto identity = helper.createIdentity();
SysSystemDto system = initSystem();
IdmRoleDto roleOne = roleService.getByCode(ROLE_ONE);
// Set system to protected mode
SysSystemMappingDto mapping = systemMappingService.findBySystem(system, SystemOperationType.PROVISIONING, SystemEntityType.IDENTITY).get(0);
mapping.setProtectionEnabled(Boolean.TRUE);
mapping.setProtectionInterval(null);
systemMappingService.save(mapping);
IdmIdentityRoleDto identityRole = helper.createIdentityRole(identity, roleOne);
AccAccountDto account = accountService.getAccount(identity.getUsername(), system.getId());
Assert.assertNotNull(account);
Assert.assertFalse(account.isInProtection());
TestResource createdAccount = helper.findResource(account.getUid());
Assert.assertNotNull(createdAccount);
// Remove role from identity
identityRoleService.deleteById(identityRole.getId());
account = accountService.getAccount(identity.getUsername(), system.getId());
Assert.assertNotNull(account);
Assert.assertTrue(account.isInProtection());
Assert.assertNull(account.getEndOfProtection());
createdAccount = helper.findResource(account.getUid());
Assert.assertNotNull(createdAccount);
Assert.assertEquals(identity.getFirstName(), createdAccount.getFirstname());
// Set account as expired
account.setEndOfProtection(ZonedDateTime.now().minusMonths(1));
account = accountService.save(account);
// Delete AccAccount directly
accountService.delete(account);
account = accountService.getAccount(identity.getUsername(), system.getId());
Assert.assertNull(account);
createdAccount = helper.findResource(identity.getUsername());
Assert.assertNull(createdAccount);
}
use of eu.bcvsolutions.idm.acc.entity.TestResource in project CzechIdMng by bcvsolutions.
the class AccountProtectionSystemTest method accountWithProtectionRetryBusinessRoleTest.
@Test
public void accountWithProtectionRetryBusinessRoleTest() {
IdmIdentityDto identity = helper.createIdentity();
SysSystemDto system = initSystem();
IdmRoleDto roleTop = helper.createRole();
IdmRoleDto roleSubNotGrantingAcc = helper.createRole();
final SysRoleSystemDto roleSystem = helper.createRoleSystem(roleSubNotGrantingAcc, system);
roleSystem.setCreateAccountByDefault(false);
roleSystemService.save(roleSystem);
IdmRoleDto roleSub = roleService.getByCode(ROLE_ONE);
helper.createRoleComposition(roleTop, roleSub);
helper.createRoleComposition(roleTop, roleSubNotGrantingAcc);
// Set system to protected mode
SysSystemMappingDto mapping = helper.getDefaultMapping(system);
mapping.setProtectionInterval(null);
mapping.setProtectionEnabled(true);
mapping = systemMappingService.save(mapping);
final IdmIdentityContractDto primeContract = helper.getPrimeContract(identity);
final IdmRoleRequestDto idmRoleRequestDto = helper.assignRoles(primeContract, roleTop);
final IdmRoleRequestDto roleRequest = helper.createRoleRequest(identity, ConceptRoleRequestOperation.REMOVE, roleTop);
// Remove role from identity
helper.executeRequest(roleRequest, true, true);
AccAccountDto account = accountService.getAccount(identity.getUsername(), system.getId());
Assert.assertNotNull(account);
Assert.assertTrue(account.isInProtection());
Assert.assertNull(account.getEndOfProtection());
TestResource createdAccount = helper.findResource(account.getUid());
Assert.assertNotNull(createdAccount);
Assert.assertEquals(identity.getFirstName(), createdAccount.getFirstname());
// We again assign same role
helper.assignRoles(primeContract, roleTop);
// Account must be unprotected
account = accountService.getAccount(identity.getUsername(), system.getId());
Assert.assertNotNull(account);
Assert.assertFalse(account.isInProtection());
createdAccount = helper.findResource(account.getUid());
Assert.assertNotNull(createdAccount);
Assert.assertEquals(identity.getFirstName(), createdAccount.getFirstname());
}
use of eu.bcvsolutions.idm.acc.entity.TestResource in project CzechIdMng by bcvsolutions.
the class MappingContextTest method testMappingContextIdentityRoles.
@Test
public void testMappingContextIdentityRoles() {
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 to the context.
mapping.setAddContextIdentityRoles(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);
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.setIdentityRoles(identityRoles);
assertEquals(context.toString(), resource.getDescrip());
// Delete role mapping
systemMappingService.delete(mapping);
}
Aggregations