use of eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException in project CzechIdMng by bcvsolutions.
the class SelfIdentityRoleEvaluatorTest method testGreenLineDelete.
@Test
public void testGreenLineDelete() {
IdmIdentityDto identity = getHelper().createIdentity();
IdmRoleDto role = getHelper().createRole();
IdmIdentityRoleDto identityRole = getHelper().createIdentityRole(identity, role);
// try get identity role
try {
getHelper().login(identity.getUsername(), identity.getPassword());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(null, IdmBasePermission.READ).getContent();
assertTrue(identityRoles.isEmpty());
} finally {
logout();
}
// create authorization policy - assign to role
getHelper().createAuthorizationPolicy(role.getId(), CoreGroupPermission.IDENTITYROLE, IdmIdentityRole.class, SelfIdentityRoleEvaluator.class, IdmBasePermission.READ);
// get identity role after add authorization policy
try {
getHelper().login(identity.getUsername(), identity.getPassword());
try {
identityRoleService.delete(identityRole, IdmBasePermission.DELETE);
fail();
} catch (ForbiddenEntityException e) {
// correct exception
} catch (Exception e) {
fail();
}
} finally {
logout();
}
}
use of eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException in project CzechIdMng by bcvsolutions.
the class SelfIdentityRoleEvaluatorTest method testGreenLineCheckAnotherIdentityRole.
@Test
public void testGreenLineCheckAnotherIdentityRole() {
IdmIdentityDto identity = getHelper().createIdentity();
IdmIdentityDto identityTwo = getHelper().createIdentity();
IdmRoleDto role = getHelper().createRole();
IdmIdentityRoleDto identityRole = getHelper().createIdentityRole(identity, role);
IdmIdentityRoleDto identityRoleTwo = getHelper().createIdentityRole(identityTwo, role);
// try get identity role
try {
getHelper().login(identity.getUsername(), identity.getPassword());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(null, IdmBasePermission.READ).getContent();
assertTrue(identityRoles.isEmpty());
} finally {
logout();
}
// create authorization policy - assign to role
getHelper().createAuthorizationPolicy(role.getId(), CoreGroupPermission.IDENTITYROLE, IdmIdentityRole.class, SelfIdentityRoleEvaluator.class, IdmBasePermission.READ);
// get identity role after add authorization policy
try {
getHelper().login(identity.getUsername(), identity.getPassword());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(null, IdmBasePermission.READ).getContent();
assertFalse(identityRoles.isEmpty());
assertEquals(1, identityRoles.size());
IdmIdentityRoleDto foundedIdentityRoleDto = identityRoles.get(0);
assertEquals(identityRole.getId(), foundedIdentityRoleDto.getId());
try {
identityRoleService.get(identityRoleTwo.getId(), IdmBasePermission.READ);
fail();
} catch (ForbiddenEntityException e) {
// correct exception
} catch (Exception e) {
fail();
}
} finally {
logout();
}
}
use of eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException in project CzechIdMng by bcvsolutions.
the class IdentityRoleByIdentityDeduplicationBulkAction method processDto.
@Override
protected OperationResult processDto(IdmIdentityDto identity) {
UUID identityId = identity.getId();
// Result will be list of concepts.
List<IdmConceptRoleRequestDto> concepts = new ArrayList<>();
List<IdmIdentityContractDto> contracts = identityContractService.findAllValidForDate(identityId, LocalDate.now(), null);
for (IdmIdentityContractDto contract : contracts) {
// Check access for contract.
try {
identityContractService.checkAccess(contract, PermissionUtils.toPermissions(getAuthoritiesForIdentityContract()).toArray(new BasePermission[] {}));
} catch (ForbiddenEntityException e) {
continue;
}
// Process deduplication per identity contract.
concepts.addAll(processDuplicitiesForContract(contract));
}
// If result is empty for identity will be removed any roles.
if (concepts.isEmpty()) {
return new OperationResult.Builder(OperationState.EXECUTED).build();
}
IdmRoleRequestDto roleRequest = new IdmRoleRequestDto();
roleRequest.setApplicant(identityId);
roleRequest.setRequestedByType(RoleRequestedByType.MANUALLY);
roleRequest.setLog("Request was created by bulk action (deduplication).");
// if set approve, dont execute immediately
roleRequest.setExecuteImmediately(!isApprove());
roleRequest = roleRequestService.save(roleRequest, IdmBasePermission.CREATE);
for (IdmConceptRoleRequestDto concept : concepts) {
concept.setRoleRequest(roleRequest.getId());
concept = conceptRoleRequestService.save(concept, IdmBasePermission.CREATE);
}
Map<String, Serializable> properties = new HashMap<>();
properties.put(RoleRequestApprovalProcessor.CHECK_RIGHT_PROPERTY, Boolean.TRUE);
RoleRequestEvent event = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, roleRequest, properties);
event.setPriority(PriorityType.HIGH);
IdmRoleRequestDto request = roleRequestService.startRequestInternal(event);
//
if (request.getState() == RoleRequestState.EXECUTED) {
return new OperationResult.Builder(OperationState.EXECUTED).build();
} else {
return new OperationResult.Builder(OperationState.CREATED).build();
}
}
use of eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException in project CzechIdMng by bcvsolutions.
the class IdentityChangeContractGuaranteeBulkAction method processDto.
@Override
protected OperationResult processDto(IdmIdentityDto identity) {
UUID newGuarantee = getSelectedGuaranteeUuid(PROPERTY_NEW_GUARANTEE);
UUID oldGuarantee = getSelectedGuaranteeUuid(PROPERTY_OLD_GUARANTEE);
if (ObjectUtils.equals(newGuarantee, oldGuarantee)) {
return new OperationResult.Builder(OperationState.EXECUTED).build();
}
Map<UUID, List<IdmContractGuaranteeDto>> currentGuaranteesByContract = getIdentityGuaranteesOrderedByContract(identity.getId());
// iterate over all contract UUIDs ~ keys and contractGuarantees in List ~ values
currentGuaranteesByContract.forEach((contractId, contractGuarantees) -> {
List<IdmContractGuaranteeDto> toUpdate = contractGuarantees.stream().filter(dto -> dto.getGuarantee().equals(oldGuarantee)).collect(Collectors.toList());
if (toUpdate.isEmpty()) {
// there is no guarantee who to replace for this contract, start new iteration
return;
}
for (IdmContractGuaranteeDto guarantee : toUpdate) {
// if same guarantee added multiple-times update all occurrences
try {
guarantee.setGuarantee(newGuarantee);
contractGuaranteeService.save(guarantee, IdmBasePermission.UPDATE);
logItemProcessed(guarantee, new OperationResult.Builder(OperationState.EXECUTED).build());
} catch (ForbiddenEntityException ex) {
LOG.warn("Not authorized to remove the contract guarantee [{}] from contract [{}] .", guarantee, contractId, ex);
logContractGuaranteePermissionError(guarantee, guarantee.getGuarantee(), contractId, IdmBasePermission.UPDATE, ex);
// start the new iteration for another contract, this guarantee wasn't removed here
return;
} catch (ResultCodeException ex) {
logResultCodeException(guarantee, ex);
// start the new iteration for another contract, this guarantee wasn't removed here
return;
}
}
});
return new OperationResult.Builder(OperationState.EXECUTED).build();
}
use of eu.bcvsolutions.idm.core.api.exception.ForbiddenEntityException in project CzechIdMng by bcvsolutions.
the class IdentityRemoveContractGuaranteeBulkAction method processDto.
@Override
protected OperationResult processDto(IdmIdentityDto identity) {
Set<UUID> selectedGuarantees = getSelectedGuaranteeUuids(PROPERTY_OLD_GUARANTEE);
Map<UUID, List<IdmContractGuaranteeDto>> currentGuarantees = getIdentityGuaranteesOrderedByContract(identity.getId());
currentGuarantees.forEach((contractId, contractGuarantees) -> {
// create list of guarantee dtos to delete
List<IdmContractGuaranteeDto> toDelete = contractGuarantees.stream().filter(guarantee -> selectedGuarantees.contains(guarantee.getGuarantee())).collect(Collectors.toList());
// delete guarantees
for (IdmContractGuaranteeDto guarantee : toDelete) {
try {
contractGuaranteeService.delete(guarantee, IdmBasePermission.DELETE);
logItemProcessed(guarantee, new OperationResult.Builder(OperationState.EXECUTED).build());
} catch (ForbiddenEntityException ex) {
LOG.warn("Not authorized to remove contract guarantee [{}] of contract [{}].", guarantee.getGuarantee(), contractId, ex);
logContractGuaranteePermissionError(guarantee, guarantee.getGuarantee(), contractId, IdmBasePermission.DELETE, ex);
} catch (ResultCodeException ex) {
logResultCodeException(guarantee, ex);
}
}
});
return new OperationResult.Builder(OperationState.EXECUTED).build();
}
Aggregations