use of eu.bcvsolutions.idm.core.api.exception.RoleRequestException in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestService method startApprovalProcess.
@Override
@Transactional
public boolean startApprovalProcess(IdmAutomaticRoleRequestDto request, boolean checkRight, EntityEvent<IdmAutomaticRoleRequestDto> event, String wfDefinition) {
// and do realization immediately (without start approval process)
if (request.isExecuteImmediately()) {
boolean haveRightExecuteImmediately = securityService.hasAnyAuthority(CoreGroupPermission.AUTOMATIC_ROLE_REQUEST_ADMIN);
if (checkRight && !haveRightExecuteImmediately) {
throw new RoleRequestException(CoreResultCode.ROLE_REQUEST_NO_EXECUTE_IMMEDIATELY_RIGHT, ImmutableMap.of("new", request));
}
// Execute request immediately
return true;
} else {
Map<String, Object> variables = new HashMap<>();
// Minimize size of DTO persisting to WF
IdmAutomaticRoleRequestDto eventRequest = event.getContent();
eventRequest.setEmbedded(null);
variables.put(EntityEvent.EVENT_PROPERTY, event);
variables.put("approvalForAutomaticRole", Boolean.TRUE);
ProcessInstance processInstance = workflowProcessInstanceService.startProcess(wfDefinition, IdmRoleDto.class.getSimpleName(), request.getCreator(), request.getCreatorId().toString(), variables);
// We have to refresh request (maybe was changed in wf process)
request = this.get(request.getId());
request.setWfProcessId(processInstance.getProcessInstanceId());
this.save(request);
}
return false;
}
use of eu.bcvsolutions.idm.core.api.exception.RoleRequestException in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestService method startApprovalProcess.
@Override
@Transactional
public boolean startApprovalProcess(IdmRoleRequestDto request, boolean checkRight, EntityEvent<IdmRoleRequestDto> event, String wfDefinition) {
// and do realization immediately (without start approval process)
if (request.isExecuteImmediately()) {
boolean haveRightExecuteImmediately = securityService.hasAnyAuthority(CoreGroupPermission.ROLE_REQUEST_EXECUTE);
if (checkRight && !haveRightExecuteImmediately) {
throw new RoleRequestException(CoreResultCode.ROLE_REQUEST_NO_EXECUTE_IMMEDIATELY_RIGHT, ImmutableMap.of("new", request));
}
// All concepts in progress state will be set on approved (we can
// execute it immediately)
request.getConceptRoles().stream().filter(concept -> {
return RoleRequestState.IN_PROGRESS == concept.getState();
}).forEach(concept -> {
concept.setState(RoleRequestState.APPROVED);
conceptRoleRequestService.save(concept);
});
// Execute request immediately
return true;
} else {
IdmIdentityDto applicant = identityService.get(request.getApplicant());
Map<String, Object> variables = new HashMap<>();
// Minimize size of DTO persisting to WF
IdmRoleRequestDto eventRequest = event.getContent();
trimRequest(eventRequest);
eventRequest.setConceptRoles(null);
eventRequest.setOriginalRequest(null);
variables.put(EntityEvent.EVENT_PROPERTY, event);
ProcessInstance processInstance = workflowProcessInstanceService.startProcess(wfDefinition, IdmIdentity.class.getSimpleName(), applicant.getUsername(), applicant.getId().toString(), variables);
// We have to refresh request (maybe was changed in wf process)
request = this.get(request.getId());
request.setWfProcessId(processInstance.getProcessInstanceId());
this.save(request);
}
return false;
}
use of eu.bcvsolutions.idm.core.api.exception.RoleRequestException in project CzechIdMng by bcvsolutions.
the class IdmRoleRequestController method delete.
@Override
@ResponseBody
@RequestMapping(value = "/{backendId}", method = RequestMethod.DELETE)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.ROLE_REQUEST_DELETE + "')")
@ApiOperation(value = "Delete role request", nickname = "deleteRoleRequest", tags = { IdmRoleRequestController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.ROLE_REQUEST_DELETE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.ROLE_REQUEST_DELETE, description = "") }) })
public ResponseEntity<?> delete(@ApiParam(value = "Role request's uuid identifier.", required = true) @PathVariable @NotNull String backendId) {
IdmRoleRequestService service = ((IdmRoleRequestService) this.getService());
IdmRoleRequestDto dto = service.get(backendId);
//
checkAccess(dto, IdmBasePermission.DELETE);
// Request in Executed state can not be delete or change
if (RoleRequestState.EXECUTED == dto.getState()) {
throw new RoleRequestException(CoreResultCode.ROLE_REQUEST_EXECUTED_CANNOT_DELETE, ImmutableMap.of("request", dto));
}
// Only request in Concept state, can be deleted. In others states, will be request set to Canceled state and save.
if (RoleRequestState.CONCEPT == dto.getState()) {
service.delete(dto);
} else {
service.cancel(dto);
}
return new ResponseEntity<Object>(HttpStatus.NO_CONTENT);
}
use of eu.bcvsolutions.idm.core.api.exception.RoleRequestException in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleRequestService method startRequest.
@Override
@Transactional
public IdmAutomaticRoleRequestDto startRequest(UUID requestId, boolean checkRight) {
IdmAutomaticRoleRequestDto request = get(requestId);
Assert.notNull(request, "Request is required!");
// Validation on exist some rule
if (AutomaticRoleRequestType.ATTRIBUTE == request.getRequestType() && RequestOperationType.REMOVE != request.getOperation()) {
IdmAutomaticRoleAttributeRuleRequestFilter ruleFilter = new IdmAutomaticRoleAttributeRuleRequestFilter();
ruleFilter.setRoleRequestId(requestId);
List<IdmAutomaticRoleAttributeRuleRequestDto> ruleConcepts = automaticRoleRuleRequestService.find(ruleFilter, null).getContent();
if (ruleConcepts.isEmpty()) {
throw new RoleRequestException(CoreResultCode.AUTOMATIC_ROLE_REQUEST_START_WITHOUT_RULE, ImmutableMap.of("request", request.getName()));
}
}
try {
IdmAutomaticRoleRequestService service = this.getIdmAutomaticRoleRequestService();
if (!(service instanceof DefaultIdmAutomaticRoleRequestService)) {
throw new CoreException("We expects instace of DefaultIdmAutomaticRoleRequestService!");
}
return ((DefaultIdmAutomaticRoleRequestService) service).startRequestNewTransactional(requestId, checkRight);
} catch (Exception ex) {
LOG.error(ex.getLocalizedMessage(), ex);
request = get(requestId);
Throwable exceptionToLog = resolveException(ex);
// TODO: I set only cause of exception, not code and properties. If are
// properties set, then request cannot be save!
request.setResult(new OperationResultDto.Builder(OperationState.EXCEPTION).setCause(exceptionToLog).build());
request.setState(RequestState.EXCEPTION);
return save(request);
}
}
use of eu.bcvsolutions.idm.core.api.exception.RoleRequestException in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestService method startRequestInternal.
@Override
@Transactional
public IdmRoleRequestDto startRequestInternal(UUID requestId, boolean checkRight) {
LOG.debug("Start role request [{}]", requestId);
Assert.notNull(requestId, "Role request ID is required!");
// Load request ... check right for read
IdmRoleRequestDto request = get(requestId);
Assert.notNull(request, "Role request DTO is required!");
Assert.isTrue(RoleRequestState.CONCEPT == request.getState() || RoleRequestState.DUPLICATED == request.getState() || RoleRequestState.EXCEPTION == request.getState(), "Only role request with CONCEPT or EXCEPTION or DUPLICATED state can be started!");
IdmRoleRequestDto duplicant = validateOnDuplicity(request);
if (duplicant != null) {
request.setState(RoleRequestState.DUPLICATED);
request.setDuplicatedToRequest(duplicant.getId());
this.addToLog(request, MessageFormat.format("This request [{0}] is duplicated to another change permissions request [{1}]", request.getId(), duplicant.getId()));
return this.save(request);
}
// Duplicant is fill, but request is not duplicated (maybe in past)
if (request.getDuplicatedToRequest() != null) {
request.setDuplicatedToRequest(null);
}
// Check on same applicants in all role concepts
boolean identityNotSame = this.get(request.getId()).getConceptRoles().stream().anyMatch(concept -> {
// get contract dto from embedded map
IdmIdentityContractDto contract = (IdmIdentityContractDto) concept.getEmbedded().get(IdmConceptRoleRequestService.IDENTITY_CONTRACT_FIELD);
if (contract == null) {
// If is contract from concept null, then contract via identity role must works
contract = (IdmIdentityContractDto) identityRoleService.get(concept.getIdentityRole()).getEmbedded().get(IdmConceptRoleRequestService.IDENTITY_CONTRACT_FIELD);
}
return !request.getApplicant().equals(contract.getIdentity());
});
if (identityNotSame) {
throw new RoleRequestException(CoreResultCode.ROLE_REQUEST_APPLICANTS_NOT_SAME, ImmutableMap.of("request", request, "applicant", request.getApplicant()));
}
// Convert whole request to JSON and persist (without logs and embedded data)
try {
IdmRoleRequestDto requestOriginal = get(requestId);
trimRequest(requestOriginal);
request.setOriginalRequest(objectMapper.writeValueAsString(requestOriginal));
} catch (JsonProcessingException e) {
throw new RoleRequestException(CoreResultCode.BAD_REQUEST, e);
}
// Request will be set on in progress state
request.setState(RoleRequestState.IN_PROGRESS);
IdmRoleRequestDto savedRequest = this.save(request);
// Throw event
Map<String, Serializable> variables = new HashMap<>();
variables.put(RoleRequestApprovalProcessor.CHECK_RIGHT_PROPERTY, checkRight);
return entityEventManager.process(new RoleRequestEvent(RoleRequestEventType.EXCECUTE, savedRequest, variables)).getContent();
}
Aggregations