Search in sources :

Example 6 with IdmDelegationDefinitionDto

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

the class DelegationIntegrationTest method testDelegationCannotBeUpdated.

@Test(expected = ResultCodeException.class)
public void testDelegationCannotBeUpdated() {
    IdmIdentityDto delegator = getHelper().createIdentity();
    IdmIdentityDto delegateOne = getHelper().createIdentity();
    // Create default delegations.
    IdmDelegationDefinitionDto definitionOne = new IdmDelegationDefinitionDto();
    definitionOne.setType(ApproveRoleByManagerDelegationType.NAME);
    definitionOne.setDelegator(delegator.getId());
    definitionOne.setDelegate(delegateOne.getId());
    definitionOne = delegationDefinitionService.save(definitionOne);
    // Update of the delegation should throw exception.
    delegationDefinitionService.save(definitionOne);
}
Also used : IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) ChangeIdentityPermissionTest(eu.bcvsolutions.idm.core.workflow.permissions.ChangeIdentityPermissionTest)

Example 7 with IdmDelegationDefinitionDto

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

the class SelfDelegationDefinitionByDelegatorEvaluatorIntegrationTest method testPolicy.

@Test
public void testPolicy() {
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmIdentityDto delegator = getHelper().createIdentity();
    IdmIdentityDto delegate = getHelper().createIdentity();
    IdmRoleDto role = getHelper().createRole();
    getHelper().createIdentityRole(identity, role);
    List<IdmDelegationDefinitionDto> delegations = null;
    IdmDelegationDefinitionDto delegation = getHelper().createDelegation(delegate, identity);
    ;
    // other
    getHelper().createDelegation(identity, delegator);
    try {
        getHelper().login(identity);
        delegations = service.find(null, IdmBasePermission.READ).getContent();
        Assert.assertTrue(delegations.isEmpty());
    } finally {
        logout();
    }
    // Create authorization policy - assign to role
    getHelper().createAuthorizationPolicy(role.getId(), CoreGroupPermission.DELEGATIONDEFINITION, IdmDelegationDefinition.class, SelfDelegationDefinitionByDelegatorEvaluator.class, IdmBasePermission.READ);
    try {
        getHelper().login(identity);
        // evaluate	access
        delegations = service.find(null, IdmBasePermission.READ).getContent();
        Assert.assertEquals(1, delegations.size());
        Assert.assertEquals(delegation.getId(), delegations.get(0).getId());
        // 
        Set<String> permissions = service.getPermissions(delegation);
        Assert.assertEquals(1, permissions.size());
        Assert.assertEquals(IdmBasePermission.READ.name(), permissions.iterator().next());
    } finally {
        logout();
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractEvaluatorIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest)

Example 8 with IdmDelegationDefinitionDto

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

the class DefaultTestHelper method createDelegation.

@Override
public IdmDelegationDefinitionDto createDelegation(IdmIdentityDto delegate, IdmIdentityDto delegator, BasePermission... permissions) {
    IdmDelegationDefinitionDto definition = new IdmDelegationDefinitionDto();
    definition.setType("default-delegation-type");
    definition.setDelegator(delegator.getId());
    definition.setDelegate(delegate.getId());
    return delegationDefinitionService.save(definition, permissions);
}
Also used : IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto)

Example 9 with IdmDelegationDefinitionDto

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

the class WorkflowHistoricTaskInstanceController method addDelegationToTask.

/**
 * Find and add definition of the delegation connected with this task.
 *
 * @param dto
 */
private void addDelegationToTask(WorkflowTaskInstanceDto dto, BasePermission... permission) {
    if (dto != null && dto.getId() != null) {
        // We need to create mock task, because DTO is instance of historic task here.
        WorkflowTaskInstanceDto mockTask = new WorkflowTaskInstanceDto();
        mockTask.setId(dto.getId());
        List<IdmDelegationDto> delegations = delegationManager.findDelegationForOwner(mockTask, permission).stream().sorted(Comparator.comparing(IdmDelegationDto::getCreated, Comparator.nullsFirst(Comparator.naturalOrder()))).collect(Collectors.toList());
        // TODO: ONLY first delegation definition is sets to the task!
        if (!CollectionUtils.isEmpty(delegations)) {
            Collections.reverse(delegations);
            IdmDelegationDto delegation = delegations.get(0);
            IdmDelegationDefinitionDto definition = DtoUtils.getEmbedded(delegation, IdmDelegation_.definition.getName(), IdmDelegationDefinitionDto.class);
            dto.setDelegationDefinition(definition);
        }
    }
}
Also used : IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdmDelegationDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDto)

Example 10 with IdmDelegationDefinitionDto

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

the class DefaultDelegationManager method findDelegation.

@Override
public List<IdmDelegationDefinitionDto> findDelegation(String type, UUID delegatorId, UUID delegatorContractId, BaseDto owner) {
    Assert.notNull(type, "Delegation type cannot be null!");
    Assert.notNull(delegatorId, "Delegator cannot be null!");
    DelegationType delegateType = this.getDelegateType(type);
    if (delegateType == null) {
        // of delegatio type for this code missing ) -> throw exception.
        throw new ResultCodeException(CoreResultCode.DELEGATION_UNSUPPORTED_TYPE, ImmutableMap.of("type", type));
    }
    List<IdmDelegationDefinitionDto> definitions = delegateType.findDelegation(delegatorId, delegatorContractId, owner);
    if (CollectionUtils.isEmpty(definitions)) {
        if (DefaultDelegationType.NAME.equals(type)) {
            return null;
        }
        // Try to default delegation.
        DelegationType defaultDelegateType = this.getDelegateType(DefaultDelegationType.NAME);
        definitions = defaultDelegateType.findDelegation(delegatorId, delegatorContractId, owner);
        if (CollectionUtils.isEmpty(definitions)) {
            return null;
        }
    }
    definitions.forEach(definition -> {
        LOG.debug("Delegation definition found [{}] for type [{}] and delegator [{}]", definition.getId(), type, delegatorId);
    });
    return definitions;
}
Also used : IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) DefaultDelegationType(eu.bcvsolutions.idm.core.model.delegation.type.DefaultDelegationType) DelegationType(eu.bcvsolutions.idm.core.eav.api.service.DelegationType)

Aggregations

IdmDelegationDefinitionDto (eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto)28 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)18 Test (org.junit.Test)14 UUID (java.util.UUID)11 WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)10 List (java.util.List)10 Autowired (org.springframework.beans.factory.annotation.Autowired)10 IdmDelegationDto (eu.bcvsolutions.idm.core.api.dto.IdmDelegationDto)9 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)9 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)8 IdmDelegationDefinitionService (eu.bcvsolutions.idm.core.api.service.IdmDelegationDefinitionService)8 IdmIdentityService (eu.bcvsolutions.idm.core.api.service.IdmIdentityService)8 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)7 DefaultDelegationType (eu.bcvsolutions.idm.core.model.delegation.type.DefaultDelegationType)7 ChangeIdentityPermissionTest (eu.bcvsolutions.idm.core.workflow.permissions.ChangeIdentityPermissionTest)7 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)7 Assert (org.junit.Assert)7 CoreGroupPermission (eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission)6 IdmBasePermission (eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission)6 AbstractEvaluatorIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest)6