Search in sources :

Example 1 with IdmRoleGuaranteeRoleDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeRoleDto in project CzechIdMng by bcvsolutions.

the class RoleExportBulkActionIntegrationTest method testExportAndImportRoleGuaranteeByRole.

@Test
public void testExportAndImportRoleGuaranteeByRole() {
    IdmRoleDto role = createRole();
    IdmRoleDto guaranteeRole = this.getHelper().createRole();
    IdmRoleGuaranteeRoleDto guarantee = this.getHelper().createRoleGuaranteeRole(role, guaranteeRole);
    // Make export, upload and import
    IdmExportImportDto importBatch = executeExportAndImport(role, RoleExportBulkAction.NAME, ImmutableMap.of(EXECUTE_BEFORE_DTO_DELETE, this::deleteAllSubroles));
    role = roleService.get(role.getId());
    Assert.assertNotNull(role);
    List<IdmRoleGuaranteeRoleDto> guarantees = this.findRoleGuarantees(role);
    Assert.assertEquals(1, guarantees.size());
    Assert.assertEquals(guarantee.getId(), guarantees.get(0).getId());
    IdmRoleDto guaranteeRoleTwo = this.getHelper().createRole();
    this.getHelper().createRoleGuaranteeRole(role, guaranteeRoleTwo);
    guarantees = this.findRoleGuarantees(role);
    Assert.assertEquals(2, guarantees.size());
    // Execute import (check authoritative mode)
    importBatch = importManager.executeImport(importBatch, false);
    Assert.assertNotNull(importBatch);
    Assert.assertEquals(ExportImportType.IMPORT, importBatch.getType());
    Assert.assertEquals(OperationState.EXECUTED, importBatch.getResult().getState());
    // Second guarantor had to be deleted!
    guarantees = this.findRoleGuarantees(role);
    Assert.assertEquals(1, guarantees.size());
    Assert.assertEquals(guarantee.getId(), guarantees.get(0).getId());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmExportImportDto(eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto) IdmRoleGuaranteeRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeRoleDto) AbstractExportBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractExportBulkActionTest) Test(org.junit.Test)

Example 2 with IdmRoleGuaranteeRoleDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeRoleDto in project CzechIdMng by bcvsolutions.

the class RoleGuaranteeRoleDeleteProcessor method process.

@Override
public EventResult<IdmRoleGuaranteeRoleDto> process(EntityEvent<IdmRoleGuaranteeRoleDto> event) {
    IdmRoleGuaranteeRoleDto entityEvent = event.getContent();
    // 
    service.deleteInternal(entityEvent);
    // 
    return new DefaultEventResult<>(event, this);
}
Also used : DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmRoleGuaranteeRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeRoleDto)

Example 3 with IdmRoleGuaranteeRoleDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeRoleDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleGuaranteeServiceIntegrationTest method testFindRoleGuaranteeByRoleGuaranteeAndType.

@Test
public void testFindRoleGuaranteeByRoleGuaranteeAndType() {
    IdmRoleDto guaranteeRole = getHelper().createRole();
    IdmRoleDto guaranteeRoleTwo = getHelper().createRole();
    // 
    IdmRoleDto role1 = getHelper().createRole();
    IdmRoleDto role2 = getHelper().createRole();
    IdmRoleDto role3 = getHelper().createRole();
    // 
    String guarranteeType = getHelper().createName();
    getHelper().createRoleGuaranteeRole(role1, guaranteeRole, guarranteeType);
    // 
    getHelper().createRoleGuaranteeRole(role2, guaranteeRoleTwo, guarranteeType);
    // 
    getHelper().createRoleGuaranteeRole(role3, guaranteeRole, null);
    // 
    IdmRoleGuaranteeRoleFilter filter = new IdmRoleGuaranteeRoleFilter();
    filter.setGuaranteeRole(guaranteeRole.getId());
    filter.setType(guarranteeType);
    List<IdmRoleGuaranteeRoleDto> list = roleGuaranteeRoleService.find(filter, null).getContent();
    Assert.assertEquals(1, list.size());
    // 
    List<UUID> roles = list.stream().map(IdmRoleGuaranteeRoleDto::getRole).collect(Collectors.toList());
    IdmRoleGuaranteeRoleDto roleGuaranteeFirst = list.get(0);
    Assert.assertEquals(guaranteeRole.getId(), roleGuaranteeFirst.getGuaranteeRole());
    Assert.assertTrue(roles.contains(role1.getId()));
    Assert.assertFalse(roles.contains(role2.getId()));
    Assert.assertFalse(roles.contains(role3.getId()));
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleGuaranteeRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleGuaranteeRoleFilter) IdmRoleGuaranteeRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeRoleDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) UUID(java.util.UUID) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 4 with IdmRoleGuaranteeRoleDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeRoleDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleServiceIntegrationTest method testReferentialIntegrity.

@Test
public void testReferentialIntegrity() {
    IdmIdentityDto identity = getHelper().createIdentity(new GuardedString("heslo"));
    // role
    IdmRoleDto role = getHelper().createRole();
    getHelper().createRoleGuarantee(role, identity);
    // 
    // guarantee by role
    IdmRoleGuaranteeRoleDto roleGuaranteeOne = new IdmRoleGuaranteeRoleDto();
    roleGuaranteeOne.setRole(role.getId());
    roleGuaranteeOne.setGuaranteeRole(getHelper().createRole().getId());
    roleGuaranteeRoleService.save(roleGuaranteeOne);
    IdmRoleGuaranteeRoleDto roleGuaranteeTwo = new IdmRoleGuaranteeRoleDto();
    roleGuaranteeTwo.setRole(getHelper().createRole().getId());
    roleGuaranteeTwo.setGuaranteeRole(role.getId());
    roleGuaranteeRoleService.save(roleGuaranteeTwo);
    // 
    // after save
    IdmRoleGuaranteeFilter guaranteeFilter = new IdmRoleGuaranteeFilter();
    guaranteeFilter.setRole(role.getId());
    IdmRoleGuaranteeRoleFilter guaranteeRoleFilter = new IdmRoleGuaranteeRoleFilter();
    guaranteeRoleFilter.setRole(role.getId());
    IdmRoleGuaranteeRoleFilter guaranteeRoleRoleFilter = new IdmRoleGuaranteeRoleFilter();
    guaranteeRoleRoleFilter.setGuaranteeRole(role.getId());
    // 
    Assert.assertNotNull(roleService.getByCode(role.getCode()));
    Assert.assertEquals(1, roleGuaranteeService.find(guaranteeFilter, null).getTotalElements());
    Assert.assertEquals(1, roleGuaranteeRoleService.find(guaranteeRoleFilter, null).getTotalElements());
    Assert.assertEquals(1, roleGuaranteeRoleService.find(guaranteeRoleFilter, null).getTotalElements());
    roleService.delete(role);
    // 
    // after delete
    Assert.assertNull(roleService.getByCode(role.getCode()));
    Assert.assertEquals(0, roleGuaranteeService.find(guaranteeFilter, null).getTotalElements());
    Assert.assertEquals(0, roleGuaranteeRoleService.find(guaranteeRoleFilter, null).getTotalElements());
    Assert.assertEquals(0, roleGuaranteeRoleService.find(guaranteeRoleFilter, null).getTotalElements());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleGuaranteeFilter) IdmRoleGuaranteeRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeRoleDto) IdmRoleGuaranteeRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleGuaranteeRoleFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test)

Example 5 with IdmRoleGuaranteeRoleDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeRoleDto in project CzechIdMng by bcvsolutions.

the class RoleGuaranteeRoleByRoleEvaluatorIntegrationTest method canReadByRole.

@Test
public void canReadByRole() {
    IdmIdentityDto identity = getHelper().createIdentity();
    List<IdmRoleGuaranteeRoleDto> roleGuarantees = null;
    IdmRoleDto role = getHelper().createRole();
    IdmRoleGuaranteeRoleDto roleGuaranteeRole = null;
    try {
        getHelper().loginAdmin();
        roleGuaranteeRole = getHelper().createRoleGuaranteeRole(role, role);
        getHelper().createIdentityRole(identity, role);
        getHelper().createUuidPolicy(role.getId(), role.getId(), IdmBasePermission.READ);
    } finally {
        logout();
    }
    // check created identity doesn't have compositions
    try {
        getHelper().login(identity.getUsername(), identity.getPassword());
        Assert.assertEquals(role.getId(), roleService.get(role.getId(), IdmBasePermission.READ).getId());
        roleGuarantees = service.find(null, IdmBasePermission.READ).getContent();
        Assert.assertTrue(roleGuarantees.isEmpty());
    } finally {
        logout();
    }
    // 
    // create authorization policy - assign to role
    getHelper().createAuthorizationPolicy(role.getId(), CoreGroupPermission.ROLEGUARANTEEROLE, IdmRoleGuaranteeRole.class, RoleGuaranteeRoleByRoleEvaluator.class);
    // 
    try {
        getHelper().login(identity.getUsername(), identity.getPassword());
        // 
        // evaluate	access
        roleGuarantees = service.find(null, IdmBasePermission.READ).getContent();
        Assert.assertEquals(1, roleGuarantees.size());
        Assert.assertEquals(roleGuaranteeRole.getId(), roleGuarantees.get(0).getId());
        // 
        Set<String> permissions = service.getPermissions(roleGuaranteeRole);
        Assert.assertEquals(1, permissions.size());
        Assert.assertEquals(IdmBasePermission.READ.name(), permissions.iterator().next());
    } finally {
        logout();
    }
    // 
    getHelper().createUuidPolicy(role.getId(), role.getId(), IdmBasePermission.UPDATE);
    // 
    try {
        getHelper().login(identity.getUsername(), identity.getPassword());
        // 
        Set<String> permissions = service.getPermissions(roleGuaranteeRole);
        Assert.assertEquals(4, permissions.size());
        Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.READ.name())));
        Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.UPDATE.name())));
        Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.CREATE.name())));
        Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.DELETE.name())));
    } finally {
        logout();
    }
}
Also used : IdmRoleGuaranteeRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeRoleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) IdmRoleGuaranteeRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleGuaranteeRoleService) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) List(java.util.List) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AbstractEvaluatorIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest) Assert(org.junit.Assert) IdmRoleGuaranteeRole(eu.bcvsolutions.idm.core.model.entity.IdmRoleGuaranteeRole) Transactional(org.springframework.transaction.annotation.Transactional) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleGuaranteeRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeRoleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractEvaluatorIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest)

Aggregations

IdmRoleGuaranteeRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeRoleDto)12 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)6 Test (org.junit.Test)6 IdmRoleGuaranteeRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleGuaranteeRoleFilter)4 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)3 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)2 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)2 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)2 AbstractRestTest (eu.bcvsolutions.idm.test.api.AbstractRestTest)2 UUID (java.util.UUID)2 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)1 IdmExportImportDto (eu.bcvsolutions.idm.core.api.dto.IdmExportImportDto)1 IdmRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleFilter)1 IdmRoleGuaranteeFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleGuaranteeFilter)1 IdmRoleGuaranteeRoleService (eu.bcvsolutions.idm.core.api.service.IdmRoleGuaranteeRoleService)1 IdmRoleService (eu.bcvsolutions.idm.core.api.service.IdmRoleService)1 CoreGroupPermission (eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission)1 IdmRoleGuaranteeRole (eu.bcvsolutions.idm.core.model.entity.IdmRoleGuaranteeRole)1 IdmBasePermission (eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission)1 AbstractEvaluatorIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest)1