Search in sources :

Example 71 with TestResource

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);
}
Also used : TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 72 with TestResource

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());
}
Also used : TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 73 with TestResource

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);
}
Also used : TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 74 with TestResource

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());
}
Also used : TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 75 with TestResource

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);
}
Also used : MappingContext(eu.bcvsolutions.idm.acc.domain.MappingContext) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

TestResource (eu.bcvsolutions.idm.acc.entity.TestResource)97 Test (org.junit.Test)83 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)81 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)69 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)51 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)50 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)36 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)32 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)32 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)30 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)27 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)26 ConfidentialString (eu.bcvsolutions.idm.core.security.api.domain.ConfidentialString)19 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)17 SysSchemaAttributeFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter)12 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)12 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)12 SysSchemaAttributeDto (eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto)11 SysSystemAttributeMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter)10 Transactional (org.springframework.transaction.annotation.Transactional)10