Search in sources :

Example 21 with ForbiddenEntityException

use of eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException in project CzechIdMng by bcvsolutions.

the class IdentityDisableBulkActionTest method checkEvaluatorForLrt.

@Test
public void checkEvaluatorForLrt() {
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmRoleDto createRole = getHelper().createRole();
    getHelper().createBasePolicy(createRole.getId(), CoreGroupPermission.IDENTITY, IdmIdentity.class, IdmBasePermission.READ, IdentityBasePermission.MANUALLYDISABLE);
    getHelper().createIdentityRole(identity, createRole);
    loginAsNoAdmin(identity.getUsername());
    IdmBulkActionDto bulkAction = this.findBulkAction(IdmIdentity.class, IdentityDisableBulkAction.NAME);
    Set<UUID> ids = this.getIdFromList(this.createIdentities(5));
    bulkAction.setIdentifiers(ids);
    IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
    IdmLongRunningTaskDto lrt = checkResultLrt(processAction, 5l, null, null);
    try {
        longRunningTaskService.get(lrt.getId(), IdmBasePermission.READ);
        fail("User hasn't permission for read the long running task.");
    } catch (ForbiddenEntityException ex) {
        assertTrue(ex.getMessage().contains(lrt.getId().toString()));
        assertTrue(ex.getMessage().contains(IdmBasePermission.READ.toString()));
    } catch (Exception ex) {
        fail("Bad exception: " + ex.getMessage());
    }
    // create authorization with SelfLongRunningTaskEvaluator
    getHelper().createAuthorizationPolicy(createRole.getId(), CoreGroupPermission.SCHEDULER, IdmLongRunningTask.class, SelfLongRunningTaskEvaluator.class, IdmBasePermission.READ);
    try {
        IdmLongRunningTaskDto longRunningTaskDto = longRunningTaskService.get(lrt.getId(), IdmBasePermission.READ);
        assertNotNull(longRunningTaskDto);
        assertEquals(lrt, longRunningTaskDto);
    } catch (ForbiddenEntityException ex) {
        fail("User has permission for read the long running task. " + ex.getMessage());
    } catch (Exception ex) {
        fail("Bad exception: " + ex.getMessage());
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) ForbiddenEntityException(eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException) ForbiddenEntityException(eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Aggregations

ForbiddenEntityException (eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException)21 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)12 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)9 Test (org.junit.Test)8 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)7 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)7 UUID (java.util.UUID)7 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)5 IdmBasePermission (eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission)5 AbstractEvaluatorIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest)5 IdmBulkActionDto (eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto)4 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)4 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)4 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)3 IdmContractGuaranteeDto (eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto)3 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)3 IdmIdentityProjectionDto (eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto)3 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)3 BasePermission (eu.bcvsolutions.idm.core.security.api.domain.BasePermission)3 ArrayList (java.util.ArrayList)3