use of eu.bcvsolutions.idm.core.api.event.DefaultEventResult in project CzechIdMng by bcvsolutions.
the class AutomaticRoleAttributeRuleDeleteProcessor method process.
@Override
public EventResult<IdmAutomaticRoleAttributeRuleDto> process(EntityEvent<IdmAutomaticRoleAttributeRuleDto> event) {
IdmAutomaticRoleAttributeRuleDto dto = event.getContent();
//
List<IdmAutomaticRoleAttributeRuleDto> allRules = automactiRoleAttributeRuleService.findAllRulesForAutomaticRole(dto.getAutomaticRoleAttribute());
// by default is skip value null => false
if (!this.getBooleanProperty(SKIP_CHECK_LAST_RULE, event.getProperties())) {
// it's last rule, remove all identity role
if (allRules.size() == 1 && dto.getId().equals(allRules.get(0).getId())) {
// before we start delete identity role, we check how many identities has the auto role
// if doesn't exist identities that has the role, skip remove
IdmIdentityFilter identityFilter = new IdmIdentityFilter();
long totalElements = identityService.find(identityFilter, new PageRequest(0, 1)).getTotalElements();
if (totalElements > 0) {
UUID automaticRoleAttributeId = dto.getAutomaticRoleAttribute();
removeAllRoles(automaticRoleAttributeId);
//
// we also set concept to false
IdmAutomaticRoleAttributeDto roleAttributeDto = automaticRoleAttributeRuleService.get(automaticRoleAttributeId);
roleAttributeDto.setConcept(false);
roleAttributeDto = automaticRoleAttributeRuleService.save(roleAttributeDto);
}
}
}
UUID automaticRuleId = dto.getId();
// Find all automatic role requests and remove relation on rule
if (automaticRuleId != null) {
IdmAutomaticRoleAttributeRuleRequestFilter automaticRoleRequestFilter = new IdmAutomaticRoleAttributeRuleRequestFilter();
automaticRoleRequestFilter.setRuleId(automaticRuleId);
ruleRequestService.find(automaticRoleRequestFilter, null).getContent().forEach(request -> {
request.setRule(null);
ruleRequestService.save(request);
});
}
//
automactiRoleAttributeRuleService.deleteInternal(dto);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.event.DefaultEventResult in project CzechIdMng by bcvsolutions.
the class AutomaticRoleAttributeRuleSaveProcessor method process.
@Override
public EventResult<IdmAutomaticRoleAttributeRuleDto> process(EntityEvent<IdmAutomaticRoleAttributeRuleDto> event) {
IdmAutomaticRoleAttributeRuleDto dto = event.getContent();
//
dto = automactiRoleAttributeRuleService.saveInternal(dto);
event.setContent(dto);
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.event.DefaultEventResult in project CzechIdMng by bcvsolutions.
the class AutomaticRoleRequestApprovalProcessor method process.
@Override
public EventResult<IdmAutomaticRoleRequestDto> process(EntityEvent<IdmAutomaticRoleRequestDto> event) {
IdmAutomaticRoleRequestDto dto = event.getContent();
boolean checkRight = (boolean) event.getProperties().get(CHECK_RIGHT_PROPERTY);
// Find approval process (by role priority)
String wfDefinition = findWfDefinition(dto);
// If none process definition was found, then is request approved;
if (Strings.isNullOrEmpty(wfDefinition)) {
LOG.info("None approval process definition was found, request [{}] for automatic role is approved.", dto);
return new DefaultEventResult<>(event, this);
}
boolean supports = this.supportsAutomaticRole(wfDefinition);
if (!supports) {
LOG.info("Approval process definition [{}] does not supports approving for automatic role. Default approval process will be used [{}]. Automatic role request [{}]", wfDefinition, DEFAULT_WF_PROCESS_NAME, dto);
wfDefinition = DEFAULT_WF_PROCESS_NAME;
}
boolean approved = service.startApprovalProcess(dto, checkRight, event, wfDefinition);
DefaultEventResult<IdmAutomaticRoleRequestDto> result = new DefaultEventResult<>(event, this);
result.setSuspended(!approved);
return result;
}
use of eu.bcvsolutions.idm.core.api.event.DefaultEventResult 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.event.DefaultEventResult in project CzechIdMng by bcvsolutions.
the class RoleRequestApprovalProcessor method process.
@Override
public EventResult<IdmRoleRequestDto> process(EntityEvent<IdmRoleRequestDto> event) {
IdmRoleRequestDto dto = event.getContent();
boolean checkRight = (boolean) event.getProperties().get(CHECK_RIGHT_PROPERTY);
//
String wfDefinition = getConfigurationValue(PROPERTY_WF);
if (Strings.isNullOrEmpty(wfDefinition)) {
wfDefinition = DEFAULT_WF_PROCESS_NAME;
}
boolean approved = service.startApprovalProcess(dto, checkRight, event, wfDefinition);
DefaultEventResult<IdmRoleRequestDto> result = new DefaultEventResult<>(event, this);
result.setSuspended(!approved);
return result;
}
Aggregations