use of eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter in project CzechIdMng by bcvsolutions.
the class RemoveAutomaticRoleTaskExecutor method end.
@Override
protected Boolean end(Boolean result, Exception ex) {
Boolean ended = super.end(result, ex);
//
if (BooleanUtils.isTrue(ended)) {
IdmRoleDto role = DtoUtils.getEmbedded(getAutomaticRole(), IdmRoleTreeNode_.role, IdmRoleDto.class);
//
long assignedRoles = identityRoleService.findByAutomaticRole(getAutomaticRoleId(), new PageRequest(0, 1)).getTotalElements();
if (assignedRoles != 0) {
LOG.debug("Remove role [{}] by automatic role [{}] is not complete, some roles [{}] remains assigned to identities.", role.getCode(), getAutomaticRole().getId(), assignedRoles);
return ended;
}
//
LOG.debug("Remove role [{}] by automatic role [{}]", role.getCode(), getAutomaticRole().getId());
try {
//
// Find all concepts and remove relation on role tree
IdmConceptRoleRequestFilter conceptRequestFilter = new IdmConceptRoleRequestFilter();
conceptRequestFilter.setAutomaticRole(getAutomaticRoleId());
//
List<IdmConceptRoleRequestDto> concepts = conceptRequestService.find(conceptRequestFilter, null).getContent();
for (IdmConceptRoleRequestDto concept : concepts) {
IdmRoleRequestDto request = roleRequestService.get(concept.getRoleRequest());
String message = null;
if (concept.getState().isTerminatedState()) {
message = MessageFormat.format("Role tree node [{0}] (reqested in concept [{1}]) was deleted (not from this role request)!", getAutomaticRoleId(), concept.getId());
} else {
message = MessageFormat.format("Request change in concept [{0}], was not executed, because requested RoleTreeNode [{1}] was deleted (not from this role request)!", concept.getId(), getAutomaticRoleId());
concept.setState(RoleRequestState.CANCELED);
}
roleRequestService.addToLog(request, message);
conceptRequestService.addToLog(concept, message);
concept.setAutomaticRole(null);
roleRequestService.save(request);
conceptRequestService.save(concept);
}
// Find all automatic role requests and remove relation on automatic role
if (automaticRoleId != null) {
IdmAutomaticRoleRequestFilter automaticRoleRequestFilter = new IdmAutomaticRoleRequestFilter();
automaticRoleRequestFilter.setAutomaticRoleId(automaticRoleId);
automaticRoleRequestService.find(automaticRoleRequestFilter, null).getContent().forEach(request -> {
request.setAutomaticRole(null);
automaticRoleRequestService.save(request);
// WFs cannot be cancel here, because this method can be called from the same WF
// automaticRoleRequestService.cancel(request);
});
}
// by default is this allowed
if (this.isDeleteEntity()) {
// delete entity
if (getAutomaticRole() instanceof IdmRoleTreeNodeDto) {
roleTreeNodeService.deleteInternalById(getAutomaticRole().getId());
} else {
// remove all rules
automaticRoleAttributeRuleService.deleteAllByAttribute(getAutomaticRole().getId());
automaticRoleAttributeService.deleteInternalById(getAutomaticRole().getId());
}
}
//
LOG.debug("End: Remove role [{}] by automatic role [{}].", role.getCode(), getAutomaticRole().getId());
//
} catch (Exception O_o) {
LOG.debug("Remove role [{}] by automatic role [{}] failed", role.getCode(), getAutomaticRole().getId(), O_o);
//
IdmLongRunningTaskDto task = longRunningTaskService.get(getLongRunningTaskId());
ResultModel resultModel = new DefaultResultModel(CoreResultCode.LONG_RUNNING_TASK_FAILED, ImmutableMap.of("taskId", getLongRunningTaskId(), "taskType", task.getTaskType(), "instanceId", task.getInstanceId()));
saveResult(resultModel, OperationState.EXCEPTION, O_o);
}
}
//
return ended;
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter in project CzechIdMng by bcvsolutions.
the class IdentityContractDeleteProcessor method process.
@Override
public EventResult<IdmIdentityContractDto> process(EntityEvent<IdmIdentityContractDto> event) {
IdmIdentityContractDto contract = event.getContent();
//
// delete referenced roles
identityRoleService.findAllByContract(contract.getId()).forEach(identityRole -> {
identityRoleService.delete(identityRole);
});
// Find all concepts and remove relation on role
IdmConceptRoleRequestFilter conceptRequestFilter = new IdmConceptRoleRequestFilter();
conceptRequestFilter.setIdentityContractId(contract.getId());
conceptRequestService.find(conceptRequestFilter, null).getContent().forEach(concept -> {
IdmRoleRequestDto request = roleRequestService.get(concept.getRoleRequest());
String message = null;
if (concept.getState().isTerminatedState()) {
message = MessageFormat.format("IdentityContract [{0}] (requested in concept [{1}]) was deleted (not from this role request)!", contract.getId(), concept.getId());
} else {
message = MessageFormat.format("Request change in concept [{0}], was not executed, because requested IdentityContract [{1}] was deleted (not from this role request)!", concept.getId(), contract.getId());
concept.setState(RoleRequestState.CANCELED);
}
roleRequestService.addToLog(request, message);
conceptRequestService.addToLog(concept, message);
concept.setIdentityContract(null);
roleRequestService.save(request);
conceptRequestService.save(concept);
});
// delete contract guarantees
IdmContractGuaranteeFilter filter = new IdmContractGuaranteeFilter();
filter.setIdentityContractId(contract.getId());
contractGuaranteeService.find(filter, null).forEach(guarantee -> {
contractGuaranteeService.delete(guarantee);
});
// delete identity contract
service.deleteInternal(contract);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter in project CzechIdMng by bcvsolutions.
the class IdentityRoleDeleteProcessor method process.
@Override
public EventResult<IdmIdentityRoleDto> process(EntityEvent<IdmIdentityRoleDto> event) {
IdmIdentityRoleDto identityRole = event.getContent();
// Find all concepts and remove relation on identity role
IdmConceptRoleRequestFilter conceptRequestFilter = new IdmConceptRoleRequestFilter();
conceptRequestFilter.setIdentityRoleId(identityRole.getId());
conceptRequestService.find(conceptRequestFilter, null).getContent().forEach(concept -> {
IdmRoleRequestDto request = roleRequestService.get(concept.getRoleRequest());
String message = null;
if (concept.getState().isTerminatedState()) {
message = MessageFormat.format("IdentityRole [{0}] (reqested in concept [{1}]) was deleted (not from this role request)!", identityRole.getId(), concept.getId());
} else {
message = MessageFormat.format("Request change in concept [{0}], was not executed, because requested IdentityRole [{1}] was deleted (not from this role request)!", concept.getId(), identityRole.getId());
concept.setState(RoleRequestState.CANCELED);
}
roleRequestService.addToLog(request, message);
conceptRequestService.addToLog(concept, message);
concept.setIdentityRole(null);
roleRequestService.save(request);
conceptRequestService.save(concept);
});
//
// remove all IdentityRoleValidRequest for this role
List<IdmIdentityRoleValidRequestDto> validRequests = identityRoleValidRequestService.findAllValidRequestForIdentityRoleId(identityRole.getId());
identityRoleValidRequestService.deleteAll(validRequests);
//
// Delete identity role
service.deleteInternal(identityRole);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter in project CzechIdMng by bcvsolutions.
the class RoleDeleteProcessor method process.
@Override
public EventResult<IdmRoleDto> process(EntityEvent<IdmRoleDto> event) {
IdmRoleDto role = event.getContent();
// role assigned to identity could not be deleted
if (identityRoleRepository.countByRole_Id(role.getId()) > 0) {
throw new ResultCodeException(CoreResultCode.ROLE_DELETE_FAILED_IDENTITY_ASSIGNED, ImmutableMap.of("role", role.getName()));
}
//
// automatic role attribute has assigned this role
IdmAutomaticRoleFilter automaticRoleFilter = new IdmAutomaticRoleFilter();
automaticRoleFilter.setRoleId(role.getId());
long totalElements = automaticRoleAttributeService.find(automaticRoleFilter, new PageRequest(0, 1)).getTotalElements();
if (totalElements > 0) {
// some automatic role attribute has assigned this role
throw new ResultCodeException(CoreResultCode.ROLE_DELETE_FAILED_AUTOMATIC_ROLE_ASSIGNED, ImmutableMap.of("role", role.getName()));
}
//
// remove related automatic roles
IdmRoleTreeNodeFilter filter = new IdmRoleTreeNodeFilter();
filter.setRoleId(role.getId());
roleTreeNodeService.find(filter, null).forEach(roleTreeNode -> {
try {
roleTreeNodeService.delete(roleTreeNode);
} catch (AcceptedException ex) {
throw new ResultCodeException(CoreResultCode.ROLE_DELETE_FAILED_HAS_TREE_NODE, ImmutableMap.of("role", role.getName(), "roleTreeNode", roleTreeNode.getId()));
}
});
// Find all concepts and remove relation on role
IdmConceptRoleRequestFilter conceptRequestFilter = new IdmConceptRoleRequestFilter();
conceptRequestFilter.setRoleId(role.getId());
conceptRoleRequestService.find(conceptRequestFilter, null).getContent().forEach(concept -> {
IdmRoleRequestDto request = roleRequestService.get(concept.getRoleRequest());
String message = null;
if (concept.getState().isTerminatedState()) {
message = MessageFormat.format("Role [{0}] (requested in concept [{1}]) was deleted (not from this role request)!", role.getName(), concept.getId());
} else {
message = MessageFormat.format("Request change in concept [{0}], was not executed, because requested role [{1}] was deleted (not from this role request)!", concept.getId(), role.getName());
concept.setState(RoleRequestState.CANCELED);
}
roleRequestService.addToLog(request, message);
conceptRoleRequestService.addToLog(concept, message);
concept.setRole(null);
roleRequestService.save(request);
conceptRoleRequestService.save(concept);
});
// remove all policies
IdmAuthorizationPolicyFilter policyFilter = new IdmAuthorizationPolicyFilter();
policyFilter.setRoleId(role.getId());
authorizationPolicyService.find(policyFilter, null).forEach(dto -> {
authorizationPolicyService.delete(dto);
});
// Find all automatic role requests and remove relation on automatic role
UUID roleId = role.getId();
if (roleId != null) {
IdmAutomaticRoleRequestFilter automaticRoleRequestFilter = new IdmAutomaticRoleRequestFilter();
automaticRoleRequestFilter.setRoleId(roleId);
automaticRoleRequestService.find(automaticRoleRequestFilter, null).getContent().forEach(request -> {
request.setRole(null);
automaticRoleRequestService.save(request);
automaticRoleRequestService.cancel(request);
});
}
//
// remove role guarantees, sub roles and catalog works automatically by hibenate mapping
service.deleteInternal(role);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmConceptRoleRequestFilter in project CzechIdMng by bcvsolutions.
the class RoleRequestByIdentityEvaluatorIntegrationTest method testCanReadRoleRequestByIdentity.
@Test
public void testCanReadRoleRequestByIdentity() {
IdmIdentityDto identityOne = helper.createIdentity();
IdmIdentityDto identityTwo = helper.createIdentity();
// create policy
IdmRoleDto role = helper.createRole();
helper.createUuidPolicy(role.getId(), identityOne.getId(), IdmBasePermission.READ);
helper.createIdentityRole(identityTwo, role);
helper.createIdentityRole(identityTwo, roleService.getByCode(InitDemoData.DEFAULT_ROLE_NAME));
IdmRoleRequestDto roleRequest = helper.assignRoles(helper.getPrimeContract(identityOne.getId()), role);
//
try {
loginService.login(new LoginDto(identityTwo.getUsername(), identityTwo.getPassword()));
//
Page<IdmRoleRequestDto> roleRequests = roleRequestService.find(null, IdmBasePermission.READ);
assertEquals(1, roleRequests.getTotalElements());
//
IdmRoleRequestDto read = roleRequestService.get(roleRequest.getId(), IdmBasePermission.READ);
assertEquals(roleRequest, read);
//
IdmConceptRoleRequestFilter filter = new IdmConceptRoleRequestFilter();
filter.setRoleRequestId(roleRequest.getId());
Page<IdmConceptRoleRequestDto> concepts = conceptRoleRequestController.find(filter, null, IdmBasePermission.READ);
assertEquals(1, concepts.getTotalElements());
} finally {
logout();
}
}
Aggregations