Search in sources :

Example 1 with IdmAuthorityChange

use of eu.bcvsolutions.idm.core.model.entity.IdmAuthorityChange in project CzechIdMng by bcvsolutions.

the class IdentityRoleAddAuthoritiesProcessorTest method testAddRoleWithoutAuthorities.

@Test
public void testAddRoleWithoutAuthorities() throws Exception {
    IdmRoleDto role = getTestRole();
    IdmIdentityDto i = getTestUser();
    IdmIdentityContractDto c = getTestContract(i);
    IdmAuthorityChange ac = getAuthorityChange(i);
    // user has no authorities - change flag is null
    Assert.assertNull(ac);
    // authority added
    getTestIdentityRole(role, c);
    i = identityService.get(i.getId());
    ac = getAuthorityChange(i);
    // 
    DateTime firstChangeTs = ac.getAuthChangeTimestamp();
    Assert.assertNotNull(firstChangeTs);
    // prepare role without authorities
    IdmRoleDto r = new IdmRoleDto();
    r.setName(UUID.randomUUID().toString());
    r = saveInTransaction(r, roleService);
    Thread.sleep(10);
    getTestIdentityRole(r, c);
    i = identityService.get(i.getId());
    ac = getAuthorityChange(i);
    Assert.assertEquals(firstChangeTs, ac.getAuthChangeTimestamp());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuthorityChange(eu.bcvsolutions.idm.core.model.entity.IdmAuthorityChange) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 2 with IdmAuthorityChange

use of eu.bcvsolutions.idm.core.model.entity.IdmAuthorityChange in project CzechIdMng by bcvsolutions.

the class IdentityRoleAddAuthoritiesProcessorTest method testAddRoleWithSuperAuthorities.

@Test
public void testAddRoleWithSuperAuthorities() throws Exception {
    // prepare role with full authorities (APP_ADMIN)
    IdmRoleDto r = new IdmRoleDto();
    r.setName(UUID.randomUUID().toString());
    r = saveInTransaction(r, roleService);
    getTestPolicy(r, IdmBasePermission.ADMIN, IdmGroupPermission.APP);
    // 
    IdmIdentityDto i = getTestUser();
    IdmIdentityContractDto c = getTestContract(i);
    IdmAuthorityChange ac = getAuthorityChange(i);
    Assert.assertNull(ac);
    // authority added
    getTestIdentityRole(r, c);
    i = identityService.get(i.getId());
    ac = getAuthorityChange(i);
    // 
    DateTime firstChangeTs = ac.getAuthChangeTimestamp();
    Assert.assertNotNull(firstChangeTs);
    // role adds IDENTITY_DELETE - must pass without auth change
    IdmRoleDto role = getTestRole();
    Thread.sleep(10);
    getTestIdentityRole(role, c);
    i = identityService.get(i.getId());
    ac = getAuthorityChange(i);
    Assert.assertEquals(firstChangeTs, ac.getAuthChangeTimestamp());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuthorityChange(eu.bcvsolutions.idm.core.model.entity.IdmAuthorityChange) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 3 with IdmAuthorityChange

use of eu.bcvsolutions.idm.core.model.entity.IdmAuthorityChange in project CzechIdMng by bcvsolutions.

the class IdentityRoleDeleteAuthoritiesProcessorTest method removeModifiedTimestamp.

private void removeModifiedTimestamp(IdmIdentityDto i) {
    // addition of roles also modifies authorities -> set to null for the sake of testing
    IdmAuthorityChange ac = getAuthorityChange(i);
    Assert.assertNotNull(ac);
    acRepository.delete(ac);
}
Also used : IdmAuthorityChange(eu.bcvsolutions.idm.core.model.entity.IdmAuthorityChange)

Example 4 with IdmAuthorityChange

use of eu.bcvsolutions.idm.core.model.entity.IdmAuthorityChange in project CzechIdMng by bcvsolutions.

the class PermissionsAuthorityChangeProcessorTest method testCreateAuthorityChangeEntity.

/**
 * In case the identity in role does not have IdmAuthorityChange entity
 * relation, changing role's authorities must create one.
 * @throws Exception
 */
@Test
public void testCreateAuthorityChangeEntity() throws Exception {
    IdmRoleDto role = getTestRole();
    IdmIdentityDto i = getTestUser();
    IdmIdentityContractDto c = getTestContract(i);
    getTestIdentityRole(role, c);
    deleteAuthorityChangedEntity(i);
    IdmAuthorityChange ac = acRepository.findOneByIdentity_Id(i.getId());
    Assert.assertNull(ac);
    sleep();
    clearAuthPolicies(role);
    ac = acRepository.findOneByIdentity_Id(i.getId());
    Assert.assertNotNull(ac);
    Assert.assertNotNull(ac.getAuthChangeTimestamp());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuthorityChange(eu.bcvsolutions.idm.core.model.entity.IdmAuthorityChange) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Test(org.junit.Test)

Example 5 with IdmAuthorityChange

use of eu.bcvsolutions.idm.core.model.entity.IdmAuthorityChange in project CzechIdMng by bcvsolutions.

the class IdentityRoleAddAuthoritiesProcessorTest method testAddRoleDoNotModifyAuthorities.

@Test
public void testAddRoleDoNotModifyAuthorities() throws Exception {
    IdmRoleDto role = getTestRole();
    IdmRoleDto role2 = getTestRole();
    IdmIdentityDto i = getTestUser();
    IdmIdentityContractDto c = getTestContract(i);
    IdmAuthorityChange ac = getAuthorityChange(i);
    // user has no authorities - change flag is null
    Assert.assertNull(ac);
    // authority added
    getTestIdentityRole(role, c);
    i = identityService.get(i.getId());
    ac = getAuthorityChange(i);
    DateTime firstChangeTs = ac.getAuthChangeTimestamp();
    Assert.assertNotNull(firstChangeTs);
    Thread.sleep(10);
    getTestIdentityRole(role2, c);
    i = identityService.get(i.getId());
    ac = getAuthorityChange(i);
    Assert.assertEquals(firstChangeTs, ac.getAuthChangeTimestamp());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuthorityChange(eu.bcvsolutions.idm.core.model.entity.IdmAuthorityChange) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

IdmAuthorityChange (eu.bcvsolutions.idm.core.model.entity.IdmAuthorityChange)11 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)6 Test (org.junit.Test)6 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)5 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)5 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)4 DateTime (org.joda.time.DateTime)3 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)2 IdmIdentityContract (eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract)2 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 IdmJwtAuthentication (eu.bcvsolutions.idm.core.security.api.domain.IdmJwtAuthentication)1 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)1