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);
}
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();
}
}
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);
}
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);
}
}
}
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;
}
Aggregations